コード例 #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
コード例 #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))
コード例 #3
0
 def test_PreterminalJapaneseUntypedVar(self):
     tree = tree_or_string(u'(学生 hello)')
     subtree = tree_or_string(u'?x0|')
     self.assertTrue(TreeContains(tree, subtree))
コード例 #4
0
 def test_PreterminalJapaneseTypedVarImmutableTree(self):
     tree = ImmutableTree.fromstring(u'(学生 hello)')
     subtree = tree_or_string(u'?x0|学生')
     self.assertTrue(TreeContains(tree, subtree))
コード例 #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))
コード例 #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))
コード例 #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))
コード例 #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))
コード例 #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))
コード例 #10
0
 def test_NegativeMatchPreterminalToNonterminal(self):
     tree = tree_or_string('(DT the)')
     subtree = tree_or_string('(NP (JJ ?x0|))')
     self.assertFalse(TreeContains(tree, subtree))
コード例 #11
0
 def test_PositiveMatchPreterminal(self):
     tree = tree_or_string('(DT the)')
     subtree = tree_or_string('(DT ?x0|)')
     self.assertTrue(TreeContains(tree, subtree))
コード例 #12
0
 def test_NegativeMatchTerminal(self):
     tree = tree_or_string('the')
     subtree = tree_or_string('da')
     self.assertFalse(TreeContains(tree, subtree))
コード例 #13
0
 def test_PositiveMatchTerminal(self):
     tree = tree_or_string('the')
     subtree = tree_or_string('the')
     self.assertTrue(TreeContains(tree, subtree))