Package org.apache.stanbol.enhancer.servicesapi

Examples of org.apache.stanbol.enhancer.servicesapi.EngineException


      // Send request
      wr = new BufferedWriter(new OutputStreamWriter(
          connection.getOutputStream(),UTF8));
    } catch (IOException e) {
      IOUtils.closeQuietly(wr);
      throw new EngineException("Unable to open connection to "+
          spotlightUrl,e);
    }
    try {

      wr.write("spotter=SpotXmlParser&");
      if (spotlightDisambiguator != null
          && !spotlightDisambiguator.isEmpty()){
        wr.write("disambiguator=");
        wr.write(URLEncoder.encode(spotlightDisambiguator, "UTF-8"));
        wr.write('&');
      }
      if (spotlightTypesRestriction != null
          && !spotlightTypesRestriction.isEmpty()){
        wr.write("types=");
        wr.write(URLEncoder.encode(spotlightTypesRestriction, "UTF-8"));
        wr.write('&');
      }
      if (spotlightSupport != null && !spotlightSupport.isEmpty()) {
        wr.write("support=");
        wr.write(URLEncoder.encode(spotlightSupport, "UTF-8"));
        wr.write('&');
      }
      if (spotlightConfidence != null && !spotlightConfidence.isEmpty()){
        wr.write("confidence=");
        wr.write(URLEncoder.encode(spotlightConfidence, "UTF-8"));
        wr.write('&');
      }
      if (spotlightSparql != null && !spotlightSparql.isEmpty()
          && spotlightTypesRestriction == null) {
        wr.write("sparql=");
        wr.write(URLEncoder.encode(spotlightSparql, "UTF-8"));
        wr.write('&');
      }
      wr.write("text=");
      wr.write(URLEncoder.encode(xmlTextAnnotations, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
      throw new IllegalStateException(
          "The platform does not support encoding " + UTF8.name(),e);
    } catch (IOException e) {
      throw new EngineException("Unable to write 'plain/text' content "
          + "for ContentItem "+contentItemUri+" to "
          + spotlightUrl,e);
    } finally {
      IOUtils.closeQuietly(wr);
    }
    InputStream is = null;
    Document xmlDoc;
    try {
      // Get Response
       is = connection.getInputStream();
      xmlDoc = loadXMLFromInputStream(is);
    } catch (IOException e) {
      throw new EngineException("Unable to spot Entities with"
          + "Dbpedia Spotlight Annotate RESTful Serice running at "
          + spotlightUrl,e);
    } catch(SAXException e) {
      throw new EngineException("Unable to parse Response from "
          + "Dbpedia Spotlight Annotate RESTful Serice running at "
          + spotlightUrl,e);
    } finally {
      IOUtils.closeQuietly(is);
    }
View Full Code Here


      // Send request
      wr = new BufferedWriter(new OutputStreamWriter(
          connection.getOutputStream(),UTF8));
    } catch (IOException e) {
      IOUtils.closeQuietly(wr);
      throw new EngineException("Unable to open connection to "+
          spotlightUrl,e);
    }
    try {
      if (spotlightSpotter != null && !spotlightSpotter.isEmpty()){
        wr.write("spotter=");
        wr.write(URLEncoder.encode(spotlightSpotter, "UTF-8"));
        wr.write('&');
      }
      if (spotlightDisambiguator != null
          && !spotlightDisambiguator.isEmpty()){
        wr.write("disambiguator=");
        wr.write(URLEncoder.encode(spotlightDisambiguator, "UTF-8"));
        wr.write('&');
      }
      if (spotlightTypesRestriction != null
          && !spotlightTypesRestriction.isEmpty()) {
        wr.write("types=");
        wr.write(URLEncoder.encode(spotlightTypesRestriction, "UTF-8"));
        wr.write('&');
      }
      if (spotlightSupport != null && !spotlightSupport.isEmpty()) {
        wr.write("support=");
        wr.write(URLEncoder.encode(spotlightSupport, "UTF-8"));
        wr.write('&');
      }
      if (spotlightConfidence != null && !spotlightConfidence.isEmpty()) {
        wr.write("confidence=");
        wr.write(URLEncoder.encode(spotlightConfidence, "UTF-8"));
        wr.write('&');
      }
      if (spotlightSparql != null && !spotlightSparql.isEmpty()
          && spotlightTypesRestriction == null) {
        wr.write("sparql=");
        wr.write(URLEncoder.encode(spotlightSparql, "UTF-8"));
        wr.write('&');
      }
      wr.write("text=");
      wr.write(URLEncoder.encode(text, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
      throw new IllegalStateException(
          "The platform does not support encoding " + UTF8.name(),e);
    } catch (IOException e) {
      throw new EngineException("Unable to write 'plain/text' content "
          + "for ContentItem "+contentItemUri+" to "
          + spotlightUrl,e);
    } finally {
      IOUtils.closeQuietly(wr);
    }
    InputStream is = null;
    Document xmlDoc;
    try {
      // Get Response
       is = connection.getInputStream();
      xmlDoc = loadXMLFromInputStream(is);
    } catch (IOException e) {
      throw new EngineException("Unable to spot Entities with"
          + "Dbpedia Spotlight Annotate RESTful Serice running at "
          + spotlightUrl,e);
    } catch(SAXException e) {
      throw new EngineException("Unable to parse Response from "
          + "Dbpedia Spotlight Annotate RESTful Serice running at "
          + spotlightUrl,e);
    } finally {
      IOUtils.closeQuietly(is);
    }
View Full Code Here

              + "EnhancementJobManager!");
    }
    try {
      return ContentItemHelper.getText(contentPart.getValue());
    } catch (IOException e) {
      throw new EngineException("Unable to read plain text content form" +
          "contentpart "+contentPart.getKey()+" of ContentItem " +
          ci.getUri());
    }
  }
View Full Code Here

                }
            });
        } catch (PrivilegedActionException pae){
            Exception e = pae.getException();
            log.error("Unable to initialise PoadingAnalyzer",e);
            throw new EngineException("Unable to initialise PoadingAnalyzer",e);
        }
        TokenStream ts = pa.tokenStream("dummy", new CharSequenceReader(at.getText()));
        int lastEnd = 0;
        try {
            while(ts.incrementToken()){
                OffsetAttribute offset = ts.addAttribute(OffsetAttribute.class);
                //when tokenizing labels we need to preserve all chars
                if(offset.startOffset() > lastEnd){ //add token for stopword
                    at.addToken(lastEnd,offset.startOffset());
                }
                at.addToken(offset.startOffset(), offset.endOffset());
                lastEnd = offset.endOffset();
            }
        } catch (IOException e) {
            log.warn("IOException while reading the parsed Text",e);
            throw new EngineException("IOException while reading the parsed Text",e);
        }
    }
View Full Code Here

            ContentSink plainTextSink;
            try {
                plainTextSink = ciFactory.createContentSink(TEXT_PLAIN +"; charset="+UTF8.name());
            } catch (IOException e) {
                IOUtils.closeQuietly(in); //close the input stream
                throw new EngineException("Error while initialising Blob for" +
                    "writing the text/plain version of the parsed content",e);
            }
            final Writer plainTextWriter = new OutputStreamWriter(plainTextSink.getOutputStream(), UTF8);
            final ContentHandler textHandler = new BodyContentHandler( //only the Body
                new PlainTextHandler(plainTextWriter, false,skipLinebreaks)); //skip ignoreable
            final ToXMLContentHandler xhtmlHandler;
            final ContentHandler mainHandler;
            ContentSink xhtmlSink = null;
            try {
                if(!plainMediaType.equals(XHTML)){ //do not parse XHTML from XHTML
                    try {
                        xhtmlSink = ciFactory.createContentSink(XHTML +"; charset="+UTF8.name());
                    } catch (IOException e) {
                        throw new EngineException("Error while initialising Blob for" +
                                "writing the application/xhtml+xml version of the parsed content",e);
                    }
                    try {
                        xhtmlHandler = new ToXMLContentHandler(xhtmlSink.getOutputStream(),UTF8.name());
                    } catch (UnsupportedEncodingException e) {
                        throw new EngineException("This system does not support the encoding "+UTF8,e);
                    }
                    mainHandler = new MultiHandler(textHandler,xhtmlHandler);
                } else {
                    mainHandler = textHandler;
                    xhtmlHandler = null;
                    xhtmlSink = null;
                }
                try {
                    AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                        public Object run() throws IOException, SAXException, TikaException {
                            parser.parse(in, mainHandler, metadata, context);
                            return null;
                        }
                    });
                } catch (PrivilegedActionException pae) {
                    Exception e = pae.getException();
                    if(e instanceof IOException || e instanceof SAXException || e instanceof TikaException){
                        throw new EngineException("Unable to convert ContentItem "+
                                ci.getUri()+" with mimeType '"+ci.getMimeType()+"' to "+
                                "plain text!",e);
                    } else { //runtime exception
                        throw RuntimeException.class.cast(e);
                    }
View Full Code Here

        } catch (NoConvertorException e) {
          log.error(e.getMessage(), e);
        }
      }
        } catch (IOException e) {
            throw new EngineException("Error while calling the CELI NER (Named Entity Recognition)"
                +" service (configured URL: " +serviceURL+")!",e);
        } catch (SOAPException e) {
            throw new EngineException("Error wile encoding/decoding the request/"
                +"response to the CELI NER (Named Entity Recognition) service!",e);
        }

  }
View Full Code Here

       
        POSTagger posTagger = getPOSTagger(language);
        if(posTagger == null){
            //this means that the POS tagger became unavailable in-between
            //the call to canEnhance and computeEnhancement
            throw new EngineException("PosTagger for langauge '"+language
                + "is not available.");
        }
        TagSet<PosTag> tagSet = tagSetRegistry.getTagSet(language);
        if(tagSet == null){
            log.warn("No POS TagSet registered for Language '{}'. Will build an "
View Full Code Here

            languages = languageIdentifier.getLanguages(text);
            log.debug("language identified: {}",languages);
        }
        catch (LangDetectException e) {
            log.warn("Could not identify language", e);
            throw new EngineException(this, ci, "Could not identify language", e);
        }
       
        // add language to metadata
        if (languages != null) {
            MGraph g = ci.getMetadata();
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.servicesapi.EngineException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.