我正在使用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);
}
答案 0 :(得分:0)
你可以转换,但你可以转换,但这取决于CoreLabel
是什么。在某些情况下,它可能是CoreLabel coreLabel = new CoreLabel (string)
。
答案 1 :(得分: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.) ) )
*/
}
你可能无法转换。但这段代码适用于你
答案 2 :(得分: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;
}