sergey-tihon / Stanford.NLP.NET

Stanford NLP for .NET
http://sergey-tihon.github.io/Stanford.NLP.NET/
MIT License
598 stars 123 forks source link

An unhandled exception of type 'System.TypeInitializationException' occurred #23

Closed crack521 closed 9 years ago

crack521 commented 9 years ago

Hello, I am trying to run through your example code, and I ran into this error: An unhandled exception of type 'System.TypeInitializationException' occurred in stanford-corenlp-3.5.2.dll Additional information: The type initializer for 'edu.stanford.nlp.util.Timing' threw an exception I copied your example exactly, and I am using 3.5.2. What could I be doing wrong?

sergey-tihon commented 9 years ago

Please try to turn of SUTime

props.setProperty("ner.useSUTime", "false") |> ignore
crack521 commented 9 years ago

I changed the value of props as you suggested,but this error occurred again,What could I be doing wrong?

sergey-tihon commented 9 years ago

@crack521 Could you please paste your source code here? (So I was able to run it)

crack521 commented 9 years ago
            java.util.Properties props = new java.util.Properties();

            var jarRoot = @"E:\codehub\java\stanford-corenlp-full-2015-04-20\stanford-corenlp-full-2015-04-20\stanford-corenlp-3.5.2-models\";
            var modelsDirectory = jarRoot + @"\edu\stanford\nlp\models";

            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            props.setProperty("ner.useSUTime", "0");

            var curDir = Environment.CurrentDirectory;
            Directory.SetCurrentDirectory(jarRoot);
            StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
            Directory.SetCurrentDirectory(curDir);

            String text = "Dan Ramage is working for\nMicrosoft. He's in Seattle! \n";
            Annotation document = new Annotation(text);
            pipeline.annotate(document);
            var sentences = document.get(typeof(CoreAnnotations.SentencesAnnotation));
crack521 commented 9 years ago

When the program runs,it occurs errors in the line of " StanfordCoreNLP pipeline = new StanfordCoreNLP(props);" An unhandled exception of type 'System.TypeInitializationException' occurred in stanford-corenlp-3.5.2.dll Additional information: The type initializer for 'edu.stanford.nlp.util.Timing' threw an exception

toncho11 commented 9 years ago

Change the culture in .NET to "US".

    CultureInfo ci = new CultureInfo("en-US");
    Thread.CurrentThread.CurrentCulture = ci;
    Thread.CurrentThread.CurrentUICulture = ci;

    tagger = new MaxentTagger(modelsDirectory + @"\french.tagger");

I had the same problem. On 2 computers it works fine and on 2 other it does not. So I figured it was something in the environment related to time, so I changed the culture. I am working with the POS tagger for French text.

crack521 commented 9 years ago

@toncho11 Thanks a lot!

sergey-tihon commented 9 years ago

@toncho11 Thank you for help. @crack521 Please close this issue if the it is resolved