/** * Holds a map from Nomlex relations to Stanford-dependencies relations. * @author Asher Stern * @since Oct 15, 2012 * */ @StandardSpecific({"stanford-dependencies","nomlex"}) public class PlaceToRelationMap { public static ImmutableMap<String, Set<String>> getMapPlaceToRelation() { return IMMUTABLE_MAP_PLACE_TO_RELATIONS; } private static final Map<String, Set<String>> MAP_PLACE_TO_RELATIONS; private static final ImmutableMap<String, Set<String>> IMMUTABLE_MAP_PLACE_TO_RELATIONS; static { MAP_PLACE_TO_RELATIONS = new LinkedHashMap<String, Set<String>>(); MAP_PLACE_TO_RELATIONS.put("DET-POSS", Collections.singleton("poss")); MAP_PLACE_TO_RELATIONS.put("N-N-MOD", Collections.singleton("nn")); IMMUTABLE_MAP_PLACE_TO_RELATIONS = new ImmutableMapWrapper<String, Set<String>>(MAP_PLACE_TO_RELATIONS); } }
@StandardSpecific("stanford-dependencies") public class VerbPredicatesIdentifier<I extends Info, S extends AbstractNode<I, S>>
@StandardSpecific("stanford-dependencies") public class CopularPredicatesIdentifier<I extends Info, S extends AbstractNode<I, S>>
@StandardSpecific("stanford-dependencies") // All the methods here are supposed to be restricted to Stanford-dependencies public class IdentificationStaticMethods
@StandardSpecific(value = { "Stanford" }) protected static final Set<String> relationTypesBeforeHead = new HashSet<String>(Arrays.asList( "num", "subj", "nsubj", "nsubjpass", "csubj", "csubjpass", "nn", "det", "amod", "advmod", "poss", "aux", "auxpass", "mark", "cop")); @StandardSpecific(value = { "Stanford" }) protected static final Set<String> relationTypesToIgnore = new HashSet<String>(Arrays.asList( "xsubj"));
@StandardSpecific("stanford-dependencies") public class RelationTypes
/** * @return an English sentence that is approximately equivalent to the given parse tree. * @note Currently handles only subject/object issues. */ @StandardSpecific(value = { "Stanford" }) public static <T extends Info,S extends AbstractNode<T,S>> String toEnglishSentence(S parseTree) { if (parseTree==null) throw new NullPointerException("parseTree is null"); List<String> words = new ArrayList<String> (); addWordsOfEnglishSentence(parseTree, words); String sentence = StringUtil.join(words, " "); sentence = sentence.toLowerCase(); sentence = sentence.replaceAll(" ([,.';:\\)])", "$1"); return sentence; }
@StandardSpecific({"stanford-dependencies","nomlex"}) public class NominalPredicateArgumentStructureIdentifier<I extends Info, S extends AbstractNode<I, S>> @StandardSpecific("nomlex") public static final String PREPOSITION_PLACE = "PP";
/** * Recursively add the words of the given parseTree to the given words list, in the correct grammatical order. Subroutine of {@link #toEnglishSentence(AbstractNode)}. * @param parseTree [INPUT] * @param words [OUTPUT] */ @StandardSpecific(value = { "Stanford" }) protected static <T extends Info,S extends AbstractNode<T,S>> void addWordsOfEnglishSentence(AbstractNode<T,S> parseTree, List<String> words) { if (parseTree==null) throw new NullPointerException("parseTree is null"); if (parseTree.getChildren()==null) { words.add(InfoGetFields.getWord(parseTree.getInfo())); } else { // add subject nodes before the verb: for (S child: parseTree.getChildren()) { if (relationTypesBeforeHead.contains(InfoGetFields.getRelation(child.getInfo()))) addWordsOfEnglishSentence(child, words); } words.add(InfoGetFields.getWord(parseTree.getInfo())); // add the root word // add non-subject nodes after the verb: for (S child: parseTree.getChildren()) { if (relationTypesBeforeHead.contains(InfoGetFields.getRelation(child.getInfo()))) continue; if (relationTypesToIgnore.contains(InfoGetFields.getRelation(child.getInfo()))) continue; addWordsOfEnglishSentence(child, words); } } }
@StandardSpecific("stanford-dependencies") @ParserSpecific("easyfirst") public class ArgumentsIdentifier<I extends Info, S extends AbstractNode<I, S>>
/** * Given a node in the parse-tree, this method finds a direct-child of that node * that is connected to it via "ref" relation, and also has an antecedent. * * @param node * @return */ @StandardSpecific("stanford-dependencies") @ParserSpecific("easyfirst") public static <I extends Info, S extends AbstractNode<I, S>> S getRefWithAntecedent(S node) { S refWithAntecedent = null; if (node.hasChildren()) { for (S child : node.getChildren()) { if ("ref".equals(InfoGetFields.getRelation(child.getInfo()))) { if (child.getAntecedent()!=null) { refWithAntecedent = child; break; } } } } return refWithAntecedent; }
@StandardSpecific("stanford-dependencies") @ParserSpecific("easyfirst") private void identifyRcmodAndPartmodArguments()
@StandardSpecific("nomlex") private Set<NodeAndPathFromPredicateAndArgumentType<I,S>> getArgumentsByPrepositions()
@StandardSpecific("stanford-dependencies") @ParserSpecific("easyfirst") public static <I extends Info, S extends AbstractNode<I, S>> ArgumentType argumentTypeByRef(Predicate<I,S> predicate, S argumentSyntacticHead)
@StandardSpecific("stanford-dependencies") private ArgumentType checkIfClausalArgument(ArgumentNodeAndPathFromPredicate<I,S> argumentNode)