List of usage examples for edu.stanford.nlp.trees.tregex TregexMatcher matches
public abstract boolean matches();
From source file:edu.cmu.ark.QuestionTransducer.java
License:Open Source License
/** * relabels the main clause from S (declarative sentence clause) * to SQ (inverted question clause)/*from ww w . ja v a 2s .c o m*/ * * @param inputTree * @return */ private Tree relabelMainClause(Tree inputTree) { Tree copyTree = inputTree.deeperCopy(); String tregexOpStr = "ROOT < S=mainclause"; TregexPattern matchPattern = TregexPatternFactory.getPattern(tregexOpStr); TregexMatcher m = matchPattern.matcher(copyTree); if (m.matches()) { m.getNode("mainclause").label().setValue("SQ"); } return copyTree; }
From source file:edu.cmu.ark.QuestionTransducer.java
License:Open Source License
/** * returns whether to perform subject-aux inversion * (true if there is an auxiliary or modal verb in addition to the predicate) * * E.g., true for "John did meet Paul" (which could lead to "Who did John meet?") * false for "John met Paul" (which could lead to "Who met Paul?") * * Note that this occurs after the main verb decomposition step * (which depends on whether the answer phrase is the subject or not) * * @param inputTree/*ww w . j a v a 2 s . c o m*/ * @return */ private boolean canInvert(Tree inputTree) { String tregexOpStr; TregexPattern matchPattern; TregexMatcher matcher; tregexOpStr = "ROOT < (S < (VP < /(MD|VB.?)/))"; matchPattern = TregexPatternFactory.getPattern(tregexOpStr); matcher = matchPattern.matcher(inputTree); return matcher.matches(); }
From source file:edu.cmu.ark.QuestionTransducer.java
License:Open Source License
/** * Filters out some stuff we don't want to process. * Note: this method is somewhat redundant with a similar method in stage 1. * * @param inputTree/*from w w w . j a va 2 s .c om*/ * @return */ private boolean isUsableInputSentence(Tree inputTree) { boolean res = false; String tregexOpStr; TregexPattern matchPattern; TregexMatcher matcher; //skip if there are leading conjunctions (need to drop these during stage 1) tregexOpStr = "ROOT < (S=mainclause < CC=frontedconj)"; matchPattern = TregexPatternFactory.getPattern(tregexOpStr); if (matchPattern.matcher(inputTree).matches()) { return false; } //make sure this is not just a single node tregexOpStr = "/\\./ !< /\\./"; matchPattern = TregexPatternFactory.getPattern(tregexOpStr); if (matchPattern.matcher(inputTree).matches()) { return false; } //MAKE SURE THERE IS A RECOGNIZABLE SUBJECT //PUNT IF THERE IS A NON-NP SUBJECT //also, avoid "there are ..." sentences tregexOpStr = "ROOT < (S < (NP !< EX))"; matchPattern = TregexPatternFactory.getPattern(tregexOpStr); matcher = matchPattern.matcher(inputTree); res = matcher.matches(); return res; }