Skip to content

Commit

Permalink
Add support for grouping in annotation display template
Browse files Browse the repository at this point in the history
Closes #482
  • Loading branch information
bkis committed Nov 12, 2024
1 parent 244a11d commit 036e552
Show file tree
Hide file tree
Showing 28 changed files with 407 additions and 80 deletions.
58 changes: 57 additions & 1 deletion Tekst-API/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "Tekst-Dev",
"summary": "An online text research platform",
"contact": {},
"version": "0.1.0a0"
"version": "0.1.1a0"
},
"servers": [
{
Expand Down Expand Up @@ -7172,6 +7172,50 @@
],
"title": "AnnotationAggregation"
},
"AnnotationGroup": {
"properties": {
"key": {
"type": "string",
"maxLength": 16,
"minLength": 1,
"title": "Key"
},
"translations": {
"items": {
"$ref": "#/components/schemas/AnnotationGroupTranslation"
},
"type": "array",
"maxItems": 3,
"title": "Translations",
"description": "Translation for the label of an annotation group"
}
},
"type": "object",
"required": [
"key",
"translations"
],
"title": "AnnotationGroup"
},
"AnnotationGroupTranslation": {
"properties": {
"locale": {
"$ref": "#/components/schemas/TranslationLocaleKey"
},
"translation": {
"type": "string",
"maxLength": 32,
"minLength": 1,
"title": "Translation"
}
},
"type": "object",
"required": [
"locale",
"translation"
],
"title": "AnnotationGroupTranslation"
},
"AudioContentCreate": {
"properties": {
"resourceId": {
Expand Down Expand Up @@ -14460,6 +14504,16 @@
"defaultCollapsed": false
}
},
"annotationGroups": {
"items": {
"$ref": "#/components/schemas/AnnotationGroup"
},
"type": "array",
"maxItems": 32,
"title": "Annotationgroups",
"description": "Display groups to use for grouping annotations",
"default": []
},
"displayTemplate": {
"anyOf": [
{
Expand Down Expand Up @@ -14633,6 +14687,7 @@
"general": {
"defaultCollapsed": false
},
"annotationGroups": [],
"multiValueDelimiter": "/"
}
},
Expand Down Expand Up @@ -14859,6 +14914,7 @@
"general": {
"defaultCollapsed": false
},
"annotationGroups": [],
"multiValueDelimiter": "/"
}
},
Expand Down
45 changes: 43 additions & 2 deletions Tekst-API/tekst/resources/text_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from uuid import uuid4

from pydantic import BeforeValidator, Field, StringConstraints, field_validator
from typing_extensions import TypeAliasType
from typing_extensions import TypeAliasType, TypedDict

from tekst.logs import log, log_op_end, log_op_start
from tekst.models.common import (
ModelBase,
PrecomputedDataDocument,
SchemaOptionalNonNullable,
TranslationBase,
Translations,
)
from tekst.models.content import ContentBase, ContentBaseDocument
from tekst.models.resource import (
Expand Down Expand Up @@ -331,8 +333,43 @@ class GeneralTextAnnotationResourceConfig(ModelBase):
font: FontConfigType = None


class AnnotationGroupTranslation(TranslationBase):
translation: Annotated[
str,
StringConstraints(
min_length=1,
max_length=32,
strip_whitespace=True,
),
]


class AnnotationGroup(TypedDict):
key: Annotated[
str,
StringConstraints(
min_length=1,
max_length=16,
strip_whitespace=True,
),
]
translations: Annotated[
Translations[AnnotationGroupTranslation],
Field(
description="Translation for the label of an annotation group",
),
] = []


class TextAnnotationResourceConfig(ResourceConfigBase):
general: GeneralTextAnnotationResourceConfig = GeneralTextAnnotationResourceConfig()
annotation_groups: Annotated[
list[AnnotationGroup],
Field(
description="Display groups to use for grouping annotations",
max_length=32,
),
] = []
display_template: Annotated[
str | None,
Field(
Expand All @@ -351,7 +388,11 @@ class TextAnnotationResourceConfig(ResourceConfigBase):
Field(
description="String used to delimit multiple values for an annotation",
),
StringConstraints(min_length=1, max_length=3, strip_whitespace=True),
StringConstraints(
min_length=1,
max_length=3,
strip_whitespace=True,
),
] = "/"


Expand Down
24 changes: 24 additions & 0 deletions Tekst-Web/src/api/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,22 @@ export interface components {
/** Values */
values?: string[] | null;
};
/** AnnotationGroup */
AnnotationGroup: {
/** Key */
key: string;
/**
* Translations
* @description Translation for the label of an annotation group
*/
translations: components['schemas']['AnnotationGroupTranslation'][];
};
/** AnnotationGroupTranslation */
AnnotationGroupTranslation: {
locale: components['schemas']['TranslationLocaleKey'];
/** Translation */
translation: string;
};
/** AudioContentCreate */
AudioContentCreate: {
/**
Expand Down Expand Up @@ -4947,6 +4963,12 @@ export interface components {
* "defaultCollapsed": false
* } */
general: components['schemas']['GeneralTextAnnotationResourceConfig'];
/**
* Annotationgroups
* @description Display groups to use for grouping annotations
* @default []
*/
annotationGroups: components['schemas']['AnnotationGroup'][];
/**
* Displaytemplate
* @description Template string used for displaying the annotations in the web client (if missing, all annotations are displayed with key and value, separated by commas)
Expand Down Expand Up @@ -5049,6 +5071,7 @@ export interface components {
* "general": {
* "defaultCollapsed": false
* },
* "annotationGroups": [],
* "multiValueDelimiter": "/"
* } */
config: components['schemas']['TextAnnotationResourceConfig'];
Expand Down Expand Up @@ -5172,6 +5195,7 @@ export interface components {
* "general": {
* "defaultCollapsed": false
* },
* "annotationGroups": [],
* "multiValueDelimiter": "/"
* } */
config: components['schemas']['TextAnnotationResourceConfig'];
Expand Down
Loading

0 comments on commit 036e552

Please sign in to comment.