如何在java中向corelabel强制转换字符串?
我正在使用斯坦福解析器。我得到一个错误: 无法将字符串解析为Corelabel 下面是一些代码:如何在java中向corelabel强制转换字符串?,java,casting,stanford-nlp,Java,Casting,Stanford Nlp,我正在使用斯坦福解析器。我得到一个错误: 无法将字符串解析为Corelabel 下面是一些代码: List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); for(CoreMap sentence: sentences) { CoreLabel temp=sentence.toString().replace(clust2, clust); sentenc
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);
}
您不能强制转换,但可能可以转换,但这取决于CoreLabel是什么。在某些情况下,可能是CoreLabel CoreLabel=新CoreLabel字符串
您可能无法转换。但是此代码将适用于u以下函数存在于您可以使用的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;
}
/** 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;
}