1

我正在使用Stanford Parser. 我收到一个错误:

无法将字符串解析为 Corelabel

这是一些代码:

List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for(CoreMap sentence: sentences) 
{
    CoreLabel temp=sentence.toString().replace(clust2, clust);
    sentences.set(m.sentNum-1,temp);              
}     
4

3 回答 3

0

你不能转换,虽然你可能可以转换,但这取决于是什么CoreLabel。在某些情况下,它可能是CoreLabel coreLabel = new CoreLabel (string)

于 2013-02-18T11:31:20.777 回答
0

以下函数存在于您可以使用的 CoreLabel.java 类下。

/** This is provided as a simple way to make a CoreLabel for a word from a String.
   *  It's often useful in fixup or test code. It sets all three of the Text, OriginalText,
   *  and Value annotations to the given value.
   *
   *  @param word The word string to make a CoreLabel for
   *  @return A CoreLabel for this word string
   */
  public static CoreLabel wordFromString(String word) {
    CoreLabel cl = new CoreLabel();
    cl.setWord(word);
    cl.setOriginalText(word);
    cl.setValue(word);
    return cl;
  }
于 2019-10-22T19:57:29.303 回答
0
public static void Parse() throws InvalidFormatException, IOException {
    // http://sourceforge.net/apps/mediawiki/opennlp/index.php?title=Parser#Training_Tool
    InputStream is = new FileInputStream("en-parser-chunking.bin");

    ParserModel model = new ParserModel(is);

    Parser parser = ParserFactory.create(model);

    String sentence = "Programcreek is a very huge and useful website.";
    Parse topParses[] = ParserTool.parseLine(sentence, parser, 1);

    for (Parse p : topParses)
        p.show();

    is.close();

    /*
     * (TOP (S (NP (NN Programcreek) ) (VP (VBZ is) (NP (DT a) (ADJP (RB
     * very) (JJ huge) (CC and) (JJ useful) ) ) ) (. website.) ) )
     */
}

你可能无法转换。但这段代码对你有用

于 2015-11-20T12:06:11.627 回答