如何将字符串标记转换为CoreLabel实例(StanfordNLP)?

如何将字符串标记转换为CoreLabel实例(StanfordNLP)?,nlp,stanford-nlp,text-mining,Nlp,Stanford Nlp,Text Mining,我们可以将字符串标记转换为实例吗 到目前为止,我正在使用: CoreLabelTokenFactory c = new CoreLabelTokenFactory(); CoreLabel tokens = c.makeToken("going",0,"going".length()); 字符串被转换,但是通过这种方法,corelab无法找到引理和位置。下面是一些示例代码,演示如何从原始字符串转换为注释对象: import java.io.*; import java.util.*; im

我们可以将字符串标记转换为实例吗

到目前为止,我正在使用:

CoreLabelTokenFactory c = new CoreLabelTokenFactory();  
CoreLabel tokens = c.makeToken("going",0,"going".length());

字符串被转换,但是通过这种方法,
corelab
无法找到引理和位置。

下面是一些示例代码,演示如何从原始字符串转换为注释对象:

import java.io.*;
import java.util.*;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.ling.CoreAnnotations.*;
import edu.stanford.nlp.util.*;

public class TokenizeExample {

    public static void main (String[] args) throws IOException {
        String text = "Here is a sentence.  Here is another sentence.";
        Annotation document = new Annotation(text);
        Properties props = new Properties();
        props.setProperty("annotators", "tokenize, ssplit, pos, lemma");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        pipeline.annotate(document);
        for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
            for (CoreLabel cl : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
                System.out.println("---");
                System.out.println(cl);
                System.out.println(cl.get(CoreAnnotations.PartOfSpeechAnnotation.class));
                System.out.println(cl.get(CoreAnnotations.LemmaAnnotation.class));
            }
        }
    }
}

确保您从这里获得了Stanford CoreNLP 3.5.2:

以下是一些示例代码,演示如何从原始字符串转换为注释对象:

import java.io.*;
import java.util.*;
import edu.stanford.nlp.io.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.ling.CoreAnnotations.*;
import edu.stanford.nlp.util.*;

public class TokenizeExample {

    public static void main (String[] args) throws IOException {
        String text = "Here is a sentence.  Here is another sentence.";
        Annotation document = new Annotation(text);
        Properties props = new Properties();
        props.setProperty("annotators", "tokenize, ssplit, pos, lemma");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        pipeline.annotate(document);
        for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
            for (CoreLabel cl : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
                System.out.println("---");
                System.out.println(cl);
                System.out.println(cl.get(CoreAnnotations.PartOfSpeechAnnotation.class));
                System.out.println(cl.get(CoreAnnotations.LemmaAnnotation.class));
            }
        }
    }
}

确保从这里获得斯坦福CoreNLP 3.5.2:

制作CoreLabels的用例是什么?我认为引理和pos不存在,因为它们可能没有通过管道,因此您必须自己提供它们。制作CoreLabels的用例是什么?我可以想象引理和pos不在那里,因为它们可能没有通过管道,因此您必须自己提供它们。