@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))); }
@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))); }
Sentence currSentence = ta.getSentenceFromToken(currSpan.getFirst()); IntPair sentenceSpan = currSentence.getSentenceConstituent().getSpan(); View PosView = ta.getView("POS");
/** * 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"; }
/** * 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"; }
/** * 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"; }
Sentence currSentence = ta.getSentenceFromToken(currSpan.getFirst()); IntPair sentenceSpan = currSentence.getSentenceConstituent().getSpan(); View PosView = ta.getView("POS");
/** * 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()); }
System.out.println(goldMention.getTextAnnotation().getSentenceFromToken(goldMention.getStartSpan()).toString()); System.out.println(goldMention.toString() + " " + goldMention.getAttribute("EntityType") + " " + predictMention.getAttribute("EntityType")); System.out.println();
System.out.println(goldMention.getTextAnnotation().getSentenceFromToken(goldMention.getStartSpan()).toString()); System.out.println(goldMention.toString() + " " + goldMention.getAttribute("EntityType") + " " + predictMention.getAttribute("EntityType")); System.out.println();
System.out.println(goldMention.getTextAnnotation().getSentenceFromToken(goldMention.getStartSpan()).toString()); System.out.println(goldMention.toString() + " " + goldMention.getAttribute("EntityType") + " " + predictMention.getAttribute("EntityType")); System.out.println();
/** * 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; }
/** * 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; }
/** * 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; }