def test_entity_created(self): kind = EntityKindFactory() doc = IEDocFactory() offset = 0 offset_end = 1 entity_count = Entity.objects.all().count() EntityOccurrenceManager.create_with_entity(kind, doc, offset, offset_end) new_entity_count = Entity.objects.all().count() self.assertEqual(new_entity_count, entity_count + 1)
def test_segmenter_is_run(self): with mock.patch("iepy.preprocess.segmenter.SyntacticSegmenterRunner") as mock_segmenter: kind = EntityKindFactory() doc = IEDocFactory() offset = 0 offset_end = 1 EntityOccurrenceManager.create_with_entity( kind, doc, offset, offset_end ) self.assertTrue(mock_segmenter.called)
def test_entity_created(self): kind = EntityKindFactory() doc = IEDocFactory() offset = 0 offset_end = 1 entity_count = Entity.objects.all().count() EntityOccurrenceManager.create_with_entity( kind, doc, offset, offset_end ) new_entity_count = Entity.objects.all().count() self.assertEqual(new_entity_count, entity_count + 1)
def test_segmenter_is_run(self): with mock.patch("iepy.preprocess.segmenter.SyntacticSegmenterRunner" ) as mock_segmenter: kind = EntityKindFactory() doc = IEDocFactory() offset = 0 offset_end = 1 EntityOccurrenceManager.create_with_entity(kind, doc, offset, offset_end) self.assertTrue(mock_segmenter.called)
def create_entity_occurrence(request): kind = get_object_or_404(EntityKind, id=request.POST.get("kind")) document = get_object_or_404(IEDocument, id=request.POST.get("doc_id")) if "offset" not in request.POST or "offset_end" not in request.POST: raise HttpResponseBadRequest("Invalid offsets") try: offset = int(request.POST["offset"]) offset_end = int(request.POST["offset_end"]) except ValueError: raise HttpResponseBadRequest("Invalid offsets") EntityOccurrenceManager.create_with_entity(kind, document, offset, offset_end) result = json.dumps({"success": True}) return HttpResponse(result, content_type='application/json')