如何从 standfordner 分类器生成 xml 输出?

How do I generate an xml output from standfordner classifier?

我使用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 ,但它不起作用。因为我是这个领域的新手,请帮我解决这个问题。 非常感谢

此示例代码应该会有帮助:

   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);