【问题标题】:How do I generate an xml output from standfordner classifier?如何从 Standfordner 分类器生成 xml 输出?
【发布时间】:2016-06-26 15:08:48
【问题描述】:

我使用standfordNER 分类器对文本进行分类。 这是代码。

string docText = fileContent;
        string txt = "";
        var classified = Classifier.classifyToCharacterOffsets(docText).toArray();

        for (int i = 0; i < classified.Length; i++)
        {
            Triple triple = (Triple)classified[i];

            int second = Convert.ToInt32(triple.second().ToString());
            int third = Convert.ToInt32(triple.third().ToString());
            txt = txt + ('\t' + triple.first().ToString() + '\t' + docText.Substring(second, third - second));

            string s = Classifier.classifyWithInlineXML(txt);
            string s1 = Classifier.classifyToString(s, "xml", true);
            Panel1.GroupingText = s1;

        }


        Panel1.Visible = true;

这是输出:

LOCATION    Lanka LOCATION  colombo ORGANIZATION microsoft

但我需要一个像这样的 xml 格式的输出

<LOCATION>  Lanka </LOCATION>   <LOCATION>colombo</LOCATION>    <ORGANIZATION> microsoft</ORGANIZATION> 

在我使用过的代码中,

 string s = Classifier.classifyWithInlineXML(txt);
            string s1 = Classifier.classifyToString(s, "xml", true);

获取xml,但它不起作用。因为我是这个领域的新手,请帮我解决这个问题。 非常感谢

【问题讨论】:

    标签: xml stanford-nlp named-entity-recognition information-extraction


    【解决方案1】:

    这个示例代码应该会有所帮助:

       String content = "...";
       String classifierPath = "edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz";
       AbstractSequenceClassifier<CoreLabel> asc  = CRFClassifier.getClassifierNoExceptions(classifierPath);
       String result = asc.classifyWithInlineXML(content);
    

    【讨论】:

      猜你喜欢
      • 2013-11-05
      • 2012-05-23
      • 1970-01-01
      • 2020-12-08
      • 2017-02-06
      • 2013-03-01
      • 2011-06-27
      • 1970-01-01
      • 2014-05-24
      相关资源
      最近更新 更多