You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.6 KiB

from rest_framework import serializers
from .models import Label, Project, Document
from .models import DocumentAnnotation, SequenceAnnotation, Seq2seqAnnotation
class LabelSerializer(serializers.ModelSerializer):
class Meta:
model = Label
fields = ('id', 'text', 'shortcut', 'background_color', 'text_color')
class DocumentAnnotationSerializer(serializers.ModelSerializer):
label = LabelSerializer()
class Meta:
model = DocumentAnnotation
fields = ('id', 'prob', 'label')
class DocumentSerializer(serializers.ModelSerializer):
labels = DocumentAnnotationSerializer(source='doc_annotations', many=True)
class Meta:
model = Document
fields = ('id', 'text', 'labels')
class SequenceAnnotationSerializer(serializers.ModelSerializer):
label = LabelSerializer()
class Meta:
model = SequenceAnnotation
fields = ('id', 'prob', 'label', 'start_offset', 'end_offset')
class SequenceSerializer(serializers.ModelSerializer):
labels = SequenceAnnotationSerializer(source='seq_annotations', many=True)
class Meta:
model = Document
fields = ('id', 'text', 'labels')
class Seq2seqAnnotationSerializer(serializers.ModelSerializer):
class Meta:
model = Seq2seqAnnotation
fields = ('id',)
class Seq2seqSerializer(serializers.ModelSerializer):
pass
class ProjectSerializer(serializers.ModelSerializer):
labels = LabelSerializer(many=True)
documents = DocumentSerializer(many=True)
class Meta:
model = Project
fields = ('id', 'name', 'description', 'users', 'labels', 'documents')