Package org.apache.stanbol.enhancer.servicesapi

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


        } catch (PrivilegedActionException pae) {
            Exception e = pae.getException();
            if(e instanceof ClientProtocolException) {
                //force re-initialisation upon error
                serviceInitialised = false;
                throw new EngineException(this, ci, "Exception while executing Request "
                    + "on RESTful NLP Analysis Service at "+analysisServiceUrl, e);
            } else if(e instanceof IOException) {
                //force re-initialisation upon error
                serviceInitialised = false;
                throw new EngineException(this, ci, "Exception while executing Request "
                        + "on RESTful NLP Analysis Service at "+analysisServiceUrl, e);
            } else {
                throw RuntimeException.class.cast(e);
            }
        }
View Full Code Here


    /**
     * @throws EngineException
     */
    private void checkRESTfulNlpAnalysisService() throws EngineException {
        if(!initRESTfulNlpAnalysisService()){
            throw new EngineException("The configured RESTful NLP Analysis Service is "
                + "currently not available (url: '"+analysisServiceUrl+"')");
        }
    }
View Full Code Here

                    nerList.get(nerSentIndex).context = at.getSpan();
                }
                nerSentIndex++;
            }
        } catch (IOException e) {
            throw new EngineException(this, ci, "Exception while reading from "
                + "AnalyzedText contentpart",e);
        } finally {
            try {
                tokenStream.close();
            } catch (IOException e) {/* ignore */}
 
View Full Code Here

    @Override
    public void computeEnhancements(ContentItem ci) throws EngineException {
        log.trace(" enhance ci {}",ci.getUri());
        if(isOfflineMode() && !entitySearcher.supportsOfflineMode()){
            throw new EngineException(this,ci,"Offline mode is not supported by the used EntitySearcher!",null);
        }
        AnalysedText at = getAnalysedText(this, ci, true);
        log.debug("  > AnalysedText {}",at);
        String language = getLanguage(this, ci, true);
        if(log.isDebugEnabled()){
            log.debug("computeEnhancements for ContentItem {} language {} text={}",
                new Object []{ci.getUri().getUnicodeString(), language, StringUtils.abbreviate(at.getSpan(), 100)});
        }
        log.debug("  > Language {}",language);
        LanguageProcessingConfig languageConfig = textProcessingConfig.getConfiguration(language);
        if(languageConfig == null){
            throw new IllegalStateException("The language '"+language+"' is not configured "
                    + "to be processed by this Engine. As this is already checked within the "
                    + "canEnhance(..) method this may indicate an bug in the used "
                    + "EnhanceemntJobManager implementation!");
        }
        EntityLinker entityLinker = new EntityLinker(at,language,
            languageConfig, entitySearcher, linkerConfig, labelTokenizer);
        //process
        try {
            entityLinker.process();
        } catch (EntitySearcherException e) {
            log.error("Unable to link Entities with "+entityLinker,e);
            throw new EngineException(this, ci, "Unable to link Entities with "+entityLinker, e);
        }
        if(log.isInfoEnabled()){
            entityLinker.logStatistics(log);
        }
        //write results (requires a write lock)
View Full Code Here

        ci.getLock().readLock().lock();
        try {
            docId = new URIImpl(ci.getUri().getUnicodeString());
            m = this.extractor.extract(ci.getStream(), docId, ci.getMimeType());
        } catch (ExtractorException e) {
            throw new EngineException("Error while processing ContentItem "
                + ci.getUri()+" with Metaxa",e);
        } catch (IOException e) {
            throw new EngineException("Error while processing ContentItem "
                    + ci.getUri()+" with Metaxa",e);
        } finally {
            ci.getLock().readLock().unlock();
        }
        // Convert the RDF2go model to a Clerezza Graph and also extract
        // the extracted plain text from the model
        if (null == m) {
            log.debug("Unable to preocess ContentItem {} (mime type {}) with Metaxa",
                ci.getUri(),ci.getMimeType());
            return;
        }
        ContentSink plainTextSink;
        try {
            plainTextSink = ciFactory.createContentSink("text/plain");
        } catch (IOException e) {
            m.close();
            throw new EngineException("Unable to initialise Blob for storing" +
                "the plain text content",e);
        }
        HashMap<BlankNode, BNode> blankNodeMap = new HashMap<BlankNode, BNode>();
        RDF2GoUtils.urifyBlankNodes(m);
        ClosableIterator<Statement> it = m.iterator();
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
            plainTextSink.getOutputStream(), UTF8));
        boolean textExtracted = false; //used to detect if some text was extracted
        try {
            MGraph g = new SimpleMGraph(); //first add to a temporary graph
            while (it.hasNext()) {
                Statement oneStmt = it.next();
                //we need to treat triples that provide the plain/text
                //version differently. Such Objects need to be added to
                //the plain text Blob!
                if(oneStmt.getSubject().equals(docId) &&
                        oneStmt.getPredicate().equals(NIE_PLAINTEXT_PROPERTY)){
                    String text = oneStmt.getObject().toString();
                    if(text != null && !text.isEmpty()){
                        try {
                            out.write(oneStmt.getObject().toString());
                        } catch (IOException e) {
                            throw new EngineException("Unable to write extracted" +
                                "plain text to Blob (blob impl: "
                                    + plainTextSink.getBlob().getClass()+")",e);
                        }
                        textExtracted = true;
                        if (includeText) {
View Full Code Here

        //process
        try {
            entityLinker.process();
        } catch (EntitySearcherException e) {
            log.error("Unable to link Entities with "+entityLinker,e);
            throw new EngineException(this, ci, "Unable to link Entities with "+entityLinker, e);
        }
        //TODO: write results
        ci.getLock().writeLock().lock();
        try {
            writeComentions(ci,entityLinker.getLinkedEntities().values(), language, textAnnotations);
View Full Code Here

            if(text.length() < 200){
                msg.append(text);
            } else {
                msg.append(text.subSequence(0, 199)).append("...");
            }
            throw new EngineException(this, ci, msg.toString(), e);
        }
       
        // add language to metadata
        if (languages != null) {
            MGraph g = ci.getMetadata();
View Full Code Here

                        dereferencedCount++;
                    }
                } catch (InterruptedException e) {
                    // Restore the interrupted status
                    Thread.currentThread().interrupt();
                    throw new EngineException(this, ci,
                        "Interupted while waiting for dereferencing Entities", e);
                } catch (ExecutionException e) {
                    if(e.getCause() instanceof DereferenceException){
                        failedEntities.add(dereferenceJob.entity);
                        log.debug(" ... error while dereferencing "
                            + dereferenceJob.entity + "!", e);
                    } else { //unknown error
                        throw new EngineException(this,ci, "Unchecked Error while "
                            + "dereferencing Entity " + dereferenceJob.entity
                            + "!", e);
                    }
                }
            }
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

      // 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 Spot RESTful Serice running at "
          + spotlightUrl,e);
    } catch(SAXException e) {
      throw new EngineException("Unable to parse Response from "
          + "Dbpedia Spotlight Spot RESTful Serice running at "
          + spotlightUrl,e);
    } finally {
      IOUtils.closeQuietly(is);
    }
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.