Example #1
0
def FilterMatchingRules(rules, src_subtree, trg_subtree, rhs_child_pos):
  if trg_subtree is None:
    relevant_rules = [rule for rule in rules \
                      if TreeContains(src_subtree, rule.lhs) \
                         and MatchPos(GetPosAt(rule.rhs, ()), rhs_child_pos)]
  else:
    relevant_rules = [rule for rule in rules \
                      if TreeContains(trg_subtree, rule.rhs)
                         and TreeContains(src_subtree, rule.lhs)]
  return relevant_rules
Example #2
0
 def test_LeafVarNoMatch(self):
     tree = tree_or_string(u'(NP (DT the) (NN house))')
     subtree = tree_or_string(u'(NP ?x0|DT ?x1|JJ)')
     self.assertFalse(TreeContains(tree, subtree))
Example #3
0
 def test_PreterminalJapaneseUntypedVar(self):
     tree = tree_or_string(u'(学生 hello)')
     subtree = tree_or_string(u'?x0|')
     self.assertTrue(TreeContains(tree, subtree))
Example #4
0
 def test_PreterminalJapaneseTypedVarImmutableTree(self):
     tree = ImmutableTree.fromstring(u'(学生 hello)')
     subtree = tree_or_string(u'?x0|学生')
     self.assertTrue(TreeContains(tree, subtree))
Example #5
0
 def test_NegativeMatchNonterminal2LevelsFullRight(self):
     tree = Tree.fromstring('(NP (DT the) (NN house))')
     subtree = tree_or_string('(NP (DT the) (NN condominium))')
     self.assertFalse(TreeContains(tree, subtree))
Example #6
0
 def test_PositiveMatchQAVar(self):
     tree = Tree.fromstring('(NP (DT the) (NN house))')
     subtree = tree_or_string('(NP (DT the) (NN []))')
     self.assertTrue(TreeContains(tree, subtree))
Example #7
0
 def test_NegativeMatchNonterminal2Levels(self):
     tree = Tree.fromstring('(NP (DT the) (NN house))')
     subtree = tree_or_string('(NP (DT da) ?x1|NN)')
     self.assertFalse(TreeContains(tree, subtree))
Example #8
0
 def test_PositiveMatchNonterminal2LevelsFull(self):
     tree = Tree.fromstring('(NP (DT the) (NN house))')
     subtree = tree_or_string('(NP (DT the) (NN house))')
     self.assertTrue(TreeContains(tree, subtree))
Example #9
0
 def test_PositiveMatchNonterminalVariable(self):
     tree = Tree.fromstring('(NP (DT the) (NN house))')
     subtree = tree_or_string('?x0|NP')
     self.assertTrue(TreeContains(tree, subtree))
Example #10
0
 def test_NegativeMatchPreterminalToNonterminal(self):
     tree = tree_or_string('(DT the)')
     subtree = tree_or_string('(NP (JJ ?x0|))')
     self.assertFalse(TreeContains(tree, subtree))
Example #11
0
 def test_PositiveMatchPreterminal(self):
     tree = tree_or_string('(DT the)')
     subtree = tree_or_string('(DT ?x0|)')
     self.assertTrue(TreeContains(tree, subtree))
Example #12
0
 def test_NegativeMatchTerminal(self):
     tree = tree_or_string('the')
     subtree = tree_or_string('da')
     self.assertFalse(TreeContains(tree, subtree))
Example #13
0
 def test_PositiveMatchTerminal(self):
     tree = tree_or_string('the')
     subtree = tree_or_string('the')
     self.assertTrue(TreeContains(tree, subtree))