我已经标记了20个句子,这是我的代码:
public class myTag {
public static void main(String[] args) {
Properties props = new Properties();
try {
props.load(new FileReader("D:/tagger/english-bidirectional-distsim.tagger.props"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MaxentTagger tagger = new MaxentTagger("D:/tagger/english-bidirectional-distsim.tagger",props);
//==================================================================================================
try (BufferedReader br = new BufferedReader(new FileReader("C:/Users/chelsea/Desktop/EN/EN.txt")))
{
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
String tagged = tagger.tagString(sCurrentLine);
System.out.println(tagged);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
这是输出:
正如您在句子节点中看到的那样,它具有Id属性,并且在这里它不停地= 0,我不应该这样。我期望值是= 0、1、2、3、4,...
我不明白我的代码有什么问题。
最佳答案
Stanford POS标记器(严格来说,是在POS注释器之前应用的句子拆分器)为每个输入文本生成句子的ID。
因此,您要求tagger
标记由一个句子组成的sCurrentLine
,该文本被拆分为多个句子-实际上,只有一个,id = 0;然后您要求标记下一个迭代中的另一个文本-sCurrentLine
-它又是唯一的句子,因此它是id = 0的第一个句子;等等。
因此,如果您想要正确的ID,请先创建整个文本,然后将其传递给tagger
。但是,如果您的输入文本已被句子分割,最好将其保留原样(并在需要时由您自己在循环中生成ID)。