【问题标题】:Locate models in Stanford NLP for .NET在 Stanford NLP for .NET 中定位模型
【发布时间】:2018-01-31 14:39:36
【问题描述】:

我正在尝试将斯坦福 NLP 用于 .NET。我对此很陌生,我在加载模型时遇到了麻烦。

我在https://sergey-tihon.github.io/Stanford.NLP.NET//faq.htmlStanford.NLP for .NET not loading models 中阅读过相同类型的问题。但我不知道他们将“stanford-corenlp-full-2016-10-31”文件夹保存在哪里。

这是我有 C# 代码的地方。 C:\Users\Kabi\source\repos\Search\Search stanford-corenlp-full-2017-06-09 文件夹在这里 - C:\Users\Kabi\source\repos\Search

我在 C:\Users\Kabi\source\repos\Search\stanford-corenlp-full-2017- 中提取了 stanford-corenlp-3.8.0-models.jar 06-09

这是我的 C# 代码。

浏览.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.IO;
using java.util;
using java.io;
using edu.stanford.nlp.pipeline;
using Console = System.Console;

namespace Search
{
    class Browse
    {
    public void StanfordNLP()
    {
        // Path to the folder with models extracted from `stanford-corenlp-3.8.0-models.jar`
        var jarRoot = @"..\stanford-corenlp-full-2017-06-09";

        // Text for processing
        var text = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply.";

        // 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();
        }

    }

}

}

如何正确加载模型?

【问题讨论】:

    标签: c# .net stanford-nlp


    【解决方案1】:

    您似乎无法找到您的模态文件尝试使用此:- 我在我的项目的根文件夹下复制了 stanford-corenlp-full-2017-06-09,即 NLP,如图 1 所示,第二个显示了我如何提取 stanford-corenlp-3.8.0-models 。罐 The directory Structure of files 这样做后使用 var jarRoot = @"......\stanford-corenlp-full-2016-10-31\stanford-corenlp-3.7.0-models";

    很简单

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多