Пример #1
0
        public void NameFinder()
        {
            using var modelIn = new java.io.FileInputStream(GetModel("en-ner-person.bin"));

            var model      = new opennlp.tools.namefind.TokenNameFinderModel(modelIn);
            var nameFinder = new opennlp.tools.namefind.NameFinderME(model);

            var sentence  = new[] { "Pierre", "Vinken", "is", "61", "years", "old", "." };
            var nameSpans = nameFinder.find(sentence);

            System.Console.WriteLine(string.Join(";", nameSpans.Select(x => x.toString())));

            Assert.AreEqual(1, nameSpans.Length);
        }
Пример #2
0
        private void Initial()
        {
            var basedir          = (string)GlobalParameter.Get(DefaultParameter.Field.opennlp_model_dir);
            var modelInputStream = new java.io.FileInputStream(Path.Combine(basedir, "en-ner-location.bin")); //load the name model into a stream
            var model            = new opennlp.tools.namefind.TokenNameFinderModel(modelInputStream);         //load the model

            locationNameFinder = new opennlp.tools.namefind.NameFinderME(model);                              //create the namefinder
            modelInputStream   = new java.io.FileInputStream(Path.Combine(basedir, "en-ner-person.bin"));
            model                  = new opennlp.tools.namefind.TokenNameFinderModel(modelInputStream);
            personNameFinder       = new opennlp.tools.namefind.NameFinderME(model);
            modelInputStream       = new java.io.FileInputStream(Path.Combine(basedir, "en-ner-organization.bin"));
            model                  = new opennlp.tools.namefind.TokenNameFinderModel(modelInputStream);
            organizationNameFinder = new opennlp.tools.namefind.NameFinderME(model);
        }