Browse Source

Add script for seq2seq annotation

pull/10/head
Hironsan 7 years ago
parent
commit
d0bbe8ba7c
7 changed files with 246 additions and 9 deletions
  1. BIN
      app/db.sqlite3
  2. 8
      app/server/serializers.py
  3. 192
      app/server/static/bundle/seq2seq.js
  4. 28
      app/server/static/js/seq2seq.js
  5. 7
      app/server/templates/annotation/seq2seq.html
  6. 17
      app/server/views.py
  7. 3
      app/server/webpack.config.js

BIN
app/db.sqlite3

8
app/server/serializers.py

@ -47,11 +47,15 @@ class Seq2seqAnnotationSerializer(serializers.ModelSerializer):
class Meta:
model = Seq2seqAnnotation
fields = ('id',)
fields = ('id', 'text')
class Seq2seqSerializer(serializers.ModelSerializer):
pass
labels = Seq2seqAnnotationSerializer(source='seq2seq_annotations', many=True)
class Meta:
model = Document
fields = ('id', 'text', 'labels')
class ProjectSerializer(serializers.ModelSerializer):

192
app/server/static/bundle/seq2seq.js
File diff suppressed because it is too large
View File

28
app/server/static/js/seq2seq.js

@ -0,0 +1,28 @@
import Vue from 'vue';
Vue.use(require('vue-shortkey'));
import annotationMixin from './mixin.js';
import HTTP from './http.js';
var vm = new Vue({
el: '#mail-app',
delimiters: ['[[', ']]'],
mixins: [annotationMixin],
methods: {
addLabel: async function (label_id) {
var payload = {
'label_id': label_id
};
var doc_id = this.items[this.cur].id;
await HTTP.post(`docs/${doc_id}/annotations/`, payload).then(response => {
this.items[this.cur]['labels'].push(response.data);
});
this.updateProgress();
}
},
created: function () {
this.updateProgress();
this.submit();
}
});

7
app/server/templates/annotation/seq2seq.html

@ -10,12 +10,15 @@
</div>
<div class="card" style="margin-top:30px;">
<div class="card-content" contenteditable="true">
<div class="card-content" contenteditable="true" v-if="items[cur].labels.length">
[[ items[cur].labels[0].text ]]
</div>
<div v-else class="card-content" contenteditable="true">
Input response...
</div>
</div>
{% endblock %}
{% block footer %}
<script type="text/javascript" src="{% static 'js/main.js' %}"></script>
<script type="text/javascript" src="{% static 'bundle/seq2seq.js' %}"></script>
{% endblock %}

17
app/server/views.py

@ -17,9 +17,10 @@ from django.db.models.query import QuerySet
from .models import Label, Document, Project
from .models import DocumentAnnotation, SequenceAnnotation
from .models import DocumentAnnotation, SequenceAnnotation, Seq2seqAnnotation
from .serializers import LabelSerializer, ProjectSerializer, DocumentSerializer, DocumentAnnotationSerializer
from .serializers import SequenceSerializer, SequenceAnnotationSerializer
from .serializers import Seq2seqSerializer, Seq2seqAnnotationSerializer
class IndexView(TemplateView):
@ -147,6 +148,8 @@ class ProjectDocsAPI(generics.ListCreateAPIView):
self.serializer_class = DocumentSerializer
elif project.is_type_of(Project.SEQUENCE_LABELING):
self.serializer_class = SequenceSerializer
elif project.is_type_of(Project.Seq2seq):
self.serializer_class = Seq2seqSerializer
return self.serializer_class
@ -158,9 +161,6 @@ class ProjectDocsAPI(generics.ListCreateAPIView):
class AnnotationsAPI(generics.ListCreateAPIView):
#queryset = DocumentAnnotation.objects.all()
#queryset = SequenceAnnotation.objects.all()
#serializer_class = DocumentAnnotationSerializer
pagination_class = None
def get_serializer_class(self):
@ -170,6 +170,8 @@ class AnnotationsAPI(generics.ListCreateAPIView):
self.serializer_class = DocumentAnnotationSerializer
elif project.is_type_of(Project.SEQUENCE_LABELING):
self.serializer_class = SequenceAnnotationSerializer
elif project.is_type_of(Project.Seq2seq):
self.serializer_class = Seq2seqAnnotationSerializer
return self.serializer_class
@ -181,6 +183,8 @@ class AnnotationsAPI(generics.ListCreateAPIView):
self.queryset = DocumentAnnotation.objects.all()
elif project.is_type_of(Project.SEQUENCE_LABELING):
self.queryset = SequenceAnnotation.objects.all()
elif project.is_type_of(Project.Seq2seq):
self.queryset = Seq2seqAnnotation.objects.all()
queryset = self.queryset.filter(document=doc_id)
return queryset
@ -199,6 +203,9 @@ class AnnotationsAPI(generics.ListCreateAPIView):
user=self.request.user,
start_offset=request.data['start_offset'],
end_offset=request.data['end_offset'])
elif project.is_type_of(Project.Seq2seq):
self.serializer_class = Seq2seqAnnotationSerializer
annotation = Seq2seqAnnotation(document=doc, manual=True, user=self.request.user)
annotation.save()
serializer = self.serializer_class(annotation)
@ -215,6 +222,8 @@ class AnnotationAPI(generics.RetrieveUpdateDestroyAPIView):
self.queryset = DocumentAnnotation.objects.all()
elif project.is_type_of(Project.SEQUENCE_LABELING):
self.queryset = SequenceAnnotation.objects.all()
elif project.is_type_of(Project.Seq2seq):
self.queryset = Seq2seqAnnotation.objects.all()
queryset = self.queryset.filter(document=doc_id)
return queryset

3
app/server/webpack.config.js

@ -4,7 +4,8 @@ module.exports = {
mode: 'development',
entry: {
'sequence_labeling': './static/js/sequence_labeling.js',
'document_classification': './static/js/document_classification.js'
'document_classification': './static/js/document_classification.js',
'seq2seq': './static/js/seq2seq.js'
},
output: {
path: __dirname + '/static/bundle',

Loading…
Cancel
Save