Example #1
0
def create_ne_segments(values, starts, ends, document, segstorage):
    segments = []
    segment = None
    for value, start, end in izip(values, starts, ends):
        if value.startswith('B-'):
            ne_value = value[2:]
            if segment is not None:
                segments.append(segment)
                segment = Segment(u'ne_type', ne_value, document, start, end)
            segment = Segment(u'ne_type', ne_value, document, start, end)
        elif value.startswith('I-'):
            segment.end = end 
        elif value.startswith('O') and segment is not None:
            segments.append(segment)
            segment = None
    if segment is not None:
        segment.end = len(document.text)
        segments.append(segment)
    segstorage.save(segments)
 def test_to_dict(self):
     A = Segment(self.name(), self.value(), self.document(), self.start(), self.end())
     self.assertEqual(Segment.to_dict(A), self.dictionary())
 def test_from_dict(self):
     A = Segment(self.name(), self.value(), self.document(), self.start(), self.end())
     B = Segment.from_dict(self.dictionary())
     self.assertEqual(A, B)