sergey-tihon / Stanford.NLP.NET

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

Exception in CoreNLP.Simple sample #89

Closed Vasyl-Za closed 5 years ago

Vasyl-Za commented 5 years ago

This is regarding Sergey Tihon's sample published here:

Simple CoreNLP http://sergey-tihon.github.io/Stanford.NLP.NET//samples/CoreNLP.Simple.html

Equivalent C# code:

using System;
using java.util;
using edu.stanford.nlp.simple; 
using Console = System.Console;

namespace SimpleCoreNLP
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string jarRoot = @"..\..\..\..\data\paket-files\nlp.stanford.edu\stanford-corenlp-full-2018-02-27\models";

                var props = new Properties();
                props.setProperty("ner.useSUTime", "0");

                string curDir = Environment.CurrentDirectory;
                Directory.SetCurrentDirectory(jarRoot);

                string text = "Lucy is in the sky with diamonds.";
                Sentence sent = new Sentence(text);

                var netTags = sent.nerTags();
                string firstPOSTag = sent.posTag(0);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION: " + e.Message);
            }
        }
    }
}

throws an exception:

Error creating edu.stanford.nlp.time.TimeExpressionExtractorImpl

at the line:

var netTags = sent.nerTags();

jarRoot and models are correct and present: if you comment out offending line var netTags = sent.nerTags();, the following

string firstPOSTag = sent.posTag(0);

works fine.

sergey-tihon commented 5 years ago

@Vasyl-Za The trick is in props

The original F# sample do it like this

let props = Properties()
props.setProperty("ner.useSUTime","0") |> ignore

let sent : Sentence = new Sentence("Lucy is in the sky with diamonds.")
let nerTags : List = sent.nerTags(props); // <---- uses props

in your C# sample you do not pass them to the function

var netTags = sent.nerTags();

this line should look like

var netTags = sent.nerTags(props);

I do not know the root cause but use of SUTime for ner does not work out-of-the-box in .NET version. The easiest fix is to turn this off

Vasyl-Za commented 5 years ago

@sergey-tihon - Many thanks! My fault: missed props as an argument - your F# code does have it.