本文整理了Java中edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation.getSentenceFromToken()
方法的一些代码示例,展示了TextAnnotation.getSentenceFromToken()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextAnnotation.getSentenceFromToken()
方法的具体详情如下:
包路径:edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation
类名称:TextAnnotation
方法名:getSentenceFromToken
[英]Gets the sentence containing the specified token
[中]获取包含指定标记的句子
代码示例来源:origin: CogComp/cogcomp-nlp
@Override
public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
Sentence sentence = ta.getSentenceFromToken(wordPosition);
int sentenceStart = sentence.getStartSpan();
int predicatePosition = wordPosition - sentenceStart;
Tree<String> tree = ParseHelper.getParseTree(parseViewName, sentence);
Tree<Pair<String, IntPair>> spanLabeledTree = ParseUtils.getSpanLabeledTree(tree);
Tree<Pair<String, IntPair>> currentNode =
spanLabeledTree.getYield().get(predicatePosition).getParent();
String f = getVoice(currentNode);
return new LinkedHashSet<Feature>(Collections.singletonList(DiscreteFeature.create(f)));
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-edison
@Override
public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException {
Sentence sentence = ta.getSentenceFromToken(wordPosition);
int sentenceStart = sentence.getStartSpan();
int predicatePosition = wordPosition - sentenceStart;
Tree<String> tree = ParseHelper.getParseTree(parseViewName, sentence);
Tree<Pair<String, IntPair>> spanLabeledTree = ParseUtils.getSpanLabeledTree(tree);
Tree<Pair<String, IntPair>> currentNode =
spanLabeledTree.getYield().get(predicatePosition).getParent();
String f = getVoice(currentNode);
return new LinkedHashSet<Feature>(Collections.singletonList(DiscreteFeature.create(f)));
}
代码示例来源:origin: CogComp/cogcomp-nlp
Sentence currSentence = ta.getSentenceFromToken(currSpan.getFirst());
IntPair sentenceSpan = currSentence.getSentenceConstituent().getSpan();
View PosView = ta.getView("POS");
代码示例来源:origin: CogComp/cogcomp-nlp
/**
* Check if the Constituent is a start of a sentence
* The size of the Constituent should be 1
*/
public static String isSentenceStart (Constituent c){
Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan());
int sentenceStart = sentence.getStartSpan();
if (c.getStartSpan() == sentenceStart){
return "1";
}
return "0";
}
代码示例来源:origin: edu.illinois.cs.cogcomp/md
/**
* Check if the Constituent is a start of a sentence
* The size of the Constituent should be 1
*/
public static String isSentenceStart (Constituent c){
Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan());
int sentenceStart = sentence.getStartSpan();
if (c.getStartSpan() == sentenceStart){
return "1";
}
return "0";
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-md
/**
* Check if the Constituent is a start of a sentence
* The size of the Constituent should be 1
*/
public static String isSentenceStart (Constituent c){
Sentence sentence = c.getTextAnnotation().getSentenceFromToken(c.getStartSpan());
int sentenceStart = sentence.getStartSpan();
if (c.getStartSpan() == sentenceStart){
return "1";
}
return "0";
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-time
Sentence currSentence = ta.getSentenceFromToken(currSpan.getFirst());
IntPair sentenceSpan = currSentence.getSentenceConstituent().getSpan();
View PosView = ta.getView("POS");
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-relation-extraction
/**
* Helper function for print essential information of a relation
* @param r Input Relation
*/
public static void printRelation (Relation r){
TextAnnotation ta = r.getSource().getTextAnnotation();
Constituent source = r.getSource();
Constituent target = r.getTarget();
Constituent source_head = RelationFeatureExtractor.getEntityHeadForConstituent(source, ta, "");
Constituent target_head = RelationFeatureExtractor.getEntityHeadForConstituent(target, ta, "");
System.out.println(ta.getSentenceFromToken(source.getStartSpan()));
System.out.println(r.getRelationName());
System.out.println(r.getAttribute("RelationType") + ":" + r.getAttribute("RelationSubtype"));
System.out.println(source.toString() + " || " + target.toString());
System.out.println(source_head.toString() + " || " + target_head.toString());
}
代码示例来源:origin: CogComp/cogcomp-nlp
System.out.println(goldMention.getTextAnnotation().getSentenceFromToken(goldMention.getStartSpan()).toString());
System.out.println(goldMention.toString() + " " + goldMention.getAttribute("EntityType") + " " + predictMention.getAttribute("EntityType"));
System.out.println();
代码示例来源:origin: edu.illinois.cs.cogcomp/md
System.out.println(goldMention.getTextAnnotation().getSentenceFromToken(goldMention.getStartSpan()).toString());
System.out.println(goldMention.toString() + " " + goldMention.getAttribute("EntityType") + " " + predictMention.getAttribute("EntityType"));
System.out.println();
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-md
System.out.println(goldMention.getTextAnnotation().getSentenceFromToken(goldMention.getStartSpan()).toString());
System.out.println(goldMention.toString() + " " + goldMention.getAttribute("EntityType") + " " + predictMention.getAttribute("EntityType"));
System.out.println();
代码示例来源:origin: CogComp/cogcomp-nlp
/**
* Get the form/lemma features of a given Constituent.
* The size of the Constituent should be 1
*/
public static List<Pair<Integer, String>> getWordFormFeatures (Constituent c){
List<Pair<Integer, String>> ret_features = new ArrayList<>();
TextAnnotation ta = c.getTextAnnotation();
Sentence sentence = ta.getSentenceFromToken(c.getStartSpan());
int sentenceStart = sentence.getStartSpan();
int sentenceEnd = sentence.getEndSpan();
if (c.getStartSpan() > sentenceStart){
ret_features.add(new Pair<>(-1, ta.getToken(c.getStartSpan() - 1)));
ret_features.add(new Pair<>(-1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() - 1))));
}
ret_features.add(new Pair<>(0, ta.getToken(c.getStartSpan())));
ret_features.add(new Pair<>(0, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan()))));
if (c.getEndSpan() < sentenceEnd){
ret_features.add(new Pair<>(1, ta.getToken(c.getStartSpan() + 1)));
ret_features.add(new Pair<>(1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 1))));
}
if (c.getEndSpan() < sentenceEnd - 1){
ret_features.add(new Pair<>(2, ta.getToken(c.getStartSpan() + 2)));
ret_features.add(new Pair<>(2, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 2))));
}
return ret_features;
}
代码示例来源:origin: edu.illinois.cs.cogcomp/md
/**
* Get the form/lemma features of a given Constituent.
* The size of the Constituent should be 1
*/
public static List<Pair<Integer, String>> getWordFormFeatures (Constituent c){
List<Pair<Integer, String>> ret_features = new ArrayList<>();
TextAnnotation ta = c.getTextAnnotation();
Sentence sentence = ta.getSentenceFromToken(c.getStartSpan());
int sentenceStart = sentence.getStartSpan();
int sentenceEnd = sentence.getEndSpan();
if (c.getStartSpan() > sentenceStart){
ret_features.add(new Pair<>(-1, ta.getToken(c.getStartSpan() - 1)));
ret_features.add(new Pair<>(-1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() - 1))));
}
ret_features.add(new Pair<>(0, ta.getToken(c.getStartSpan())));
ret_features.add(new Pair<>(0, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan()))));
if (c.getEndSpan() < sentenceEnd){
ret_features.add(new Pair<>(1, ta.getToken(c.getStartSpan() + 1)));
ret_features.add(new Pair<>(1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 1))));
}
if (c.getEndSpan() < sentenceEnd - 1){
ret_features.add(new Pair<>(2, ta.getToken(c.getStartSpan() + 2)));
ret_features.add(new Pair<>(2, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 2))));
}
return ret_features;
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-md
/**
* Get the form/lemma features of a given Constituent.
* The size of the Constituent should be 1
*/
public static List<Pair<Integer, String>> getWordFormFeatures (Constituent c){
List<Pair<Integer, String>> ret_features = new ArrayList<>();
TextAnnotation ta = c.getTextAnnotation();
Sentence sentence = ta.getSentenceFromToken(c.getStartSpan());
int sentenceStart = sentence.getStartSpan();
int sentenceEnd = sentence.getEndSpan();
if (c.getStartSpan() > sentenceStart){
ret_features.add(new Pair<>(-1, ta.getToken(c.getStartSpan() - 1)));
ret_features.add(new Pair<>(-1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() - 1))));
}
ret_features.add(new Pair<>(0, ta.getToken(c.getStartSpan())));
ret_features.add(new Pair<>(0, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan()))));
if (c.getEndSpan() < sentenceEnd){
ret_features.add(new Pair<>(1, ta.getToken(c.getStartSpan() + 1)));
ret_features.add(new Pair<>(1, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 1))));
}
if (c.getEndSpan() < sentenceEnd - 1){
ret_features.add(new Pair<>(2, ta.getToken(c.getStartSpan() + 2)));
ret_features.add(new Pair<>(2, MyString.normalizeDigitsForFeatureExtraction(ta.getToken(c.getStartSpan() + 2))));
}
return ret_features;
}
内容来源于网络,如有侵权,请联系作者删除!