【问题标题】:stanford nlp tokenizer斯坦福 nlp 分词器
【发布时间】:2012-10-11 20:06:44
【问题描述】:

如何使用 stanford 解析器标记 java 类中的字符串?

我只能找到 documentProcessor 和 PTBTokenizer 从外部文件中获取文本的示例。

 DocumentPreprocessor dp = new DocumentPreprocessor("hello.txt");
   for (List sentence : dp) {
    System.out.println(sentence);
  }
  // option #2: By token

   PTBTokenizer ptbt = new PTBTokenizer(new FileReader("hello.txt"),
          new CoreLabelTokenFactory(), "");
  for (CoreLabel label; ptbt.hasNext(); ) {
    label = (CoreLabel) ptbt.next();
    System.out.println(label);
  }

谢谢。

【问题讨论】:

    标签: tokenize stanford-nlp


    【解决方案1】:

    PTBTokenizer 构造函数采用 java.io.Reader,然后您可以使用 StringReader 来解析您的文本

    【讨论】:

    • 你能写出构造函数的代码吗?我该如何使用阅读器。谢谢
    • 没关系,这给了我标记: List rawWords = tokenizerFactory.getTokenizer(new StringReader(sentence)).tokenize(); System.out.println(rawWords.get(0).value());
    • 我花了一些时间打开 NetBeans,制作一个新项目,等等......然后停电......该死......
    • @Naveen 感谢您分享您的解决方案!但是,每次传入不同的句子时,这不会创建一个新的 PTBTokenizer 对象吗?如果您有多个句子,我想您的解决方案的前一步是将它们连接成一个字符串“句子”,然后在“句子”上使用您的解决方案?
    猜你喜欢
    • 2015-04-30
    • 1970-01-01
    • 2015-11-12
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    相关资源
    最近更新 更多