public static String dumpDependencyGraph(Annotation annotation) { StringBuilder builder = new StringBuilder(); for (ConllDependencyNode depNode : JCasUtil.selectCovered(ConllDependencyNode.class, annotation)) { ConllDependencyNode head = depNode.getHead(); String headStr = (head != null) ? head.getCoveredText() : "TOP"; builder.append(String.format("%s(%s, %s)\n", depNode.getDeprel(), depNode.getCoveredText(), headStr)); } return builder.toString(); } }
public static String dumpDependencyGraph(Annotation annotation) { StringBuilder builder = new StringBuilder(); for (ConllDependencyNode depNode : JCasUtil.selectCovered(ConllDependencyNode.class, annotation)) { ConllDependencyNode head = depNode.getHead(); String headStr = (head != null) ? head.getCoveredText() : "TOP"; builder.append(String.format("%s(%s, %s)\n", depNode.getDeprel(), depNode.getCoveredText(), headStr)); } return builder.toString(); } }
public static String dumpDependencyRelations(JCas jcas, Annotation annotation) { StringBuilder builder = new StringBuilder(); for (ConllDependencyNode depNode : JCasUtil.selectCovered(jcas, ConllDependencyNode.class, annotation)) { if (depNode.getHead() != null) { builder.append(String.format("%s(%s,%s)\n", depNode.getDeprel(), depNode.getCoveredText(), depNode.getHead().getCoveredText())); } } return builder.toString(); }
public static String dumpDependencyRelations(JCas jcas, Annotation annotation) { StringBuilder builder = new StringBuilder(); for (ConllDependencyNode depNode : JCasUtil.selectCovered(jcas, ConllDependencyNode.class, annotation)) { if (depNode.getHead() != null) { builder.append(String.format("%s(%s,%s)\n", depNode.getDeprel(), depNode.getCoveredText(), depNode.getHead().getCoveredText())); } } return builder.toString(); }
public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> feats = new ArrayList<>(); ConllDependencyNode head1 = DependencyUtility.getNominalHeadNode(jCas, arg1); ConllDependencyNode head2 = DependencyUtility.getNominalHeadNode(jCas, arg2); if(head1 != null){ feats.add(new Feature("Arg1Head", head1.getCoveredText().toLowerCase())); } if(head2 != null){ feats.add(new Feature("Arg2Head", head2.getCoveredText().toLowerCase())); } return feats; }
protected List<CollectionTextRelationIdentifiedAnnotationPair> getHeadwordMatchPairs(JCas jcas, IdentifiedAnnotation mention, int sentDist){ List<CollectionTextRelationIdentifiedAnnotationPair> pairs = new ArrayList<>(); ConllDependencyNode headNode = DependencyUtility.getNominalHeadNode(jcas, mention); if(headNode == null){ Logger.getLogger(MentionClusterRankingCoreferenceAnnotator.class).warn("There is a markable with no dependency node covering it."); return pairs; } String head = headNode.getCoveredText().toLowerCase(); if(headWordMarkables.containsKey(head)){ final Set<Markable> headSet = headWordMarkables.get( head ); ClusterMentionFetcher.populatePairs( jcas, mention, headSet, pairs ); } return pairs; }
public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) throws AnalysisEngineProcessException { List<Feature> feats = new ArrayList<>(); ConllDependencyNode head1 = DependencyUtility.getNominalHeadNode(jCas, arg1); ConllDependencyNode head2 = DependencyUtility.getNominalHeadNode(jCas, arg2); if(head1 != null){ feats.add(new Feature("Arg1Head", head1.getCoveredText().toLowerCase())); } if(head2 != null){ feats.add(new Feature("Arg2Head", head2.getCoveredText().toLowerCase())); } return feats; }
@Override public List<CollectionTextRelationIdentifiedAnnotationPair> getPairs(JCas jcas, Markable mention) { List<CollectionTextRelationIdentifiedAnnotationPair> pairs = new ArrayList<>(); ConllDependencyNode headNode = DependencyUtility.getNominalHeadNode(jcas, mention); if(headNode == null){ Logger.getLogger(MentionClusterCoreferenceAnnotator.class).warn("There is a markable with no dependency node covering it."); return pairs; } String head = headNode.getCoveredText().toLowerCase(); if(headWordMarkables.containsKey(head)){ final Set<Markable> headSet = headWordMarkables.get( head ); ClusterMentionFetcher.populatePairs( jcas, mention, headSet, pairs ); } else { headWordMarkables.put(head, new HashSet<Markable>()); } headWordMarkables.get(head).add(mention); return pairs; } }
/** * This will convert a path into a string lexicalized at the end points with arc labels and POS tags in between */ public static String pathToString(LinkedList<ConllDependencyNode> path) { StringBuilder builder = new StringBuilder(); for (ConllDependencyNode node : path) { if (node == path.getFirst() || node == path.getLast()) { builder.append(node.getCoveredText()); } else { builder.append(node.getPostag()); } builder.append("-"); builder.append(node.getDeprel()); if (node != path.getLast()) { builder.append("/"); } } return builder.toString(); }
/** * This will convert a path into a string lexicalized at the end points with arc labels and POS tags in between */ public static String pathToString(LinkedList<ConllDependencyNode> path) { StringBuilder builder = new StringBuilder(); for (ConllDependencyNode node : path) { if (node == path.getFirst() || node == path.getLast()) { builder.append(node.getCoveredText()); } else { builder.append(node.getPostag()); } builder.append("-"); builder.append(node.getDeprel()); if (node != path.getLast()) { builder.append("/"); } } return builder.toString(); }
private static List<ConllDependencyNode> removeUnannotatedNodes(ConllDependencyNode originalNode, List<ConllDependencyNode> progeny) { List<ConllDependencyNode> filtered = new ArrayList<>(); for(ConllDependencyNode node: progeny){ if(node == originalNode) filtered.add(node); boolean blockedByConj = false; for(ConllDependencyNode pathEl : DependencyUtility.getPath(progeny, node, originalNode)){ if(pathEl == originalNode) continue; if(pathEl.getDeprel().equals("conj") || pathEl.getDeprel().equals("cc") || pathEl.getPostag().equals(".") || pathEl.getPostag().equals(",") || pathEl.getDeprel().equals("punct") || pathEl.getDeprel().equals("meta") || pathEl.getCoveredText().matches("(([A-Z][\\.\\:\\)])|(#\\d+)|(\\d+[\\.\\:\\)]))")){ blockedByConj = true; break; } } if(!blockedByConj){ filtered.add(node); } } return filtered; }
public static List<Feature> extractForNode(JCas jCas, IdentifiedAnnotation mention, String ftrPrefix) { List<Feature> features = new ArrayList<Feature>(); ConllDependencyNode mentionHeadNode = DependencyParseUtils.findAnnotationHead(jCas, mention); if (mentionHeadNode != null) { ConllDependencyNode dependsOn = mentionHeadNode.getHead(); if (dependsOn != null) { features.add(new Feature(ftrPrefix + "_DEPENDS_ON_WORD", dependsOn.getCoveredText())); features.add(new Feature(ftrPrefix + "_DEPENDS_ON_POS", dependsOn.getPostag())); // Following features come from Zhou et al. 2005 // ET1DW1: combination of the entity type and the dependent word for M1 features.add(new Feature(ftrPrefix + "_TYPE-GOVERNING_WORD", String.format("%d-%s", mention.getTypeID(), dependsOn.getCoveredText()))); // H1DW1: combination of the head word and the dependent word for M1 features.add(new Feature(ftrPrefix + "_HEAD_WORD-GOVERNING_WORD", String.format("%s-%s", mentionHeadNode.getCoveredText(), dependsOn.getCoveredText()))); features.add(new Feature(ftrPrefix + "_TYPE-GOVERNING_POS", String.format("%d-%s", mention.getTypeID(), dependsOn.getPostag()))); features.add(new Feature(ftrPrefix + "_HEAD_POS-GOVERNING_POS", String.format("%s-%s", mentionHeadNode.getPostag(), dependsOn.getPostag()))); } } return features; }
public static List<Feature> extractForNode(JCas jCas, IdentifiedAnnotation mention, String ftrPrefix) { List<Feature> features = new ArrayList<Feature>(); ConllDependencyNode mentionHeadNode = DependencyParseUtils.findAnnotationHead(jCas, mention); if (mentionHeadNode != null) { ConllDependencyNode dependsOn = mentionHeadNode.getHead(); if (dependsOn != null) { features.add(new Feature(ftrPrefix + "_DEPENDS_ON_WORD", dependsOn.getCoveredText())); features.add(new Feature(ftrPrefix + "_DEPENDS_ON_POS", dependsOn.getPostag())); // Following features come from Zhou et al. 2005 // ET1DW1: combination of the entity type and the dependent word for M1 features.add(new Feature(ftrPrefix + "_TYPE-GOVERNING_WORD", String.format("%d-%s", mention.getTypeID(), dependsOn.getCoveredText()))); // H1DW1: combination of the head word and the dependent word for M1 features.add(new Feature(ftrPrefix + "_HEAD_WORD-GOVERNING_WORD", String.format("%s-%s", mentionHeadNode.getCoveredText(), dependsOn.getCoveredText()))); features.add(new Feature(ftrPrefix + "_TYPE-GOVERNING_POS", String.format("%d-%s", mention.getTypeID(), dependsOn.getPostag()))); features.add(new Feature(ftrPrefix + "_HEAD_POS-GOVERNING_POS", String.format("%s-%s", mentionHeadNode.getPostag(), dependsOn.getPostag()))); } } return features; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg) { List<Feature> features = new ArrayList<>(); // Pull in general dependency-based features -- externalize to another extractor? ConllDependencyNode node = DependencyUtility.getNominalHeadNode(jCas, arg); if (node!= null) { features.add(new Feature("DEPENDENCY_HEAD", node.getCoveredText())); features.add(new Feature("DEPENDENCY_HEAD_deprel", node.getDeprel())); } HashMap<String, Boolean> featsMap = SubjectAttributeClassifier.extract(jCas, arg); if (!featsMap.isEmpty()) { // Pull in all the features that were used for the rule-based module features.addAll( hashToFeatureList(featsMap) ); // Pull in the result of the rule-based module as well features.add(new Feature("SUBJECT_CLASSIFIER_LOGIC", SubjectAttributeClassifier.classifyWithLogic(featsMap))); } return features; }
@Override public List<Feature> extract( JCas jCas, IdentifiedAnnotation arg ) { List<Feature> features = new ArrayList<>(); // Pull in general dependency-based features -- externalize to another extractor? ConllDependencyNode node = DependencyUtility.getNominalHeadNode( jCas, arg ); if ( node != null ) { features.add( new Feature( "DEPENDENCY_HEAD", node.getCoveredText() ) ); features.add( new Feature( "DEPENDENCY_HEAD_deprel", node.getDeprel() ) ); } HashMap<String, Boolean> featsMap = WindowedGenericAttributeClassifier.extract( jCas, _sentence, arg ); // Pull in all the features that were used for the rule-based module features.addAll( hashToFeatureList( featsMap ) ); // Pull in the result of the rule-based module as well features.add( new Feature( "GENERIC_CLASSIFIER_LOGIC", WindowedGenericAttributeClassifier.classifyWithLogic( featsMap ) ) ); return features; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg) { List<Feature> features = new ArrayList<>(); // Pull in general dependency-based features -- externalize to another extractor? ConllDependencyNode node = DependencyUtility.getNominalHeadNode(jCas, arg); if (node!= null) { features.add(new Feature("DEPENDENCY_HEAD", node.getCoveredText())); features.add(new Feature("DEPENDENCY_HEAD_deprel", node.getDeprel())); } HashMap<String, Boolean> featsMap = GenericAttributeClassifier.extract(jCas, arg); // Pull in all the features that were used for the rule-based module features.addAll( hashToFeatureList(featsMap) ); // Pull in the result of the rule-based module as well features.add(new Feature("GENERIC_CLASSIFIER_LOGIC", GenericAttributeClassifier.classifyWithLogic(featsMap))); return features; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg) { List<Feature> features = new ArrayList<>(); // Pull in general dependency-based features -- externalize to another extractor? ConllDependencyNode node = DependencyUtility.getNominalHeadNode(jCas, arg); if (node!= null) { features.add(new Feature("DEPENDENCY_HEAD", node.getCoveredText())); features.add(new Feature("DEPENDENCY_HEAD_deprel", node.getDeprel())); } HashMap<String, Boolean> featsMap = GenericAttributeClassifier.extract(jCas, arg); // Pull in all the features that were used for the rule-based module features.addAll( hashToFeatureList(featsMap) ); // Pull in the result of the rule-based module as well features.add(new Feature("GENERIC_CLASSIFIER_LOGIC", GenericAttributeClassifier.classifyWithLogic(featsMap))); return features; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg) { List<Feature> features = new ArrayList<>(); // Pull in general dependency-based features -- externalize to another extractor? ConllDependencyNode node = DependencyUtility.getNominalHeadNode(jCas, arg); if (node!= null) { features.add(new Feature("DEPENDENCY_HEAD", node.getCoveredText())); features.add(new Feature("DEPENDENCY_HEAD_deprel", node.getDeprel())); } HashMap<String, Boolean> featsMap = SubjectAttributeClassifier.extract(jCas, arg); if (!featsMap.isEmpty()) { // Pull in all the features that were used for the rule-based module features.addAll( hashToFeatureList(featsMap) ); // Pull in the result of the rule-based module as well features.add(new Feature("SUBJECT_CLASSIFIER_LOGIC", SubjectAttributeClassifier.classifyWithLogic(featsMap))); } return features; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg) { List<Feature> features = new ArrayList<>(); // Pull in general dependency-based features -- externalize to another extractor? ConllDependencyNode node = DependencyUtility.getNominalHeadNode(jCas, arg); if (node!= null) { // features.add(new Feature("DEPENDENCY_HEAD", node)); features.add(new Feature("DEPENDENCY_HEAD_word", node.getCoveredText())); // features.add(new Feature("DEPENDENCY_HEAD_pos", node.getPostag())); features.add(new Feature("DEPENDENCY_HEAD_deprel", node.getDeprel())); // features.add(new Feature("DEPENDENCY_HEAD_lemma", node.getLemma())); } HashMap<String, Boolean> featsMap = HistoryAttributeClassifier.extract(jCas, arg); // Pull in all the features that were used for the rule-based module features.addAll( hashToFeatureList(featsMap) ); // Pull in the result of the rule-based module as well features.add(new Feature("HISTORY_CLASSIFIER_LOGIC", HistoryAttributeClassifier.classifyWithLogic(featsMap))); // Add whether it is token preceded by "h/o" //features.add(new Feature("PRECEDED_BY_H_SLASH_O", HistoryAttributeClassifier.precededByH_O(jCas, arg))); return features; }
@Override public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg) { List<Feature> features = new ArrayList<>(); // Pull in general dependency-based features -- externalize to another extractor? ConllDependencyNode node = DependencyUtility.getNominalHeadNode(jCas, arg); if (node!= null) { // features.add(new Feature("DEPENDENCY_HEAD", node)); features.add(new Feature("DEPENDENCY_HEAD_word", node.getCoveredText())); // features.add(new Feature("DEPENDENCY_HEAD_pos", node.getPostag())); features.add(new Feature("DEPENDENCY_HEAD_deprel", node.getDeprel())); // features.add(new Feature("DEPENDENCY_HEAD_lemma", node.getLemma())); } HashMap<String, Boolean> featsMap = HistoryAttributeClassifier.extract(jCas, arg); // Pull in all the features that were used for the rule-based module features.addAll( hashToFeatureList(featsMap) ); // Pull in the result of the rule-based module as well features.add(new Feature("HISTORY_CLASSIFIER_LOGIC", HistoryAttributeClassifier.classifyWithLogic(featsMap))); // Add whether it is token preceded by "h/o" //features.add(new Feature("PRECEDED_BY_H_SLASH_O", HistoryAttributeClassifier.precededByH_O(jCas, arg))); return features; }