Browse Source

Rename model

pull/10/head
Hironsan 6 years ago
parent
commit
138182ad1d
5 changed files with 14 additions and 14 deletions
  1. BIN
      doccano/app/db.sqlite3
  2. 4
      doccano/app/server/admin.py
  3. 4
      doccano/app/server/models.py
  4. 6
      doccano/app/server/tests.py
  5. 14
      doccano/app/server/views.py

BIN
doccano/app/db.sqlite3

4
doccano/app/server/admin.py

@ -1,8 +1,8 @@
from django.contrib import admin 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(Annotation)
admin.site.register(Label) admin.site.register(Label)
admin.site.register(RawData)
admin.site.register(Document)
admin.site.register(Project) admin.site.register(Project)

4
doccano/app/server/models.py

@ -24,7 +24,7 @@ class Label(models.Model):
'shortcut': self.shortcut} 'shortcut': self.shortcut}
class RawData(models.Model):
class Document(models.Model):
text = models.TextField() text = models.TextField()
project = models.ForeignKey(Project, on_delete=models.CASCADE, null=True) project = models.ForeignKey(Project, on_delete=models.CASCADE, null=True)
@ -36,7 +36,7 @@ class RawData(models.Model):
class Annotation(models.Model): class Annotation(models.Model):
prob = models.FloatField(blank=True, null=True) prob = models.FloatField(blank=True, null=True)
label = models.ForeignKey(Label, on_delete=models.CASCADE) 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) manual = models.BooleanField(default=False)
def as_dict(self): def as_dict(self):

6
doccano/app/server/tests.py

@ -3,7 +3,7 @@ import os
from django.test import TestCase, Client from django.test import TestCase, Client
from django.urls import reverse from django.urls import reverse
from .models import Project, RawData, Label
from .models import Project, Document, Label
class ProjectModelTest(TestCase): class ProjectModelTest(TestCase):
@ -24,7 +24,7 @@ class TestRawDataAPI(TestCase):
self.assertEqual(res.json()['data'], []) self.assertEqual(res.json()['data'], [])
def test_post(self): 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') filename = os.path.join(os.path.dirname(__file__), 'data/test.jsonl')
client = Client() client = Client()
@ -32,7 +32,7 @@ class TestRawDataAPI(TestCase):
client.post(reverse('data_api', args=[1]), client.post(reverse('data_api', args=[1]),
{'name': 'fred', 'attachment': f}) {'name': 'fred', 'attachment': f})
self.assertGreater(RawData.objects.count(), 0)
self.assertGreater(Document.objects.count(), 0)
class TestLabelAPI(TestCase): class TestLabelAPI(TestCase):

14
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.list import ListView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from .models import Annotation, Label, RawData, Project
from .models import Annotation, Label, Document, Project
class AnnotationView(View): class AnnotationView(View):
@ -30,7 +30,7 @@ class AnnotationAPIView(View):
docs = Annotation.objects.all() docs = Annotation.objects.all()
else: else:
# Left outer join data and annotation. # 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] docs = [{**d.as_dict(), **{'labels': []}} for d in docs]
if not docs: if not docs:
@ -42,7 +42,7 @@ class AnnotationAPIView(View):
body = json.loads(request.body) body = json.loads(request.body)
data_id, label_id = body.get('id'), body.get('label_id') # {id:0, label_id:1} 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) label = Label.objects.get(id=label_id)
Annotation(data=data, label=label, manual=True).save() Annotation(data=data, label=label, manual=True).save()
@ -59,8 +59,8 @@ class AnnotationAPIView(View):
class MetaInfoAPI(View): class MetaInfoAPI(View):
def get(self, request, *args, **kwargs): 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}) return JsonResponse({'total': total, 'remaining': remaining})
@ -69,7 +69,7 @@ class SearchAPI(View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
keyword = request.GET.get('keyword') 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] labels = [[a.as_dict() for a in Annotation.objects.filter(data=d.id)] for d in docs]
# print(annotations) # print(annotations)
# print(docs) # print(docs)
@ -140,7 +140,7 @@ class RawDataAPI(View):
content = ''.join(chunk.decode('utf-8') for chunk in f.chunks()) content = ''.join(chunk.decode('utf-8') for chunk in f.chunks())
for line in content.split('\n'): for line in content.split('\n'):
j = json.loads(line) j = json.loads(line)
RawData(text=j['text']).save()
Document(text=j['text']).save()
return JsonResponse({'status': 'ok'}) return JsonResponse({'status': 'ok'})

Loading…
Cancel
Save