Source code for annotations.serializers

from rest_framework import serializers
from annotations.models import VogonUser
from models import *
from concepts.models import Concept, Type


[docs]class UserSerializer(serializers.ModelSerializer):
[docs] class Meta: model = VogonUser fields = ('username', 'email', 'id', 'affiliation', 'location', 'full_name', 'link')
[docs]class RemoteCollectionSerializer(serializers.Serializer): source = serializers.IntegerField() id_or_uri = serializers.CharField(max_length=255) name = serializers.CharField(max_length=255)
[docs]class RemoteResourceSerializer(serializers.Serializer): source = serializers.IntegerField() id_or_uri = serializers.CharField(max_length=255) title = serializers.CharField(max_length=255)
[docs]class RepositorySerializer(serializers.ModelSerializer):
[docs] class Meta: model = Repository
[docs]class RelationSerializer(serializers.ModelSerializer):
[docs] class Meta: model = Relation
[docs]class AppellationSerializer(serializers.ModelSerializer):
[docs] class Meta: model = Appellation fields = ('asPredicate', 'created', 'createdBy', 'endPos', 'id', 'interpretation', 'interpretation_type', 'occursIn', 'startPos', 'stringRep', 'tokenIds', 'interpretation_label', 'interpretation_type_label')
[docs]class ConceptSerializer(serializers.ModelSerializer):
[docs] class Meta: model = Concept fields = ('id', 'url', 'uri', 'label', 'authority', 'typed', 'description', 'pos', 'resolved', 'typed_label')
[docs]class TypeSerializer(serializers.ModelSerializer):
[docs] class Meta: model = Type fields = ('id', 'url', 'uri', 'label', 'authority', 'typed', 'description')
[docs]class RelationSetSerializer(serializers.ModelSerializer): appellations = AppellationSerializer(many=True) concepts = ConceptSerializer(many=True)
[docs] class Meta: model = RelationSet fields = ('id', 'label', 'created', 'template', 'createdBy', 'occursIn', 'appellations', 'concepts')
[docs]class TemporalBoundsSerializer(serializers.ModelSerializer):
[docs] class Meta: model = TemporalBounds
[docs]class TextSerializer(serializers.ModelSerializer):
[docs] class Meta: model = Text fields = ('id', 'uri', 'title', 'created', 'added', 'addedBy', 'source', 'annotators', 'annotation_count')
[docs] def create(self, validated_data): repository = Repository.objects.get(pk=validated_data['source']) # TODO: Make retrieval/tokenization/other processing asynchronous. tokenizedContent = tokenize(retrieve(repository, validated_data['uri'])) text = Text(uri=validated_data['uri'], title=validated_data['title'], source=repository, addedBy=self.context['request'].user, tokenizedContent=tokenizedContent) text.save() return HttpResponse(text.id)
[docs]class TextCollectionSerializer(serializers.ModelSerializer):
[docs] class Meta: model = TextCollection