Search in sources :

Example 6 with TokenNameFinderModel

use of opennlp.tools.namefind.TokenNameFinderModel in project tika by apache.

the class GeoParser method initialize.

/**
     * Initializes this parser
     * @param modelUrl the URL to NER model
     */
public void initialize(URL modelUrl) {
    try {
        if (this.modelUrl != null && this.modelUrl.toURI().equals(modelUrl.toURI())) {
            return;
        }
    } catch (URISyntaxException e1) {
        throw new RuntimeException(e1.getMessage());
    }
    this.modelUrl = modelUrl;
    gazetteerClient = new GeoGazetteerClient(config);
    // Check if the NER model is available, and if the
    //  lucene-geo-gazetteer is available
    this.available = modelUrl != null && gazetteerClient.checkAvail();
    if (this.available) {
        try {
            TokenNameFinderModel model = new TokenNameFinderModel(modelUrl);
            this.nameFinder = new NameFinderME(model);
        } catch (Exception e) {
            LOG.warn("Named Entity Extractor setup failed: {}", e.getMessage(), e);
            this.available = false;
        }
    }
    initialized = true;
}
Also used : TokenNameFinderModel(opennlp.tools.namefind.TokenNameFinderModel) GeoGazetteerClient(org.apache.tika.parser.geo.topic.gazetteer.GeoGazetteerClient) NameFinderME(opennlp.tools.namefind.NameFinderME) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) TikaException(org.apache.tika.exception.TikaException) SAXException(org.xml.sax.SAXException)

Example 7 with TokenNameFinderModel

use of opennlp.tools.namefind.TokenNameFinderModel in project stanbol by apache.

the class OpenNLPTest method testLoadEnNER.

@Test
public void testLoadEnNER() throws IOException {
    for (String type : Arrays.asList("person", "organization", "location")) {
        TokenNameFinderModel model = openNLP.getNameModel(type, "en");
        Assert.assertNotNull(model);
        TokenNameFinder ner = openNLP.getNameFinder(type, "en");
        Assert.assertNotNull(ner);
    }
}
Also used : TokenNameFinder(opennlp.tools.namefind.TokenNameFinder) TokenNameFinderModel(opennlp.tools.namefind.TokenNameFinderModel) Test(org.junit.Test)

Aggregations

TokenNameFinderModel (opennlp.tools.namefind.TokenNameFinderModel)7 NameFinderME (opennlp.tools.namefind.NameFinderME)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 TokenNameFinder (opennlp.tools.namefind.TokenNameFinder)2 Span (opennlp.tools.util.Span)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 Scanner (java.util.Scanner)1 ChunkerModel (opennlp.tools.chunker.ChunkerModel)1 PerformanceMonitor (opennlp.tools.cmdline.PerformanceMonitor)1 POSModel (opennlp.tools.postag.POSModel)1 SentenceModel (opennlp.tools.sentdetect.SentenceModel)1 TokenizerModel (opennlp.tools.tokenize.TokenizerModel)1 InvalidFormatException (opennlp.tools.util.InvalidFormatException)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 AnalysedText (org.apache.stanbol.enhancer.nlp.model.AnalysedText)1 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)1