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

Hi excuse,how can i run this in chinese model #76

Closed leezhihui closed 3 years ago

leezhihui commented 6 years ago

the code is like this it can run when process english text but it can not process the chinese text

static void Main(string[] args)
        {
            // Path to the folder with models extracted from `stanford - corenlp - 3.7.0 - models.jar`
            var jarRoot = @"stanford-english-corenlp-2017-06-09-models\";
            var jarRoot2 = @"stanford-chinese-corenlp-2017-06-09-models\";

            // Text for processing
            var text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";
            //var text = "我爱北京天安门。天安门上太阳升。";

            // Annotation pipeline configuration
            var props = new Properties();
            props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            props.setProperty("ner.useSUTime", "0");

            // We should change current directory, so StanfordCoreNLP could find all the model files automatically
            var curDir = Environment.CurrentDirectory;
            Directory.SetCurrentDirectory(jarRoot);
            var pipeline = new StanfordCoreNLP(props);
            Directory.SetCurrentDirectory(curDir);

            // Annotation
            var annotation = new Annotation(text);
            pipeline.annotate(annotation);

            // Result - Pretty Print
            using (var stream = new ByteArrayOutputStream())
            {
                pipeline.prettyPrint(annotation, new PrintWriter(stream));
                Console.WriteLine(stream.toString());
                stream.close();
            }

the code is comes from here ,i want to do some annotation about chinese text http://sergey-tihon.github.io/Stanford.NLP.NET/StanfordCoreNLP.html and i change the model directory to chinese but it did't work. the program still under the english model ,how can i set someting to deal with the chinese . can you help me ?

sergey-tihon commented 6 years ago

Do you have an error message?)

My initial guess that you still use jarRoot directory models instead of jarRoot2

 Directory.SetCurrentDirectory(jarRoot);
var pipeline = new StanfordCoreNLP(props);
leezhihui commented 6 years ago

when i use the jarRoot2 error message:

edu.stanford.nlp.io.RuntimeIOException occurred
  HResult=0x80131500
  Message=Error while loading a tagger model (probably missing model file)
  Source=stanford-corenlp-3.8.0
  StackTrace:
   at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(Properties config, String modelFileOrUrl, Boolean printLoading)
   at edu.stanford.nlp.tagger.maxent.MaxentTagger..ctor(String modelFile, Properties config, Boolean printLoading)
   at edu.stanford.nlp.tagger.maxent.MaxentTagger..ctor(String modelFile)
   at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(String , Boolean )
   at edu.stanford.nlp.pipeline.POSTaggerAnnotator..ctor(String annotatorName, Properties props)
   at edu.stanford.nlp.pipeline.AnnotatorImplementations.posTagger(Properties properties)
   at edu.stanford.nlp.pipeline.StanfordCoreNLP.lambda$getNamedAnnotators$42(Properties , AnnotatorImplementations )
   at edu.stanford.nlp.pipeline.StanfordCoreNLP.__<>Anon4.apply(Object , Object )
   at edu.stanford.nlp.pipeline.StanfordCoreNLP.lambda$getDefaultAnnotatorPool$65(Entry , Properties , AnnotatorImplementations )
   at edu.stanford.nlp.pipeline.StanfordCoreNLP.__<>Anon27.get()
   at edu.stanford.nlp.util.Lazy.3.compute()
   at edu.stanford.nlp.util.Lazy.get()
   at edu.stanford.nlp.pipeline.AnnotatorPool.get(String name)
   at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(Properties , Boolean , AnnotatorImplementations , AnnotatorPool )
   at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props, Boolean enforceRequirements, AnnotatorPool annotatorPool)
   at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props, Boolean enforceRequirements)
   at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props)
   at StanfordNLP.Program.Main(String[] args) in C:\Users\admin\source\repos\StanfordNLP\StanfordNLP\Program.cs:line 34
Inner Exception 1:
IOException: Unable to open "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as class path, filename or URL

thank you for your concerning . because i am in China, there is a 12 hours time difference, after one hour you may get up .

cherryywei commented 6 years ago

你好,我也是中国学生,目前也在试着做句法分析,能沟通一下吗?

sergey-tihon commented 6 years ago

I do not have ready solution for correct bootstrapping for chinese, sorry

I can only suggest the direction

// Text for processing var text = "你好,我也是中国学生,目前也在试着做句法分析,能沟通一下吗?";

// Annotation pipeline configuration var propsFile = Path.Combine(jarRoot2, "StanfordCoreNLP-chinese.properties"); var props = new Properties(); //props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, mention, coref"); props.load(new FileReader(propsFile)); props.setProperty("ner.useSUTime", "0");

// We should change current directory, so StanfordCoreNLP could find all the model files automatically var curDir = Environment.CurrentDirectory; Directory.SetCurrentDirectory(jarRoot2); var pipeline = new StanfordCoreNLP(props); Directory.SetCurrentDirectory(curDir);

// Annotation var annotation = new Annotation(text); pipeline.annotate(annotation);

// Result - Pretty Print using (var stream = new ByteArrayOutputStream()) { pipeline.prettyPrint(annotation, new PrintWriter(stream)); Console.WriteLine(stream.toString()); stream.close(); }


- try to understand new errors/find java sample that works
leezhihui commented 6 years ago

thank you

leezhihui commented 6 years ago

My email 1446129333@qq.com @cherryywei

leezhihui commented 6 years ago

i use the code you paste above ,it works a little but occurs erro the error message is

`java.lang.RuntimeException occurred HResult=0x80131500 Message=java.lang.RuntimeException: Error initializing coref system Source=stanford-corenlp-3.8.0 StackTrace: at edu.stanford.nlp.pipeline.CorefAnnotator..ctor(Properties props) at edu.stanford.nlp.pipeline.AnnotatorImplementations.coref(Properties properties) at edu.stanford.nlp.pipeline.StanfordCoreNLP.lambda$getNamedAnnotators$53(Properties , AnnotatorImplementations ) at edu.stanford.nlp.pipeline.StanfordCoreNLP.<>Anon15.apply(Object , Object ) at edu.stanford.nlp.pipeline.StanfordCoreNLP.lambda$getDefaultAnnotatorPool$65(Entry , Properties , AnnotatorImplementations ) at edu.stanford.nlp.pipeline.StanfordCoreNLP.<>Anon27.get() at edu.stanford.nlp.util.Lazy.3.compute() at edu.stanford.nlp.util.Lazy.get() at edu.stanford.nlp.pipeline.AnnotatorPool.get(String name) at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(Properties , Boolean , AnnotatorImplementations , AnnotatorPool ) at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props, Boolean enforceRequirements, AnnotatorPool annotatorPool) at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props, Boolean enforceRequirements) at edu.stanford.nlp.pipeline.StanfordCoreNLP..ctor(Properties props) at StanfordNLP.Program.Main(String[] args) in C:\Users\admin\source\repos\StanfordNLP\StanfordNLP\Program.cs:line 47

Inner Exception 1: RuntimeException: Error initializing coref system

Inner Exception 2: RuntimeIOException: java.io.IOException: Unable to open "edu/stanford/nlp/models/dcoref/demonyms.txt" as class path, filename or URL

Inner Exception 3: IOException: Unable to open "edu/stanford/nlp/models/dcoref/demonyms.txt" as class path, filename or URL`

i open the folder along the path, and do not find the directory [coref] in the location ,so there is no file dmonyms.txt.

if you have time please pay some attention .

sergey-tihon commented 6 years ago

I think that if should exist in http://nlp.stanford.edu/software/stanford-corenlp-full-2017-06-09.zip