Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
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')
Пример #6
0
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')