@Override public List<Feature> extract(JCas jCas, Markable mention) throws CleartkExtractorException { if(cache == null){ throw new RuntimeException("This extractor requires a cached Markable->ConllDependencyNode map to be set with setCache()"); } List<Feature> feats = new ArrayList<>(); ConllDependencyNode mentionHead = cache.get(mention); if(mentionHead != null){ feats.add(new Feature("MentionRel", mentionHead.getDeprel())); } return feats; }
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; }
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; }
/** * 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(); }
@Override public List<Feature> extract(JCas jCas, Markable mention) throws CleartkExtractorException { List<Feature> feats = new ArrayList<>(); ConllDependencyNode mentionHead = MapFactory.get(getKey(jCas), mention); if(mentionHead != null){ feats.add(new Feature("MentionRel", mentionHead.getDeprel())); } return feats; }
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 String toSyntaxString() { StringBuilder str = new StringBuilder(); boolean foundCommon = false; for (ConllDependencyNode node : this) { if (isCommonNode(node)) { foundCommon = true; str.append( L_POS_DELIM + node.getPostag() + R_POS_DELIM ); continue; } str.append( foundCommon ? DN_ARC_A + L_REL_DELIM + node.getDeprel() + R_REL_DELIM + DN_ARC_B + L_POS_DELIM + node.getPostag() + R_POS_DELIM : L_POS_DELIM + node.getPostag() + R_POS_DELIM + UP_ARC_B + L_REL_DELIM + node.getDeprel() + R_REL_DELIM + UP_ARC_A ); } return str.toString(); }
public String toSyntaxString() { StringBuilder str = new StringBuilder(); boolean foundCommon = false; for (ConllDependencyNode node : this) { if (isCommonNode(node)) { foundCommon = true; str.append( L_POS_DELIM + node.getPostag() + R_POS_DELIM ); continue; } str.append( foundCommon ? DN_ARC_A + L_REL_DELIM + node.getDeprel() + R_REL_DELIM + DN_ARC_B + L_POS_DELIM + node.getPostag() + R_POS_DELIM : L_POS_DELIM + node.getPostag() + R_POS_DELIM + UP_ARC_B + L_REL_DELIM + node.getDeprel() + R_REL_DELIM + UP_ARC_A ); } return str.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(); }
@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 = 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)); 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; }
@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 = WindowedHistoryAttributeClassifier.extract( jCas, _sentences, _sentence, _sentenceIndex, 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", WindowedHistoryAttributeClassifier.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; }