Commit 67289414 authored by Konstantin Schulz's avatar Konstantin Schulz

added the Vischer vocabulary; and deep link navigation for the ranking page

parent 57a15c03
Pipeline #14637 passed with stages
in 3 minutes and 14 seconds
......@@ -13,6 +13,7 @@ from mcserver.app.models import FileType, ResourceType, DownloadableFile, MimeTy
from mcserver.app.services import FileService, NetworkService, DatabaseService
from mcserver.config import Config
from mcserver.models_auto import Exercise, UpdateInfo, LearningResult
from openapi.openapi_server.models import FileForm
def clean_tmp_folder():
......@@ -40,9 +41,10 @@ def get(id: str, type: FileType, solution_indices: List[int]) -> Union[ETagRespo
file_name: str = id + "." + str(type)
mime_type: str = MimeType[type].value
if exercise is None:
# try and see if a file is already cached on disk
# there is no exercise in the database; try and see if a file is already cached on disk
if not os.path.exists(os.path.join(Config.TMP_DIRECTORY, file_name)):
return connexion.problem(404, Config.ERROR_TITLE_NOT_FOUND, Config.ERROR_MESSAGE_EXERCISE_NOT_FOUND)
# there is a cached (non-exercise) file on disk, retrieve it and offer for download
return send_from_directory(Config.TMP_DIRECTORY, file_name, mimetype=mime_type, as_attachment=True)
exercise.last_access_time = datetime.utcnow().timestamp()
DatabaseService.commit()
......@@ -59,17 +61,15 @@ def post(file_data: dict) -> Response:
""" The POST method for the File REST API.
It writes learning results or HTML content to the disk for later access. """
lr_string: str = file_data.get("learning_result", None)
if lr_string:
lr_dict: dict = json.loads(lr_string)
ff: FileForm = FileForm.from_dict(file_data)
if ff.learning_result:
lr_dict: dict = json.loads(ff.learning_result)
for exercise_id in lr_dict:
xapi_statement: XapiStatement = XapiStatement(lr_dict[exercise_id])
save_learning_result(xapi_statement)
return NetworkService.make_json_response(str(True))
else:
file_type: FileType = file_data["file_type"]
existing_file: DownloadableFile = FileService.make_tmp_file_from_html(file_data["urn"], file_type,
file_data["html_content"])
existing_file: DownloadableFile = FileService.make_tmp_file_from_html(ff.urn, ff.file_type, ff.html_content)
return NetworkService.make_json_response(existing_file.file_name)
......
......@@ -157,6 +157,7 @@ class VocabularyCorpus(Enum):
agldt = Config.VOCABULARY_AGLDT_FILE_NAME
bws = Config.VOCABULARY_BWS_FILE_NAME
proiel = Config.VOCABULARY_PROIEL_FILE_NAME
vischer = Config.VOCABULARY_VISCHER_FILE_NAME
viva = Config.VOCABULARY_VIVA_FILE_NAME
......
......@@ -202,7 +202,7 @@ class CustomCorpusService:
annotations = CustomCorpusService.get_treebank_sub_annotations(urn, annotations, cc)
# add an artificial punctuation sign at the end of each sentence
for sent in annotations:
sent.metadata["urn"] = ":".join(urn.split(":")[:-1] + [sent.tokens[0]["misc"]["ref"]])
sent.metadata["urn"] = ":".join([cc.corpus.source_urn, sent.tokens[0]["misc"]["ref"]])
if sent.tokens[-1]["form"] != ".":
root_token: OrderedDict = next(x for x in sent.tokens if x[Config.AQL_DEPREL] == "root")
sent.append(OrderedDict(
......
......@@ -83,7 +83,7 @@ class FileService:
def get_vocabulary_set(vocabulary_corpus: VocabularyCorpus, frequency_upper_bound: int) -> Set[str]:
""" Retrieves a set of highly frequent lemmata from a specific vocabulary. """
vocabulary_file_content: str = FileService.get_file_content(
os.path.join(Config.ASSETS_DIRECTORY, vocabulary_corpus.value))
os.path.join(Config.VOCABULARY_DIRECTORY, vocabulary_corpus.value))
vocabulary_list: List[str] = json.loads(vocabulary_file_content)
frequency_upper_bound = frequency_upper_bound if frequency_upper_bound else len(vocabulary_list)
return set(vocabulary_list[:frequency_upper_bound])
......
......@@ -162,7 +162,9 @@ class Config(object):
UDPIPE_PATH_WIN64 = os.path.join(ASSETS_DIRECTORY, "udpipe_win64.exe")
VOCABULARY_AGLDT_FILE_NAME = "vocabulary_ancient_greek_latin_dependency_treebank.json"
VOCABULARY_BWS_FILE_NAME = "vocabulary_bamberg_core.json"
VOCABULARY_DIRECTORY = os.path.join(ASSETS_DIRECTORY, "vocabulary")
VOCABULARY_PROIEL_FILE_NAME = "vocabulary_proiel_treebank.json"
VOCABULARY_VISCHER_FILE_NAME = "vocabulary_vischer.json"
VOCABULARY_VIVA_FILE_NAME = "vocabulary_viva.json"
......
......@@ -203,24 +203,7 @@ paths:
content:
application/x-www-form-urlencoded:
schema:
type: object
description: Data that should be serialized and persisted.
x-body-name: file_data
properties:
file_type:
$ref: '../openapi_models.yaml#/components/schemas/FileType'
html_content:
type: string
description: HTML content to be serialized.
example: <html></html>
learning_result:
type: string
description: Serialized XAPI results for an interactive exercise.
example: "{'0': {}}"
urn:
type: string
description: CTS URN for the text passage from which the HTML content was created.
example: urn:cts:latinLit:phi0448.phi001.perseus-lat2:1.1.1-1.1.1
$ref: '../openapi_models.yaml#/components/schemas/FileForm'
/frequency:
get:
summary: Returns results for a frequency query from ANNIS for a given CTS URN.
......
......@@ -10,11 +10,11 @@ from openapi.openapi_server.models.exercise_extension import ExerciseExtension
from openapi.openapi_server.models.exercise_form import ExerciseForm
from openapi.openapi_server.models.exercise_form_all_of import ExerciseFormAllOf
from openapi.openapi_server.models.exercise_type_path import ExerciseTypePath
from openapi.openapi_server.models.file_form import FileForm
from openapi.openapi_server.models.file_type import FileType
from openapi.openapi_server.models.frequency_item import FrequencyItem
from openapi.openapi_server.models.graph_data import GraphData
from openapi.openapi_server.models.h5_p_form import H5PForm
from openapi.openapi_server.models.inline_object import InlineObject
from openapi.openapi_server.models.kwic_form import KwicForm
from openapi.openapi_server.models.link import Link
from openapi.openapi_server.models.matching_exercise import MatchingExercise
......
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi.openapi_server.models.base_model_ import Model
from openapi.openapi_server.models.file_type import FileType
from openapi.openapi_server import util
from openapi.openapi_server.models.file_type import FileType # noqa: E501
class FileForm(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, file_type=None, html_content=None, learning_result=None, urn=None): # noqa: E501
"""FileForm - a model defined in OpenAPI
:param file_type: The file_type of this FileForm. # noqa: E501
:type file_type: FileType
:param html_content: The html_content of this FileForm. # noqa: E501
:type html_content: str
:param learning_result: The learning_result of this FileForm. # noqa: E501
:type learning_result: str
:param urn: The urn of this FileForm. # noqa: E501
:type urn: str
"""
self.openapi_types = {
'file_type': FileType,
'html_content': str,
'learning_result': str,
'urn': str
}
self.attribute_map = {
'file_type': 'file_type',
'html_content': 'html_content',
'learning_result': 'learning_result',
'urn': 'urn'
}
self._file_type = file_type
self._html_content = html_content
self._learning_result = learning_result
self._urn = urn
@classmethod
def from_dict(cls, dikt) -> 'FileForm':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The FileForm of this FileForm. # noqa: E501
:rtype: FileForm
"""
return util.deserialize_model(dikt, cls)
@property
def file_type(self):
"""Gets the file_type of this FileForm.
:return: The file_type of this FileForm.
:rtype: FileType
"""
return self._file_type
@file_type.setter
def file_type(self, file_type):
"""Sets the file_type of this FileForm.
:param file_type: The file_type of this FileForm.
:type file_type: FileType
"""
self._file_type = file_type
@property
def html_content(self):
"""Gets the html_content of this FileForm.
HTML content to be serialized. # noqa: E501
:return: The html_content of this FileForm.
:rtype: str
"""
return self._html_content
@html_content.setter
def html_content(self, html_content):
"""Sets the html_content of this FileForm.
HTML content to be serialized. # noqa: E501
:param html_content: The html_content of this FileForm.
:type html_content: str
"""
self._html_content = html_content
@property
def learning_result(self):
"""Gets the learning_result of this FileForm.
Serialized XAPI results for an interactive exercise. # noqa: E501
:return: The learning_result of this FileForm.
:rtype: str
"""
return self._learning_result
@learning_result.setter
def learning_result(self, learning_result):
"""Sets the learning_result of this FileForm.
Serialized XAPI results for an interactive exercise. # noqa: E501
:param learning_result: The learning_result of this FileForm.
:type learning_result: str
"""
self._learning_result = learning_result
@property
def urn(self):
"""Gets the urn of this FileForm.
CTS URN for the text passage from which the HTML content was created. # noqa: E501
:return: The urn of this FileForm.
:rtype: str
"""
return self._urn
@urn.setter
def urn(self, urn):
"""Sets the urn of this FileForm.
CTS URN for the text passage from which the HTML content was created. # noqa: E501
:param urn: The urn of this FileForm.
:type urn: str
"""
self._urn = urn
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi.openapi_server.models.base_model_ import Model
from openapi.openapi_server.models.file_type import FileType
from openapi.openapi_server import util
from openapi.openapi_server.models.file_type import FileType # noqa: E501
class FileFormAllOf(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, file_type=None, html_content=None, learning_result=None, urn=None): # noqa: E501
"""FileFormAllOf - a model defined in OpenAPI
:param file_type: The file_type of this FileFormAllOf. # noqa: E501
:type file_type: FileType
:param html_content: The html_content of this FileFormAllOf. # noqa: E501
:type html_content: str
:param learning_result: The learning_result of this FileFormAllOf. # noqa: E501
:type learning_result: str
:param urn: The urn of this FileFormAllOf. # noqa: E501
:type urn: str
"""
self.openapi_types = {
'file_type': FileType,
'html_content': str,
'learning_result': str,
'urn': str
}
self.attribute_map = {
'file_type': 'file_type',
'html_content': 'html_content',
'learning_result': 'learning_result',
'urn': 'urn'
}
self._file_type = file_type
self._html_content = html_content
self._learning_result = learning_result
self._urn = urn
@classmethod
def from_dict(cls, dikt) -> 'FileFormAllOf':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The FileForm_allOf of this FileFormAllOf. # noqa: E501
:rtype: FileFormAllOf
"""
return util.deserialize_model(dikt, cls)
@property
def file_type(self):
"""Gets the file_type of this FileFormAllOf.
:return: The file_type of this FileFormAllOf.
:rtype: FileType
"""
return self._file_type
@file_type.setter
def file_type(self, file_type):
"""Sets the file_type of this FileFormAllOf.
:param file_type: The file_type of this FileFormAllOf.
:type file_type: FileType
"""
self._file_type = file_type
@property
def html_content(self):
"""Gets the html_content of this FileFormAllOf.
HTML content to be serialized. # noqa: E501
:return: The html_content of this FileFormAllOf.
:rtype: str
"""
return self._html_content
@html_content.setter
def html_content(self, html_content):
"""Sets the html_content of this FileFormAllOf.
HTML content to be serialized. # noqa: E501
:param html_content: The html_content of this FileFormAllOf.
:type html_content: str
"""
self._html_content = html_content
@property
def learning_result(self):
"""Gets the learning_result of this FileFormAllOf.
Serialized XAPI results for an interactive exercise. # noqa: E501
:return: The learning_result of this FileFormAllOf.
:rtype: str
"""
return self._learning_result
@learning_result.setter
def learning_result(self, learning_result):
"""Sets the learning_result of this FileFormAllOf.
Serialized XAPI results for an interactive exercise. # noqa: E501
:param learning_result: The learning_result of this FileFormAllOf.
:type learning_result: str
"""
self._learning_result = learning_result
@property
def urn(self):
"""Gets the urn of this FileFormAllOf.
CTS URN for the text passage from which the HTML content was created. # noqa: E501
:return: The urn of this FileFormAllOf.
:rtype: str
"""
return self._urn
@urn.setter
def urn(self, urn):
"""Sets the urn of this FileFormAllOf.
CTS URN for the text passage from which the HTML content was created. # noqa: E501
:param urn: The urn of this FileFormAllOf.
:type urn: str
"""
self._urn = urn
......@@ -21,6 +21,7 @@ class VocabularyMC(Model):
AGLDT = "agldt"
BWS = "bws"
PROIEL = "proiel"
VISCHER = "vischer"
VIVA = "viva"
def __init__(self): # noqa: E501
"""VocabularyMC - a model defined in OpenAPI
......
......@@ -256,29 +256,10 @@ paths:
post:
operationId: mcserver_app_api_file_api_post
requestBody:
$ref: '#/components/requestBodies/inline_object'
content:
application/x-www-form-urlencoded:
schema:
description: Data that should be serialized and persisted.
properties:
file_type:
$ref: '#/components/schemas/FileType'
html_content:
description: HTML content to be serialized.
example: <html></html>
type: string
learning_result:
description: Serialized XAPI results for an interactive exercise.
example: '{''0'': {}}'
type: string
urn:
description: CTS URN for the text passage from which the HTML content
was created.
example: urn:cts:latinLit:phi0448.phi001.perseus-lat2:1.1.1-1.1.1
type: string
type: object
x-body-name: file_data
$ref: '#/components/schemas/FileForm'
required: true
responses:
"200":
......@@ -623,13 +604,6 @@ paths:
vocabulary.
x-openapi-router-controller: openapi_server.controllers.default_controller
components:
requestBodies:
inline_object:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/inline_object'
required: true
schemas:
TextComplexityFormExtension:
allOf:
......@@ -1205,11 +1179,12 @@ components:
type: object
VocabularyMC:
description: 'Reference vocabularies: Ancient Greek and Latin Dependency Treebank,
Bamberger Wortschatz, PROIEL treebank, VIVA textbook'
Bamberger Wortschatz, PROIEL treebank, Vischer vocabulary, VIVA textbook'
enum:
- agldt
- bws
- proiel
- vischer
- viva
example: agldt
type: string
......@@ -1281,6 +1256,26 @@ components:
- zip
example: pdf
type: string
FileForm:
description: Metadata for file content to be saved for later access.
properties:
file_type:
$ref: '#/components/schemas/FileType'
html_content:
description: HTML content to be serialized.
example: <html></html>
type: string
learning_result:
description: Serialized XAPI results for an interactive exercise.
example: '{''0'': {}}'
type: string
urn:
description: CTS URN for the text passage from which the HTML content was
created.
example: urn:cts:latinLit:phi0448.phi001.perseus-lat2:1.1.1-1.1.1
type: string
type: object
x-body-name: file_data
H5PForm:
description: Metadata for the H5P exercise.
properties:
......@@ -1449,26 +1444,6 @@ components:
- urn
type: object
x-body-name: complexity_data
inline_object:
description: Data that should be serialized and persisted.
properties:
file_type:
$ref: '#/components/schemas/FileType'
html_content:
description: HTML content to be serialized.
example: <html></html>
type: string
learning_result:
description: Serialized XAPI results for an interactive exercise.
example: '{''0'': {}}'
type: string
urn:
description: CTS URN for the text passage from which the HTML content was
created.
example: urn:cts:latinLit:phi0448.phi001.perseus-lat2:1.1.1-1.1.1
type: string
type: object
x-body-name: file_data
ExerciseForm_allOf:
description: Additional exercise data.
properties:
......
......@@ -258,6 +258,25 @@ components:
enum: [drag_text, fill_blanks, mark_words, multi_choice, voc_list]
description: Paths to the data directories for various H5P exercise types.
example: drag_text
FileForm:
x-body-name: file_data
description: Metadata for file content to be saved for later access.
type: object
properties:
file_type:
$ref: '#/components/schemas/FileType'
html_content:
type: string
description: HTML content to be serialized.
example: <html></html>
learning_result:
type: string
description: Serialized XAPI results for an interactive exercise.
example: "{'0': {}}"
urn:
type: string
description: CTS URN for the text passage from which the HTML content was created.
example: urn:cts:latinLit:phi0448.phi001.perseus-lat2:1.1.1-1.1.1
FileType:
type: string
enum: [docx, json, pdf, xml, zip]
......@@ -775,9 +794,9 @@ components:
- search_regex