Пример #1
0
 def test_reconcile_TIMEX(self):
     s = Timex3XmlDocument("<root>This is some annotated text.</root>")
     t = Timex(type="date")
     t1 = Timex(id=1)
     t2 = Timex(id=2)
     t3 = Timex(id=3)
     t.value = "20100710"
     t.id = 6
     t.mod = "BEFORE"
     t.freq = "1M"
     t.comment = "Test"
     t.quant = "EVERY"
     t.temporal_function = True
     t.document_role = "MODIFICATION_TIME"
     t.begin_timex = t1
     t.end_timex = t2
     t.context = t3
     s.reconcile(
         [
             [
                 ("This", "POS", set()),
                 ("is", "POS", set()),
                 ("some", "POS", {t}),
                 ("annotated", "POS", {t}),
                 ("text", "POS", {t}),
                 (".", "POS", set()),
             ]
         ]
     )
     self.assertEquals(
         str(s),
         xml.dom.minidom.parseString(
             '<root>This is <TIMEX3 tid="t6" beginPoint="t1" endPoint="t2" anchorTimeID="t3" functionInDocument="MODIFICATION_TIME" temporalFunction="true" type="DATE" value="20100710" mod="BEFORE" freq="1M" comment="Test" quant="EVERY">some annotated text</TIMEX3>.</root>'
         ).toxml(),
     )
Пример #2
0
 def test_reconcile_TIMEX(self):
     s = Timex3XmlDocument('<root>This is some annotated text.</root>')
     t = Timex(type='date')
     t1 = Timex(id=1)
     t2 = Timex(id=2)
     t3 = Timex(id=3)
     t.value = "20100710"
     t.id = 6
     t.mod = "BEFORE"
     t.freq = "1M"
     t.comment = "Test"
     t.quant = 'EVERY'
     t.temporal_function = True
     t.document_role = 'MODIFICATION_TIME'
     t.begin_timex = t1
     t.end_timex = t2
     t.context = t3
     s.reconcile([[('This', 'POS', set()), ('is', 'POS', set()),
                   ('some', 'POS', {t}), ('annotated', 'POS', {t}),
                   ('text', 'POS', {t}), ('.', 'POS', set())]])
     self.assertEqual(
         str(s),
         xml.dom.minidom.parseString(
             '<root>This is <TIMEX3 tid="t6" beginPoint="t1" endPoint="t2" anchorTimeID="t3" functionInDocument="MODIFICATION_TIME" temporalFunction="true" type="DATE" value="20100710" mod="BEFORE" freq="1M" comment="Test" quant="EVERY">some annotated text</TIMEX3>.</root>'
         ).toxml())
Пример #3
0
    def _timex_from_node(self, node):
        """
        Given a node representing a TIMEX3 element, return a timex object
        representing it
        """
        t = Timex()

        if node.hasAttribute('tid'):
            t.id = int(node.getAttribute('tid')[1:])

        if node.hasAttribute('value'):
            t.value = node.getAttribute('value')

        if node.hasAttribute('mod'):
            t.mod = node.getAttribute('mod')

        if node.hasAttribute('type'):
            t.type = node.getAttribute('type')

        if node.hasAttribute('freq'):
            t.freq = node.getAttribute('freq')

        if node.hasAttribute('quant'):
            t.quant = node.getAttribute('quant')

        if node.hasAttribute('comment'):
            t.comment = node.getAttribute('comment')

        if node.getAttribute('temporalFunction'):
            t.temporal_function = True

        if node.hasAttribute('functionInDocument'):
            t.document_role = node.getAttribute('functionInDocument')

        if node.hasAttribute('beginPoint'):
            t.begin_timex = int(node.getAttribute('beginPoint')[1:])

        if node.hasAttribute('endPoint'):
            t.end_timex = int(node.getAttribute('endPoint')[1:])

        if node.hasAttribute('anchorTimeID'):
            t.context = int(node.getAttribute('anchorTimeID')[1:])

        return t
Пример #4
0
    def _timex_from_node(self, node):
        """
        Given a node representing a TIMEX3 element, return a timex object
        representing it
        """
        t = Timex()

        if node.hasAttribute('tid'):
            t.id = int(node.getAttribute('tid')[1:])

        if node.hasAttribute('value'):
            t.value = node.getAttribute('value')

        if node.hasAttribute('mod'):
            t.mod = node.getAttribute('mod')

        if node.hasAttribute('type'):
            t.type = node.getAttribute('type')

        if node.hasAttribute('freq'):
            t.freq = node.getAttribute('freq')

        if node.hasAttribute('quant'):
            t.quant = node.getAttribute('quant')

        if node.hasAttribute('comment'):
            t.comment = node.getAttribute('comment')

        if node.getAttribute('temporalFunction'):
            t.temporal_function = True

        if node.hasAttribute('functionInDocument'):
            t.document_role = node.getAttribute('functionInDocument')

        if node.hasAttribute('beginPoint'):
            t.begin_timex = int(node.getAttribute('beginPoint')[1:])

        if node.hasAttribute('endPoint'):
            t.end_timex = int(node.getAttribute('endPoint')[1:])

        if node.hasAttribute('anchorTimeID'):
            t.context = int(node.getAttribute('anchorTimeID')[1:])

        return t
Пример #5
0
 def test_assign_IDs_consecutive(self):
     # Get some sample IDs
     ts = set([Timex(), Timex(), Timex()])
     at = Timex()
     at.id = 2
     ts.add(at)
     add_timex_ids(ts)
     
     # Get the assigned IDs
     tids = set()
     for t in ts:
         tids.add(t.id)
     
     # Should be exactly 4 unique IDs and pre-assigned one hasn't changed
     self.assertEquals(len(tids), 4)
     self.assertEquals(2, at.id)
     
     # Should be consecutive for new ones
     self.assertTrue(1 in tids)
     self.assertTrue(2 in tids)
     self.assertTrue(3 in tids)
     self.assertTrue(4 in tids)