本文整理汇总了Java中edu.stanford.nlp.util.IntTuple类的典型用法代码示例。如果您正苦于以下问题:Java IntTuple类的具体用法?Java IntTuple怎么用?Java IntTuple使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IntTuple类属于edu.stanford.nlp.util包,在下文中一共展示了IntTuple类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findNextParagraphSpeaker
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
private String findNextParagraphSpeaker(List<CoreMap> paragraph, int paragraphOffset, Dictionaries dict) {
CoreMap lastSent = paragraph.get(paragraph.size()-1);
String speaker = "";
for(CoreLabel w : lastSent.get(CoreAnnotations.TokensAnnotation.class)) {
if(w.get(CoreAnnotations.LemmaAnnotation.class).equals("report") || w.get(CoreAnnotations.LemmaAnnotation.class).equals("say")) {
String word = w.get(CoreAnnotations.TextAnnotation.class);
SemanticGraph dependency = lastSent.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
IndexedWord t = dependency.getNodeByWordPattern(word);
for(Pair<GrammaticalRelation,IndexedWord> child : dependency.childPairs(t)){
if(child.first().getShortName().equals("nsubj")) {
int subjectIndex = child.second().index(); // start from 1
IntTuple headPosition = new IntTuple(2);
headPosition.set(0, paragraph.size()-1 + paragraphOffset);
headPosition.set(1, subjectIndex-1);
if(mentionheadPositions.containsKey(headPosition)
&& mentionheadPositions.get(headPosition).nerString.startsWith("PER")) {
speaker = Integer.toString(mentionheadPositions.get(headPosition).mentionID);
}
}
}
}
}
return speaker;
}
示例2: CorefMention
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
public CorefMention(MentionType mentionType,
Number number,
Gender gender,
Animacy animacy,
int startIndex,
int endIndex,
int headIndex,
int corefClusterID,
int mentionID,
int sentNum,
IntTuple position,
String mentionSpan) {
this.mentionType = mentionType;
this.number = number;
this.gender = gender;
this.animacy = animacy;
this.startIndex = startIndex;
this.endIndex = endIndex;
this.headIndex = headIndex;
this.corefClusterID = corefClusterID;
this.mentionID = mentionID;
this.sentNum = sentNum;
this.position = position;
this.mentionSpan = mentionSpan;
}
示例3: initializeCorefCluster
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
/** initialize positions and corefClusters (put each mention in each CorefCluster) */
private void initializeCorefCluster() {
for(int i = 0; i < predictedOrderedMentionsBySentence.size(); i ++){
for(int j = 0; j < predictedOrderedMentionsBySentence.get(i).size(); j ++){
Mention m = predictedOrderedMentionsBySentence.get(i).get(j);
if (allPredictedMentions.containsKey(m.mentionID)) {
SieveCoreferenceSystem.logger.warning("WARNING: Already contain mention " + m.mentionID);
Mention m1 = allPredictedMentions.get(m.mentionID);
SieveCoreferenceSystem.logger.warning("OLD mention: " + m1.spanToString() + "[" + m1.startIndex + "," + m1.endIndex + "]");
SieveCoreferenceSystem.logger.warning("NEW mention: " + m.spanToString() + "[" + m.startIndex + "," + m.endIndex + "]");
// SieveCoreferenceSystem.debugPrintMentions(System.err, "PREDICTED ORDERED", predictedOrderedMentionsBySentence);
// SieveCoreferenceSystem.debugPrintMentions(System.err, "GOLD ORDERED", goldOrderedMentionsBySentence);
}
assert(!allPredictedMentions.containsKey(m.mentionID));
allPredictedMentions.put(m.mentionID, m);
IntTuple pos = new IntTuple(2);
pos.set(0, i);
pos.set(1, j);
positions.put(m, pos);
m.sentNum = i;
assert(!corefClusters.containsKey(m.mentionID));
corefClusters.put(m.mentionID, new CorefCluster(m.mentionID, Generics.newHashSet(Arrays.asList(m))));
m.corefClusterID = m.mentionID;
IntTuple headPosition = new IntTuple(2);
headPosition.set(0, i);
headPosition.set(1, m.headIndex);
mentionheadPositions.put(headPosition, m);
}
}
}
示例4: findSpeaker
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
private boolean findSpeaker(int utterNum, int sentNum, List<CoreMap> sentences,
int startIndex, int endIndex, Dictionaries dict) {
List<CoreLabel> sent = sentences.get(sentNum).get(CoreAnnotations.TokensAnnotation.class);
for(int i = startIndex ; i < endIndex ; i++) {
if(sent.get(i).get(CoreAnnotations.UtteranceAnnotation.class)!=0) continue;
String lemma = sent.get(i).get(CoreAnnotations.LemmaAnnotation.class);
String word = sent.get(i).get(CoreAnnotations.TextAnnotation.class);
if(dict.reportVerb.contains(lemma)) {
// find subject
SemanticGraph dependency = sentences.get(sentNum).get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class);
IndexedWord w = dependency.getNodeByWordPattern(word);
if (w != null) {
for(Pair<GrammaticalRelation,IndexedWord> child : dependency.childPairs(w)){
if(child.first().getShortName().equals("nsubj")) {
String subjectString = child.second().word();
int subjectIndex = child.second().index(); // start from 1
IntTuple headPosition = new IntTuple(2);
headPosition.set(0, sentNum);
headPosition.set(1, subjectIndex-1);
String speaker;
if(mentionheadPositions.containsKey(headPosition)) {
speaker = Integer.toString(mentionheadPositions.get(headPosition).mentionID);
} else {
speaker = subjectString;
}
speakers.put(utterNum, speaker);
return true;
}
}
} else {
SieveCoreferenceSystem.logger.warning("Cannot find node in dependency for word " + word);
}
}
}
return false;
}
示例5: findParagraphSpeaker
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
private String findParagraphSpeaker(List<CoreMap> paragraph,
int paragraphUtterIndex, String nextParagraphSpeaker, int paragraphOffset, Dictionaries dict) {
if(!speakers.containsKey(paragraphUtterIndex)) {
if(!nextParagraphSpeaker.equals("")) {
speakers.put(paragraphUtterIndex, nextParagraphSpeaker);
} else { // find the speaker of this paragraph (John, nbc news)
CoreMap lastSent = paragraph.get(paragraph.size()-1);
String speaker = "";
boolean hasVerb = false;
for(int i = 0 ; i < lastSent.get(CoreAnnotations.TokensAnnotation.class).size() ; i++){
CoreLabel w = lastSent.get(CoreAnnotations.TokensAnnotation.class).get(i);
String pos = w.get(CoreAnnotations.PartOfSpeechAnnotation.class);
String ner = w.get(CoreAnnotations.NamedEntityTagAnnotation.class);
if(pos.startsWith("V")) {
hasVerb = true;
break;
}
if(ner.startsWith("PER")) {
IntTuple headPosition = new IntTuple(2);
headPosition.set(0, paragraph.size()-1 + paragraphOffset);
headPosition.set(1, i);
if(mentionheadPositions.containsKey(headPosition)) {
speaker = Integer.toString(mentionheadPositions.get(headPosition).mentionID);
}
}
}
if(!hasVerb && !speaker.equals("")) {
speakers.put(paragraphUtterIndex, speaker);
}
}
}
return findNextParagraphSpeaker(paragraph, paragraphOffset, dict);
}
示例6: postProcessing
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
/** Remove singletons, appositive, predicate nominatives, relative pronouns */
private static void postProcessing(Document document) {
Set<IntTuple> removeSet = Generics.newHashSet();
Set<Integer> removeClusterSet = Generics.newHashSet();
for(CorefCluster c : document.corefClusters.values()){
Set<Mention> removeMentions = Generics.newHashSet();
for(Mention m : c.getCorefMentions()) {
if(Constants.REMOVE_APPOSITION_PREDICATENOMINATIVES
&& ((m.appositions!=null && m.appositions.size() > 0)
|| (m.predicateNominatives!=null && m.predicateNominatives.size() > 0)
|| (m.relativePronouns!=null && m.relativePronouns.size() > 0))){
removeMentions.add(m);
removeSet.add(document.positions.get(m));
m.corefClusterID = m.mentionID;
}
}
c.corefMentions.removeAll(removeMentions);
if(Constants.REMOVE_SINGLETONS && c.getCorefMentions().size()==1) {
removeClusterSet.add(c.clusterID);
}
}
for (int removeId : removeClusterSet){
document.corefClusters.remove(removeId);
}
// todo [cdm 2013]: This is buggy: positions is Map<Mention,IntTuple>, so can't remove IntTuple
for(IntTuple pos : removeSet){
document.positions.remove(pos);
}
}
示例7: printLink
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
/** Print coref link info */
private static void printLink(Logger logger, String header, IntTuple src, IntTuple dst, List<List<Mention>> orderedMentionsBySentence) {
Mention srcMention = orderedMentionsBySentence.get(src.get(0)).get(src.get(1));
Mention dstMention = orderedMentionsBySentence.get(dst.get(0)).get(dst.get(1));
if(src.get(0)==dst.get(0)) {
logger.fine(header + ": ["+srcMention.spanToString()+"](id="+srcMention.mentionID
+") in sent #"+src.get(0)+" => ["+dstMention.spanToString()+"](id="+dstMention.mentionID+") in sent #"+dst.get(0) + " Same Sentence");
} else {
logger.fine(header + ": ["+srcMention.spanToString()+"](id="+srcMention.mentionID
+") in sent #"+src.get(0)+" => ["+dstMention.spanToString()+"](id="+dstMention.mentionID+") in sent #"+dst.get(0));
}
}
示例8: printLogs
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
/** Print pass results */
private static void printLogs(CorefCluster c1, CorefCluster c2, Mention m1,
Mention m2, Document document, int sieveIndex) {
Map<Mention, IntTuple> positions = document.positions;
List<List<Mention>> orderedMentionsBySentence = document.getOrderedMentions();
List<Pair<IntTuple, IntTuple>> goldLinks = document.getGoldLinks();
IntTuple p1 = positions.get(m1);
assert(p1 != null);
IntTuple p2 = positions.get(m2);
assert(p2 != null);
int menDist = 0;
for (int i = p2.get(0) ; i<= p1.get(0) ; i++){
if(p1.get(0)==p2.get(0)) {
menDist = p1.get(1)-p2.get(1);
break;
}
if(i==p2.get(0)) {
menDist += orderedMentionsBySentence.get(p2.get(0)).size()-p2.get(1);
continue;
}
if(i==p1.get(0)) {
menDist += p1.get(1);
continue;
}
if(p2.get(0)<i && i < p1.get(0)) menDist += orderedMentionsBySentence.get(i).size();
}
String correct = (goldLinks.contains(new Pair<IntTuple, IntTuple>(p1,p2)))? "\tCorrect" : "\tIncorrect";
logger.finest("\nsentence distance: "+(p1.get(0)-p2.get(0))+"\tmention distance: "+menDist + correct);
if(!goldLinks.contains(new Pair<IntTuple,IntTuple>(p1,p2))){
logger.finer("-------Incorrect merge in pass"+sieveIndex+"::--------------------");
c1.printCorefCluster(logger);
logger.finer("--------------------------------------------");
c2.printCorefCluster(logger);
logger.finer("--------------------------------------------");
}
logger.finer("antecedent: "+m2.spanToString()+"("+m2.mentionID+")\tmention: "+m1.spanToString()+"("+m1.mentionID+")\tsentDistance: "+Math.abs(m1.sentNum-m2.sentNum)+"\t"+correct+" Pass"+sieveIndex+":");
}
示例9: getLinks
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
public static List<Pair<IntTuple, IntTuple>> getLinks(
Map<Integer, CorefChain> result) {
List<Pair<IntTuple, IntTuple>> links = new ArrayList<Pair<IntTuple, IntTuple>>();
MentionComparator comparator = new MentionComparator();
for(CorefChain c : result.values()) {
List<CorefMention> s = c.getMentionsInTextualOrder();
for(CorefMention m1 : s){
for(CorefMention m2 : s){
if(comparator.compare(m1, m2)==1) links.add(new Pair<IntTuple, IntTuple>(m1.position, m2.position));
}
}
}
return links;
}
示例10: CorefChain
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
public CorefChain(CorefCluster c, Map<Mention, IntTuple> positions){
chainID = c.clusterID;
mentions = new ArrayList<CorefMention>();
mentionMap = Generics.newHashMap();
for (Mention m : c.getCorefMentions()) {
CorefMention men = new CorefMention(m, positions.get(m));
mentions.add(men);
IntPair position = new IntPair(men.sentNum, men.headIndex);
if(!mentionMap.containsKey(position)) mentionMap.put(position, Generics.<CorefMention>newHashSet());
mentionMap.get(position).add(men);
if(men.moreRepresentativeThan(representative)) representative = men;
}
Collections.sort(mentions, new MentionComparator());
}
示例11: getType
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
public Class<IntTuple> getType() {
return IntTuple.class;
}
示例12: getGoldLinks
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
protected List<Pair<IntTuple, IntTuple>> getGoldLinks() {
if(goldLinks==null) this.extractGoldLinks();
return goldLinks;
}
示例13: getType
import edu.stanford.nlp.util.IntTuple; //导入依赖的package包/类
public Class<IntTuple> getType() { return IntTuple.class; }