Fatal error loading tagger model using nugetpackages

I am trying to create and run a simple program using stunford-corenlp-3.5.2 nugetpackage.

However, after searching for the code for beginners, I found the following code: props.setProperty ("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref") (link to an example code: http: //sergey-tihon.github .io / Stanford.NLP.NET / StanfordCoreNLP.html )

But whenever the console application loads, it launches a runtime error, stating that it cannot load the tagger.

I am wondering if I am missing any nugetpackages or if there is an additional setup that I have to go through. (Note that anytime I try to add, say, a naget package for postagger, I get an error message indicating that the Annotation class references two dll libraries.)

I found that if I delete some properties, the application will work correctly, so the new line will look like this: "props.setProperty (" annotators "," tokenize, ssplit ");

Any help to get past the runtime error so that I can continue further analysis of the sample text would be greatly appreciated. Thanks.

Attached image for reference (apparently, I need more reputation to post the pic, but when I can, I will do it right away :) Edit I added the photo now :) enter image description here

stack trace when line is thrown looks like this:

at edu.stanford.nlp.pipeline.AnnotatorFactories.4.create()
at edu.stanford.nlp.pipeline.AnnotatorPool.get(String name)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(Properties , Boolean , AnnotatorImplementations )
at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props, Boolean enforceRequirements)
at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props)
at ConApplicationSabrinaNLP.TestClass.donlp() in c:\Users\Justin\Documents\Visual Studio 2013\Projects\ConApplicationSabrinaNLP\ConApplicationSabrinaNLP\TestClass.cs:line 28
at ConApplicationSabrinaNLP.Program.Main(String[] args) in c:\Users\Justin\Documents\Visual Studio 2013\Projects\ConApplicationSabrinaNLP\ConApplicationSabrinaNLP\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
+4
source share
1 answer

The problem is that you did not load the models. The Nuget package does not work on its own. You must download the latest version here POS-Tagger

, . . 3.6.0 2015-12-09 , , "english-twoirectional-distsim.tagger". , , .

windows forms.

using java.io;
using java.util;
using edu.stanford.nlp.ling;
using edu.stanford.nlp.tagger.maxent;
using Console = System.Console;
using System.IO;
using System.Windows.Forms;

namespace Stanford.NLP.POSTagger.CSharp
{
    class PosTagger

    {
        // get the base folder for the project
        public static string GetAppFolder()
        {
            return Path.GetDirectoryName(Application.ExecutablePath).Replace(@"*your project directory here*\bin\Debug", string.Empty);
        }

        public void testTagger()
        {
            var jarRoot = Path.Combine(GetAppFolder(), @"packages\stanford-postagger-2015-12-09");
            Console.WriteLine(jarRoot.ToString());
            var modelsDirectory = jarRoot + @"\models";

            // Loading POS Tagger
            var tagger = new MaxentTagger(modelsDirectory + @"\english-bidirectional-distsim.tagger");

            // Text for tagging
            var text = "A Part-Of-Speech Tagger (POS Tagger) is a piece of software that reads text"
                       + "in some language and assigns parts of speech to each word (and other token),"
                       + " such as noun, verb, adjective, etc., although generally computational "
                       + "applications use more fine-grained POS tags like 'noun-plural'.";

            var sentences = MaxentTagger.tokenizeText(new java.io.StringReader(text)).toArray();
            foreach (ArrayList sentence in sentences)
            {
                var taggedSentence = tagger.tagSentence(sentence);
                Console.WriteLine(Sentence.listToString(taggedSentence, false));
            }
        }
    }
}
+1

All Articles