Examples of EntityLinker


Examples of opennlp.tools.entitylinker.EntityLinker

        throw new TerminateToolException(-1, "Failed to load the properties file!");
      }

      // TODO: It should not just throw Exception.

      EntityLinker entityLinker;
      try {
        entityLinker = EntityLinkerFactory.getLinker(entityType, properties);
      }
      catch (Exception e) {
        throw new TerminateToolException(-1, "Failed to instantiate the Entity Linker: " + e.getMessage());
      }

      PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
      perfMon.start();

      try {

        ObjectStream<String> untokenizedLineStream = new PlainTextByLineStream(
            new SystemInputStreamFactory(), SystemInputStreamFactory.encoding());

        List<NameSample> document = new ArrayList<NameSample>();

        String line;
        while ((line = untokenizedLineStream.read()) != null) {

          if (line.trim().isEmpty()) {
            // Run entity linker ... and output result ...

            StringBuilder text = new StringBuilder();
            Span sentences[] = new Span[document.size()];
            Span[][] tokensBySentence = new Span[document.size()][];
            Span[][] namesBySentence = new Span[document.size()][];

            for (int i = 0; i < document.size(); i++) {

              NameSample sample = document.get(i);
             
              namesBySentence[i] = sample.getNames();
             
              int sentenceBegin = text.length();
             
              Span[] tokens = new Span[sample.getSentence().length];

              // for all tokens
              for (int ti = 0; ti < sample.getSentence().length; ti++) {
                int tokenBegin = text.length();
                text.append(sample.getSentence()[ti]);
                text.append(" ");
                tokens[i] = new Span(tokenBegin, text.length());
              }
             
              tokensBySentence[i] = tokens;
             
              sentences[i] = new Span(sentenceBegin, text.length());
              text.append("\n");
            }

            List<Span> linkedSpans = entityLinker.find(text.toString(), sentences, tokensBySentence, namesBySentence);

            for (int i = 0; i < linkedSpans.size(); i++) {
              System.out.println(linkedSpans.get(i));
            }
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.entitylinking.impl.EntityLinker

        tpc.setLinkedLexicalCategories(LanguageProcessingConfig.DEFAULT_LINKED_LEXICAL_CATEGORIES);
        tpc.setLinkedPos(Collections.EMPTY_SET);
        EntityLinkerConfig config = new EntityLinkerConfig();
        config.setMinFoundTokens(2);//this is assumed by this test
        config.setRedirectProcessingMode(RedirectProcessingMode.FOLLOW);
        EntityLinker linker = new EntityLinker(TEST_ANALYSED_TEXT,"en",
            tpc, searcher, config, labelTokenizer);
        linker.process();
        Map<String,List<String>> expectedResults = new HashMap<String,List<String>>();
        expectedResults.put("Patrick Marshall", new ArrayList<String>(
                Arrays.asList("urn:test:PatrickMarshall")));
        expectedResults.put("geologist", new ArrayList<String>(
                Arrays.asList("urn:test:redirect:Geologist"))); //the redirected entity
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.entitylinking.impl.EntityLinker

        tpc.setLinkedPos(Collections.EMPTY_SET);
        tpc.setIgnoreChunksState(true); //to emulate pre STANBOL-1211
        EntityLinkerConfig config = new EntityLinkerConfig();
        config.setMinFoundTokens(2);//this is assumed by this test
        config.setRedirectProcessingMode(RedirectProcessingMode.FOLLOW);
        EntityLinker linker = new EntityLinker(TEST_ANALYSED_TEXT_WO,"en",
            tpc, searcher, config, labelTokenizer);
        linker.process();
        Map<String,List<String>> expectedResults = new HashMap<String,List<String>>();
        expectedResults.put("Marshall Patrick", new ArrayList<String>(
                Arrays.asList("urn:test:PatrickMarshall")));
        expectedResults.put("geologist", new ArrayList<String>(
                Arrays.asList("urn:test:redirect:Geologist"))); //the redirected entity
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.entitylinking.impl.EntityLinker

        tpc.setLinkedLexicalCategories(Collections.EMPTY_SET);
        tpc.setLinkedPos(LanguageProcessingConfig.DEFAULT_LINKED_POS);
        EntityLinkerConfig config = new EntityLinkerConfig();
        config.setMinFoundTokens(2);//this is assumed by this test
        config.setRedirectProcessingMode(RedirectProcessingMode.FOLLOW);
        EntityLinker linker = new EntityLinker(TEST_ANALYSED_TEXT,"en",
            tpc, searcher, config, labelTokenizer);
        linker.process();
        Map<String,List<String>> expectedResults = new HashMap<String,List<String>>();
        expectedResults.put("Patrick Marshall", new ArrayList<String>(
                Arrays.asList("urn:test:PatrickMarshall")));
        //Geologist is a common noun and MUST NOT be found
        //expectedResults.put("geologist", new ArrayList<String>(
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.entitylinking.impl.EntityLinker

            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)
        ci.getLock().writeLock().lock();
        try {
            writeEnhancements(ci, entityLinker.getLinkedEntities().values(), language);
        } finally {
            ci.getLock().writeLock().unlock();
        }
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.entitylinking.impl.EntityLinker

                textAnnotations.add(ta); //store the registered text annotations
            }
        } finally {
            ci.getLock().readLock().unlock();
        }
        EntityLinker entityLinker = new EntityLinker(at,language,
            languageConfig, entityMentionIndex, linkerConfig, labelTokenizer,entityMentionIndex);
        //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);
        } finally {
            ci.getLock().writeLock().unlock();
        }
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.entitylinking.impl.EntityLinker

            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);
        } finally {
            ci.getLock().writeLock().unlock();
        }
    }
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.entitylinking.impl.EntityLinker

        tpc.setLinkedLexicalCategories(LanguageProcessingConfig.DEFAULT_LINKED_LEXICAL_CATEGORIES);
        tpc.setLinkedPos(Collections.EMPTY_SET);
        EntityLinkerConfig config = new EntityLinkerConfig();
        config.setMinFoundTokens(2);//this is assumed by this test
        config.setRedirectProcessingMode(RedirectProcessingMode.FOLLOW);
        EntityLinker linker = new EntityLinker(TEST_ANALYSED_TEXT,"en",
            tpc, searcher, config, labelTokenizer);
        linker.process();
        Map<String,List<String>> expectedResults = new HashMap<String,List<String>>();
        expectedResults.put("Patrick Marshall", new ArrayList<String>(
                Arrays.asList("urn:test:PatrickMarshall")));
        expectedResults.put("geologist", new ArrayList<String>(
                Arrays.asList("urn:test:redirect:Geologist"))); //the redirected entity
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.entitylinking.impl.EntityLinker

        tpc.setLinkedLexicalCategories(Collections.EMPTY_SET);
        tpc.setLinkedPos(LanguageProcessingConfig.DEFAULT_LINKED_POS);
        EntityLinkerConfig config = new EntityLinkerConfig();
        config.setMinFoundTokens(2);//this is assumed by this test
        config.setRedirectProcessingMode(RedirectProcessingMode.FOLLOW);
        EntityLinker linker = new EntityLinker(TEST_ANALYSED_TEXT,"en",
            tpc, searcher, config, labelTokenizer);
        linker.process();
        Map<String,List<String>> expectedResults = new HashMap<String,List<String>>();
        expectedResults.put("Patrick Marshall", new ArrayList<String>(
                Arrays.asList("urn:test:PatrickMarshall")));
        //Geologist is a common noun and MUST NOT be found
        //expectedResults.put("geologist", new ArrayList<String>(
View Full Code Here

Examples of org.apache.stanbol.enhancer.engines.keywordextraction.impl.EntityLinker

        }
        if(isProcessableLanguages(language)){
            log.debug("computeEnhancements for ContentItem {} language {} text={}",
                new Object []{ci.getUri().getUnicodeString(), language, StringUtils.abbreviate(text, 100)});
           
            EntityLinker entityLinker = new EntityLinker(
                analysedContentFactory.create(text, language),
                entitySearcher, linkerConfig);
            //process
            entityLinker.process();
            //write results (requires a write lock)
            ci.getLock().writeLock().lock();
            try {
                writeEnhancements(ci, entityLinker.getLinkedEntities().values(), language);
            } finally {
                ci.getLock().writeLock().unlock();
            }
        } else {
            log.debug("ignore ContentItem {} because language '{}' is not configured to" +
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.