Exemplo n.º 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(),
     )
Exemplo n.º 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())
Exemplo n.º 3
0
    def _timex_from_node(self, node):
        """
        Given a TIMEX2 node, create a timex object with the values of that node
        """
        t = Timex()

        if node.hasAttribute('SET'):
            if node.getAttribute('SET').lower() == 'yes':
                t.type = 'set'
                if node.hasAttribute('PERIODICITY'):
                    t.value = 'P' + node.getAttribute('PERIODICITY')[1:]

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

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

        if node.hasAttribute('GRANUALITY'):
            t.freq = node.getAttribute('GRANUALITY')[1:]

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

        return t
Exemplo n.º 4
0
    def _timex_from_node(self, node):
        """
        Given a TIMEX2 node, create a timex object with the values of that node
        """
        t = Timex()

        if node.hasAttribute('SET'):
            if node.getAttribute('SET').lower() == 'yes':
                t.type = 'set'
                if node.hasAttribute('PERIODICITY'):
                    t.value = 'P' + node.getAttribute('PERIODICITY')[1:]

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

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

        if node.hasAttribute('GRANUALITY'):
            t.freq = node.getAttribute('GRANUALITY')[1:]

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

        return t
Exemplo n.º 5
0
 def test_reconcile_TIMEX_SET(self):
     s = Timex2XmlDocument('<root>This is some annotated text.</root>')
     t = Timex(type='set')
     t.value = "P6M"
     t.mod = "BEFORE"
     s.reconcile([[('This', 'POS', set()), ('is', 'POS', set()), ('some', 'POS', set([t])), ('annotated', 'POS', set([t])), ('text', 'POS', {t}), ('.', 'POS', set())]])
     self.assertEqual(str(s), xml.dom.minidom.parseString('<root>This is <TIMEX2 PERIODICITY="F6M" MOD="BEFORE" SET="YES">some annotated text</TIMEX2>.</root>').toxml())
Exemplo n.º 6
0
 def test_reconcile_TIMEX_SET(self):
     s = Timex2XmlDocument('<root>This is some annotated text.</root>')
     t = Timex(type='set')
     t.value = "P6M"
     t.mod = "BEFORE"
     s.reconcile([[('This', 'POS', set()), ('is', 'POS', set()), ('some', 'POS', set([t])), ('annotated', 'POS', set([t])), ('text', 'POS', {t}), ('.', 'POS', set())]])
     self.assertEquals(str(s), xml.dom.minidom.parseString('<root>This is <TIMEX2 PERIODICITY="F6M" MOD="BEFORE" SET="YES">some annotated text</TIMEX2>.</root>').toxml())
Exemplo n.º 7
0
 def test_reconcile_TIMEX(self):
     s = Timex2XmlDocument('<root>This is some annotated text.</root>')
     t = Timex(type='date')
     t.value = "20100710"
     t.mod = "BEFORE"
     t.freq = "1M"
     t.comment = "Test"
     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 <TIMEX2 VAL="20100710" MOD="BEFORE" COMMENT="Test" GRANUALITY="G1M">some annotated text</TIMEX2>.</root>').toxml())
Exemplo n.º 8
0
 def test_reconcile_TIMEX(self):
     s = Timex2XmlDocument('<root>This is some annotated text.</root>')
     t = Timex(type='date')
     t.value = "20100710"
     t.mod = "BEFORE"
     t.freq = "1M"
     t.comment = "Test"
     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 <TIMEX2 VAL="20100710" MOD="BEFORE" COMMENT="Test" GRANUALITY="G1M">some annotated text</TIMEX2>.</root>').toxml())
Exemplo n.º 9
0
    def test_reconcile_sents_attrs(self):
        t1 = Timex(id=1, type='date')
        t2 = Timex(id=2)
        t3 = Timex(id=3)
        t1.value = "20100710"
        t1.mod = "BEFORE"
        t1.freq = "1M"
        t1.comment = "Test"
        t1.granuality = "1D"
        t1.non_specific = True
        t1.quant = 'EVERY'
        t1.temporal_function = True
        t1.document_role = 'MODIFICATION_TIME'
        t1.begin_timex = t1
        t1.end_timex = t2
        t1.context = t3
        d = GateDocument("""This	POS	B	20101010
is	POS	I
a	POS	I
sentence	POS	I
.	.	I
And	POS	B
a	POS	I
second	POS	I
sentence	POS	I
.	POS	I
Outside	POS	O""")
        d.reconcile([[('This', 'POS', set()), ('is', 'POS', set()),
                      ('a', 'POS', set([t1])), ('sentence', 'POS', set([t1])),
                      ('.', '.', set())],
                     [
                         ('And', 'POS', set()),
                         ('a', 'POS', set()),
                         ('second', 'POS', set()),
                         ('sentence', 'POS', set()),
                         ('.', 'POS', set()),
                     ], [('Outside', 'POS', set())]])
        self.assertEquals(
            str(d), """This		
is		
a	id=t1,value=20100710,type=DATE,mod=BEFORE,freq=1M,quant=EVERY,temporalFunction=true,functionInDocument=MODIFICATION_TIME,beginPoint=t1,endPoint=t2,anchorTimeID=t3	
sentence		t1
.		
And		
a		
second		
sentence		
.		
Outside		
""")
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
0
 def test_attr(self):
     t1 = Timex(id=1, type='date')
     t2 = Timex(id=2)
     t3 = Timex(id=3)
     t1.value = "20100710"
     t1.mod = "BEFORE"
     t1.freq = "1M"
     t1.comment = "Test"
     t1.granuality = "1D"
     t1.non_specific = True
     t1.quant = 'EVERY'
     t1.temporal_function = True
     t1.document_role = 'MODIFICATION_TIME'
     t1.begin_timex = t1
     t1.end_timex = t2
     t1.context = t3
     sents = [[('The', 'DT', set()), ('first', 'JJ', {t1}), ('sentence', 'NN', set()), ('.', '.', set())],
              [('The', 'DT', set()), ('second', 'JJ', {t2}), ('sentence', 'NN', {t2}), ('.', '.', {t3})]]
     d = TempEval2Document.create(sents, 'ABC1')
     with open(self.filepath('timex-attr.tab')) as fd:
         self.assertEquals(sorted(d.get_attrs().splitlines()), sorted(fd.read().splitlines()))
Exemplo n.º 13
0
 def test_attr(self):
     t1 = Timex(id=1, type='date')
     t2 = Timex(id=2)
     t3 = Timex(id=3)
     t1.value = "20100710"
     t1.mod = "BEFORE"
     t1.freq = "1M"
     t1.comment = "Test"
     t1.granuality = "1D"
     t1.non_specific = True
     t1.quant = 'EVERY'
     t1.temporal_function = True
     t1.document_role = 'MODIFICATION_TIME'
     t1.begin_timex = t1
     t1.end_timex = t2
     t1.context = t3
     sents = [[('The', 'DT', set()), ('first', 'JJ', {t1}), ('sentence', 'NN', set()), ('.', '.', set())],
              [('The', 'DT', set()), ('second', 'JJ', {t2}), ('sentence', 'NN', {t2}), ('.', '.', {t3})]]
     d = TempEval2Document.create(sents, 'ABC1')
     with open(self.filepath('timex-attr.tab')) as fd:
         self.assertEqual(sorted(d.get_attrs().splitlines()), sorted(fd.read().splitlines()))
Exemplo n.º 14
0
    def test_reconcile_sents_attrs(self):
        t1 = Timex(id=1, type='date')
        t2 = Timex(id=2)
        t3 = Timex(id=3)
        t1.value = "20100710"
        t1.mod = "BEFORE"
        t1.freq = "1M"
        t1.comment = "Test"
        t1.granuality = "1D"
        t1.non_specific = True
        t1.quant = 'EVERY'
        t1.temporal_function = True
        t1.document_role = 'MODIFICATION_TIME'
        t1.begin_timex = t1
        t1.end_timex = t2
        t1.context = t3
        d = GateDocument("""This	POS	B	20101010
is	POS	I
a	POS	I
sentence	POS	I
.	.	I
And	POS	B
a	POS	I
second	POS	I
sentence	POS	I
.	POS	I
Outside	POS	O""")
        d.reconcile([[('This', 'POS', set()), ('is', 'POS', set()), ('a', 'POS', set([t1])), ('sentence', 'POS', set([t1])), ('.', '.', set())], [('And', 'POS', set()), ('a', 'POS', set()), ('second', 'POS', set()), ('sentence', 'POS', set()), ('.', 'POS', set()), ], [('Outside', 'POS', set())]])
        self.assertEquals(str(d), """This		
is		
a	id=t1,value=20100710,type=DATE,mod=BEFORE,freq=1M,quant=EVERY,temporalFunction=true,functionInDocument=MODIFICATION_TIME,beginPoint=t1,endPoint=t2,anchorTimeID=t3	
sentence		t1
.		
And		
a		
second		
sentence		
.		
Outside		
""")