'Test labeled nodes.
Test case from Emily M. Bender.'

def test_labeled_nodes(self):

    search = u'\n                                                #    macros\n                                                @    SBJ    /SBJ/;\n                                                @    VP    /VP/;\n                                                @    VB    /VB/;\n                                                @    VPoB    /V[PB]/;\n                                                @    OBJ    /OBJ/;\n\n                                                #    1    svo\n                                                S    <    @SBJ=s    <    (@VP=v    <    (@VB    $..    @OBJ))    :    =s    ..    =v'
    sent1 = ParentedTree.fromstring(u'(S    (NP-SBJ    I)    (VP    (VB    eat)    (NP-OBJ    (NNS    apples))))')
    sent2 = ParentedTree.fromstring(u'(S    (VP    (VB    eat)    (NP-OBJ    (NNS    apples)))    (NP-SBJ    I))')
    search_firsthalf = (search.split(u'\n\n')[0] + u'S    <    @SBJ    <    (@VP    <    (@VB    $..    @OBJ))')
    search_rewrite = u'S    <    (/.*SBJ/    $..    (/VP/    <    (/VB/    $..    /.*OBJ/)))'
    self.assertTrue(list(tgrep.tgrep_positions(search_firsthalf, [sent1]))[0])
    self.assertTrue(list(tgrep.tgrep_positions(search, [sent1]))[0])
    self.assertTrue(list(tgrep.tgrep_positions(search_rewrite, [sent1]))[0])
    self.assertEqual(list(tgrep.tgrep_positions(search, [sent1])), list(tgrep.tgrep_positions(search_rewrite, [sent1])))
    self.assertTrue(list(tgrep.tgrep_positions(search_firsthalf, [sent2]))[0])
    self.assertFalse(list(tgrep.tgrep_positions(search, [sent2]))[0])
    self.assertFalse(list(tgrep.tgrep_positions(search_rewrite, [sent2]))[0])
    self.assertEqual(list(tgrep.tgrep_positions(search, [sent2])), list(tgrep.tgrep_positions(search_rewrite, [sent2])))
