diff --git a/doccano/app/db.sqlite3 b/doccano/app/db.sqlite3 index 399e96ee..26bddf1c 100644 Binary files a/doccano/app/db.sqlite3 and b/doccano/app/db.sqlite3 differ diff --git a/doccano/app/server/admin.py b/doccano/app/server/admin.py index 1cf1bb1a..cca19f35 100644 --- a/doccano/app/server/admin.py +++ b/doccano/app/server/admin.py @@ -1,8 +1,8 @@ from django.contrib import admin -from .models import Annotation, Label, RawData, Project +from .models import Annotation, Label, Document, Project admin.site.register(Annotation) admin.site.register(Label) -admin.site.register(RawData) +admin.site.register(Document) admin.site.register(Project) diff --git a/doccano/app/server/models.py b/doccano/app/server/models.py index 8b578e32..0a44dbc8 100644 --- a/doccano/app/server/models.py +++ b/doccano/app/server/models.py @@ -24,7 +24,7 @@ class Label(models.Model): 'shortcut': self.shortcut} -class RawData(models.Model): +class Document(models.Model): text = models.TextField() project = models.ForeignKey(Project, on_delete=models.CASCADE, null=True) @@ -36,7 +36,7 @@ class RawData(models.Model): class Annotation(models.Model): prob = models.FloatField(blank=True, null=True) label = models.ForeignKey(Label, on_delete=models.CASCADE) - data = models.ForeignKey(RawData, on_delete=models.CASCADE) + data = models.ForeignKey(Document, on_delete=models.CASCADE) manual = models.BooleanField(default=False) def as_dict(self): diff --git a/doccano/app/server/tests.py b/doccano/app/server/tests.py index dd58d89d..d045f17f 100644 --- a/doccano/app/server/tests.py +++ b/doccano/app/server/tests.py @@ -3,7 +3,7 @@ import os from django.test import TestCase, Client from django.urls import reverse -from .models import Project, RawData, Label +from .models import Project, Document, Label class ProjectModelTest(TestCase): @@ -24,7 +24,7 @@ class TestRawDataAPI(TestCase): self.assertEqual(res.json()['data'], []) def test_post(self): - self.assertEqual(RawData.objects.count(), 0) + self.assertEqual(Document.objects.count(), 0) filename = os.path.join(os.path.dirname(__file__), 'data/test.jsonl') client = Client() @@ -32,7 +32,7 @@ class TestRawDataAPI(TestCase): client.post(reverse('data_api', args=[1]), {'name': 'fred', 'attachment': f}) - self.assertGreater(RawData.objects.count(), 0) + self.assertGreater(Document.objects.count(), 0) class TestLabelAPI(TestCase): diff --git a/doccano/app/server/views.py b/doccano/app/server/views.py index 0055a123..51ceac01 100644 --- a/doccano/app/server/views.py +++ b/doccano/app/server/views.py @@ -6,7 +6,7 @@ from django.views import View from django.views.generic.list import ListView from django.views.generic.detail import DetailView -from .models import Annotation, Label, RawData, Project +from .models import Annotation, Label, Document, Project class AnnotationView(View): @@ -30,7 +30,7 @@ class AnnotationAPIView(View): docs = Annotation.objects.all() else: # Left outer join data and annotation. - docs = RawData.objects.filter(annotation__isnull=True, project=project) + docs = Document.objects.filter(annotation__isnull=True, project=project) docs = [{**d.as_dict(), **{'labels': []}} for d in docs] if not docs: @@ -42,7 +42,7 @@ class AnnotationAPIView(View): body = json.loads(request.body) data_id, label_id = body.get('id'), body.get('label_id') # {id:0, label_id:1} - data = RawData.objects.get(id=data_id) + data = Document.objects.get(id=data_id) label = Label.objects.get(id=label_id) Annotation(data=data, label=label, manual=True).save() @@ -59,8 +59,8 @@ class AnnotationAPIView(View): class MetaInfoAPI(View): def get(self, request, *args, **kwargs): - total = RawData.objects.count() - remaining = RawData.objects.filter(annotation__isnull=True).count() + total = Document.objects.count() + remaining = Document.objects.filter(annotation__isnull=True).count() return JsonResponse({'total': total, 'remaining': remaining}) @@ -69,7 +69,7 @@ class SearchAPI(View): def get(self, request, *args, **kwargs): keyword = request.GET.get('keyword') - docs = RawData.objects.filter(text__contains=keyword) + docs = Document.objects.filter(text__contains=keyword) labels = [[a.as_dict() for a in Annotation.objects.filter(data=d.id)] for d in docs] # print(annotations) # print(docs) @@ -140,7 +140,7 @@ class RawDataAPI(View): content = ''.join(chunk.decode('utf-8') for chunk in f.chunks()) for line in content.split('\n'): j = json.loads(line) - RawData(text=j['text']).save() + Document(text=j['text']).save() return JsonResponse({'status': 'ok'})