Package org.apache.stanbol.enhancer.servicesapi

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


        MGraph results = new SimpleMGraph();
        ZemantaAPIWrapper zemanta = new ZemantaAPIWrapper(key);
        try {
            results.addAll(zemanta.enhance(text));
        } catch (IOException e) {
           throw new EngineException("Unable to get Enhancement from remote Zemanta Service",e);
        }
        //now we need to process the results and convert them into the Enhancer
        //annotation structure
        ci.getLock().writeLock().lock();
        try {
View Full Code Here


                    site, entry.getKey(),entry.getValue());
                if(entitySuggestions != null && !entitySuggestions.isEmpty()){
                    suggestions.put(entry.getKey(), entitySuggestions);
                }
            } catch (EntityhubException e) {
                throw new EngineException(this, ci, e);
            }
        }
        //now write the results (requires write lock)
        ci.getLock().writeLock().lock();
        try {
View Full Code Here

                xhtmlHandler = null;
            }
            try {
                parser.parse(in, mainHandler, metadata, context);
            } catch (Exception e) {
                throw new EngineException("Unable to convert ContentItem "+
                        ci.getUri()+" with mimeType '"+ci.getMimeType()+"' to "+
                        "plain text!",e);
            }
            IOUtils.closeQuietly(in);
            if(log.isDebugEnabled()){
View Full Code Here

    }

    @Override
    public void computeEnhancements(ContentItem ci) throws EngineException {
        if(isOfflineMode() && !entitySearcher.supportsOfflineMode()){
            throw new EngineException("Offline mode is not supported by the Component used to lookup Entities");
        }
        Entry<UriRef,Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMETYPES);
        if(contentPart == null){
            throw new IllegalStateException("No ContentPart with a supported Mime Type"
                    + "found for ContentItem "+ci.getUri()+"(supported: '"
View Full Code Here

            log.debug("Calais data:\n{}", calaisResult);
            // build model from Calais result
            InputStream in = new ByteArrayInputStream(calaisResult.getBytes("utf-8"));
            model = readModel(in, "application/rdf+xml");
        } catch (UnsupportedEncodingException e) {
            throw new EngineException(e.getMessage(), e);
        } catch (IOException e) {
            throw new EngineException(e.getMessage(), e);
        }
        return model;
    }
View Full Code Here

        MGraph metadata = ci.getMetadata();
        List<TopicSuggestion> topics;
        try {
            topics = suggestTopics(text);
        } catch (ClassifierException e) {
            throw new EngineException(e);
        }
        ci.getLock().writeLock().lock();
        try {
            for (TopicSuggestion topic : topics) {
                UriRef enhancement = EnhancementEngineHelper.createEntityEnhancement(ci, this);
View Full Code Here

                     * This depends if single requests can result in Exceptions
                     * (e.g. because of encoding problems) or if usually Exceptions
                     * are thrown because of general things like connection issues
                     * or service unavailability.
                     */
                throw new EngineException(this, ci, e);
            }
            if (results != null) {
                for (Toponym result : results) {
                    log.debug("process result {} {}",result.getGeoNameId(),result.getName());
                    Double score = getToponymScore(result);
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, UTF8.name()));
        wr.write('&');
      }
      wr.write("text=");
      //now append the URL encoded text
      //TODO: This will load the URLEncoded variant in-memory.
      //      One could avoid that by encoding the data in smaller
      //      pieces, but using URLEncoding for big data is anyway
      //      very inefficient. So instead of fixing this issue here
      //      DBpedia Spotlight should support "multipart/from-data"
      //      instead.
      //      As soon as this is supported this should be re-implemented
      //      to support streaming.
      wr.write(URLEncoder.encode(text, UTF8.name()));
    } 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);
    }
    // rwesten: reimplemented this to read the XML
    // Document directly form the response
    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

    @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);
        }
        //write results (requires a write lock)
        ci.getLock().writeLock().lock();
        try {
            writeEnhancements(ci, entityLinker.getLinkedEntities().values(), language);
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.