Example #1
0
 def test_clean_with_multiple_examples(self):
     self.disable_overlapping()
     example_uuid1 = uuid.uuid4()
     example_uuid2 = uuid.uuid4()
     labels = [
         SpanLabel(example_uuid=example_uuid1,
                   label="A",
                   start_offset=0,
                   end_offset=1),
         SpanLabel(example_uuid=example_uuid2,
                   label="B",
                   start_offset=0,
                   end_offset=3),
     ]
     mommy.make("Example", project=self.project.item, uuid=example_uuid1)
     mommy.make("Example", project=self.project.item, uuid=example_uuid2)
     spans = Spans(labels, self.types)
     spans.clean(self.project.item)
     self.assertEqual(len(spans), 2)
Example #2
0
 def setUp(self):
     self.types = LabelTypes(SpanType)
     self.project = prepare_project(SEQUENCE_LABELING,
                                    allow_overlapping=True)
     self.user = self.project.admin
     example_uuid = uuid.uuid4()
     labels = [
         SpanLabel(example_uuid=example_uuid,
                   label="A",
                   start_offset=0,
                   end_offset=1),
         SpanLabel(example_uuid=example_uuid,
                   label="B",
                   start_offset=0,
                   end_offset=3),
         SpanLabel(example_uuid=example_uuid,
                   label="B",
                   start_offset=3,
                   end_offset=4),
     ]
     mommy.make("Example", project=self.project.item, uuid=example_uuid)
     self.spans = Spans(labels, self.types)
Example #3
0
 def test_parse_invalid_dict(self):
     example_uuid = uuid.uuid4()
     with self.assertRaises(ValueError):
         SpanLabel.parse(example_uuid, obj={"label": "A", "start_offset": 0})
Example #4
0
 def test_create_type(self):
     span = SpanLabel(label="A", start_offset=0, end_offset=1, example_uuid=uuid.uuid4())
     span_type = span.create_type(self.project.item)
     self.assertIsInstance(span_type, SpanType)
     self.assertEqual(span_type.text, "A")
Example #5
0
 def test_invalid_offset(self):
     with self.assertRaises(ValueError):
         SpanLabel(label="A", start_offset=1, end_offset=0, example_uuid=uuid.uuid4())
Example #6
0
 def test_parse_dict(self):
     example_uuid = uuid.uuid4()
     span = SpanLabel.parse(example_uuid, obj={"label": "A", "start_offset": 0, "end_offset": 1})
     self.assertEqual(span.label, "A")
     self.assertEqual(span.start_offset, 0)
     self.assertEqual(span.end_offset, 1)
Example #7
0
 def test_parse_tuple(self):
     example_uuid = uuid.uuid4()
     span = SpanLabel.parse(example_uuid, obj=(0, 1, "A"))
     self.assertEqual(span.label, "A")
     self.assertEqual(span.start_offset, 0)
     self.assertEqual(span.end_offset, 1)
Example #8
0
 def test_comparison(self):
     span1 = SpanLabel(label="A", start_offset=0, end_offset=1, example_uuid=uuid.uuid4())
     span2 = SpanLabel(label="A", start_offset=1, end_offset=2, example_uuid=uuid.uuid4())
     self.assertLess(span1, span2)
Example #9
0
 def test_create(self):
     span = SpanLabel(label="A", start_offset=0, end_offset=1, example_uuid=uuid.uuid4())
     types = MagicMock()
     types.__getitem__.return_value = mommy.make(SpanType, project=self.project.item)
     span_model = span.create(self.user, self.example, types)
     self.assertIsInstance(span_model, SpanModel)