本文整理匯總了Java中edu.stanford.nlp.ling.CoreLabel.get方法的典型用法代碼示例。如果您正苦於以下問題:Java CoreLabel.get方法的具體用法?Java CoreLabel.get怎麽用?Java CoreLabel.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.stanford.nlp.ling.CoreLabel
的用法示例。
在下文中一共展示了CoreLabel.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Token
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public Token(Sentence sentence, CoreLabel coreLabel, int tokenIndex) {
this.sentence = sentence;
this.coreLabel = coreLabel;
this.index = tokenIndex;
// pure word
this.word = coreLabel.get(CoreAnnotations.TextAnnotation.class);
// this is the POS tag of the token
this.partOfSpeech = coreLabel.get(CoreAnnotations.PartOfSpeechAnnotation.class);
// this is the NE label of the token
this.namedEntity = coreLabel.get(CoreAnnotations.NamedEntityTagAnnotation.class);
// lema
this.lemma = coreLabel.get(CoreAnnotations.LemmaAnnotation.class);
this.characterOffsetBegin = coreLabel.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class);
this.characterOffsetEnd = coreLabel.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);
// resolve edge node in semantic graph for this label
this.typeDependency = findTypeDependency(sentence.semanticGraph(), coreLabel);
// stemmer
this.stem = new IteratedLovinsStemmer().stem(word);
}
示例2: readResultInContents
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
private void readResultInContents(Layer targetLayer, List<CoreLabel> tokenList, AtomicInteger n) {
int start = 0;
int end = 0;
String prevLabel = "O";
for (int i = 0; i < tokenList.size(); ++i) {
CoreLabel token = tokenList.get(i);
String label = token.get(CoreAnnotations.AnswerAnnotation.class);
if (!label.equals(prevLabel)) {
createAnnotation(targetLayer, start, end, prevLabel, n);
start = token.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class);
prevLabel = label;
}
end = token.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);
}
createAnnotation(targetLayer, start, end, prevLabel, n);
}
示例3: readResultInSentence
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
private void readResultInSentence(Layer targetLayer, Layer sentence, List<CoreLabel> tokenList, AtomicInteger n) {
int start = 0;
int end = 0;
String prevLabel = "O";
for (int i = 0; i < tokenList.size(); ++i) {
Annotation w = sentence.get(i);
CoreLabel token = tokenList.get(i);
String label = token.get(CoreAnnotations.AnswerAnnotation.class);
if (!label.equals(prevLabel)) {
createAnnotation(targetLayer, start, end, prevLabel, n);
start = w.getStart();
prevLabel = label;
}
end = w.getEnd();
}
createAnnotation(targetLayer, start, end, prevLabel, n);
}
示例4: preprocess
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public Concept preprocess(Concept c) {
if (this.tagger == null)
this.tagger = new MaxentTagger("ext_models/pos_tagger/english-left3words-distsim.tagger");
if (this.ner == null)
this.ner = CRFClassifier.getClassifierNoExceptions("ext_models/ner/english.all.3class.distsim.crf.ser.gz");
List<CoreLabel> words = tokFactory.getTokenizer(new StringReader(c.name)).tokenize();
tagger.tagCoreLabels(words);
words = ner.classifySentence(words);
words = this.addLemmas(words);
List<PToken> tokens = new ArrayList<PToken>();
for (CoreLabel word : words) {
PToken t = new PToken(word.originalText());
t.pos = word.tag();
t.neTag = word.get(CoreAnnotations.AnswerAnnotation.class);
t.lemma = word.get(LemmaAnnotation.class);
tokens.add(t);
}
c.tokenList = tokens;
return c;
}
示例5: addingContentWord
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
@Override public void addingContentWord(CoreLabel token) {
super.addingContentWord(token);
HashMap<Integer, HashMultimap<String, String>> easyWords = model.getEasyWords();
String simplePos = getGenericPos(token.get(CoreAnnotations.PartOfSpeechAnnotation.class));
String lemma = token.get(CoreAnnotations.LemmaAnnotation.class);
token.set(ReadabilityAnnotations.DifficultyLevelAnnotation.class, 4);
if (easyWords.get(3).get(simplePos).contains(lemma)) {
level3WordSize++;
token.set(ReadabilityAnnotations.DifficultyLevelAnnotation.class, 3);
}
if (easyWords.get(2).get(simplePos).contains(lemma)) {
level2WordSize++;
token.set(ReadabilityAnnotations.DifficultyLevelAnnotation.class, 2);
}
if (easyWords.get(1).get(simplePos).contains(lemma)) {
level1WordSize++;
token.set(ReadabilityAnnotations.DifficultyLevelAnnotation.class, 1);
}
}
示例6: getExampleTextFromSerGz
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
private static String getExampleTextFromSerGz(File f)
{
String result = "";
Annotation deserDoc = EntityLabeler.deserializeAnnotatedDoc(f.getAbsolutePath());
List<CoreMap> sentences = deserDoc.get(SentencesAnnotation.class);
for (int sentencenum = 0; sentencenum < sentences.size(); sentencenum++)
{
CoreMap sentence = sentences.get(sentencenum);
List<CoreLabel> labels = sentence.get(TokensAnnotation.class);
for (int i = 0; i < labels.size(); i++)
{
CoreLabel token = labels.get(i);
String tokenstring = token.get(TextAnnotation.class);
result += " " + tokenstring;
}
result = result.trim() + "\n";
}
return result;
}
示例7: extractNER
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public static List<String> extractNER(String doc){
Annotation document = new Annotation(doc);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
List<String> result = new ArrayList<String>();
for(CoreMap sentence: sentences) {
// traversing the words in the current sentence
// a CoreLabel is a CoreMap with additional token-specific methods
for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
// this is the text of the token
String word = token.get(CoreAnnotations.TextAnnotation.class);
// this is the POS tag of the token
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
// this is the NER label of the token
String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
result.add(ne);
}
}
return result;
}
示例8: extractNER
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public static List<String> extractNER(String doc){
Annotation document = new Annotation(doc);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
List<String> result = new ArrayList<String>();
for(CoreMap sentence: sentences) {
// traversing the words in the current sentence
// a CoreLabel is a CoreMap with additional token-specific methods
for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
// this is the text of the token
String word = token.get(CoreAnnotations.TextAnnotation.class);
// this is the NER label of the token
String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
result.add(ne);
System.out.println(word + "\t" + ne);
}
}
return result;
}
示例9: TokenizedCoreLabelWrapper
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
/**
*
*/
public TokenizedCoreLabelWrapper(final CoreLabel cl) {
this.value = cl.get(ValueAnnotation.class);
this.text = cl.get(TextAnnotation.class);
LOGGER.trace("Wrapping token text: {}", this.text);
this.originalText = cl.get(OriginalTextAnnotation.class);
this.before = cl.get(BeforeAnnotation.class);
this.after = cl.get(AfterAnnotation.class);
this.startSentenceOffset = cl.get(CharacterOffsetBeginAnnotation.class);
this.endSentenceOffset = cl.get(CharacterOffsetEndAnnotation.class);
this.startOffset = Optional.ofNullable(cl.get(TokenBeginAnnotation.class));
this.endOffset = Optional.ofNullable(cl.get(TokenEndAnnotation.class));
LOGGER.trace("TokenBegin: {}", this.startOffset);
LOGGER.trace("TokenEnd: {}", this.endOffset);
this.idx = cl.get(IndexAnnotation.class);
this.sentenceIdx = cl.get(SentenceIndexAnnotation.class);
LOGGER.trace("Got sentence idx: {}", this.sentenceIdx);
}
示例10: sentenceSplitter
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public static List<String> sentenceSplitter(List<CoreMap> sentences) {
List<String> sentenceList = new ArrayList<String>();
for (CoreMap sentence : sentences) {
String sentenceString = "";
for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
String word = token.get(TextAnnotation.class);
sentenceString += word + " ";
}
sentenceList.add(sentenceString);
}
return sentenceList;
}
示例11: main
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public static void main (String[] args) {
String string = "I went into my bedroom and flipped the light switch. Oh, I see that the ceiling lamp is not turning on." +
" It must be that the light bulb needs replacement. I go through my closet and find a new light bulb that will fit" +
" this lamp and place it in my pocket. I also get my stepladder and place it under the lamp. I make sure the light" +
" switch is in the off position. I climb up the ladder and unscrew the old light bulb. I place the old bulb in my " +
"pocket and take out the new one. I then screw in the new bulb. I climb down the stepladder and place it back into " +
"the closet. I then throw out the old bulb into the recycling bin. I go back to my bedroom and turn on the light switch." +
" I am happy to see that there is again light in my room.";
Properties prop = new Properties();
prop.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
//prop.setProperty("parse.model", "edu/stanford/nlp/models/parser/nndep/english_SD.gz");
StanfordCoreNLP pipeline = new StanfordCoreNLP(prop);
Annotation annotation = new Annotation(string);
pipeline.annotate(annotation); // add annotation to pipeline
// a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for(CoreMap sentence: sentences) {
for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
// this is the text of the token
String word = token.get(CoreAnnotations.TextAnnotation.class);
// this is the POS tag of the token
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
// this is the NER label of the token
//String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
System.out.print(word + "/" + pos);
}
System.out.println("\n");
// this is the parse tree of the current sentence
Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
System.out.println("parse tree:\n" + tree);
SemanticGraph dependencies = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
System.out.println("dependency graph:\n" + dependencies);
}
}
示例12: getPersons
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
static TreeSet<String> getPersons(SemanticGraph semanticGraph, IndexedWord word, CoreMap sentence) {
Stack<IndexedWord> wordsToCheck = new Stack<>();
wordsToCheck.add(word);
int index = word.index();
while (!wordsToCheck.isEmpty()) {
IndexedWord thisWord = wordsToCheck.pop();
List<SemanticGraphEdge> outEdgesSorted = semanticGraph.getOutEdgesSorted(thisWord);
for (SemanticGraphEdge semanticGraphEdge : outEdgesSorted) {
IndexedWord dependent = semanticGraphEdge.getDependent();
String pos = dependent.get(CoreAnnotations.PartOfSpeechAnnotation.class);
if (pos.equals("VA")) {
index = Math.min(index, dependent.index());
wordsToCheck.push(dependent);
}
}
}
CoreLabel token = sentence.get(CoreAnnotations.TokensAnnotation.class).get(index - 1);
String morpho = token.get(DigiMorphAnnotations.MorphoAnnotation.class);
String[] parts = morpho.split("\\s+");
TreeSet<String> persons = new TreeSet<>();
for (int i = 1; i < parts.length; i++) {
String[] vParts = parts[i].split("\\+");
if (!vParts[1].equals("v")) {
continue;
}
persons.add(vParts[5] + "+" + vParts[6]);
}
return persons;
}
示例13: annotate
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
@Override
public void annotate(Annotation annotation) {
if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
for (CoreLabel c : tokens) {
String[] morph_fatures = c.get(DigiMorphAnnotations.MorphoAnnotation.class).split(" ");
String lemma = c.get(CoreAnnotations.LemmaAnnotation.class);
if (morph_fatures.length > 1) {
List<String> comps = new ArrayList<>();
for (String m : morph_fatures) {
if (m.startsWith(lemma + "+") || m.startsWith(lemma + "~")) {
comps.add(m);
}
}
c.set(DigiMorphAnnotations.MorphoCompAnnotation.class, comps);
} else {
if (morph_fatures[0].startsWith(lemma + "+") || morph_fatures[0].startsWith(lemma + "~")) {
c.set(DigiMorphAnnotations.MorphoCompAnnotation.class,
new ArrayList<String>(Arrays.asList(morph_fatures[0])));
}
}
}
}
}
}
示例14: tagTokens
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public List<String> tagTokens(String text) {
List<String> tagged = new ArrayList<String>();
Annotation document = runPipeline(text);
// these are all the sentences in this document
// a CoreMap is essentially a Map that uses class objects as keys
// and has values with custom types
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
// traversing the words in the current sentence
// a CoreLabel is a CoreMap with additional token-specific methods
for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
// this is the text of the token
String word = token.get(TextAnnotation.class);
// this is the POS tag of the token
String pos = token.get(PartOfSpeechAnnotation.class);
// this is the NER label of the token
String ne = token.get(NamedEntityTagAnnotation.class);
// this is the lemma of the token
String lemma = token.get(LemmaAnnotation.class);
// this is the sentence index
int sentId = token.get(SentenceIndexAnnotation.class);
tagged.add(word + "/" + pos + "/" + ne + "/" + lemma + "/" + sentId);
}
}
return tagged;
}
示例15: annotateText
import edu.stanford.nlp.ling.CoreLabel; //導入方法依賴的package包/類
public Multimap<String, String> annotateText(String text) {
loadResource();
Multimap<String, String> taggerTokens = ArrayListMultimap.create();
Annotation document = new Annotation(text);
pipeline.annotate(document);
for (CoreLabel token : document.get(TokensAnnotation.class)) {
String ne = token.get(NamedEntityTagAnnotation.class);
String word = token.get(TextAnnotation.class);
taggerTokens.put(ne, word);
}
return taggerTokens;
}