예제 #1
0
def get(urn: str) -> Union[Response, ConnexionResponse]:
    """Provides the raw text for a requested text passage."""
    ar: AnnisResponse = CorpusService.get_corpus(cts_urn=urn, is_csm=False)
    if not ar.graph_data.nodes:
        return connexion.problem(404, Config.ERROR_TITLE_NOT_FOUND,
                                 Config.ERROR_MESSAGE_CORPUS_NOT_FOUND)
    ar.text_complexity = TextComplexityService.text_complexity(
        TextComplexityMeasure.all.name, urn, False, ar.graph_data).to_dict()
    return NetworkService.make_json_response(ar.to_dict())
예제 #2
0
 def get(self):
     """ Returns graph data for a given CTS URN. """
     # get request arguments
     args: Dict = flask.request.args
     cts_urn: str = args["urn"]
     ar: AnnisResponse = CorpusService.get_corpus(cts_urn=cts_urn,
                                                  is_csm=True)
     if not ar.graph_data.nodes:
         abort(404)
     return NetworkService.make_json_response(ar.to_dict())
예제 #3
0
def get(frequency_upper_bound: int, query_urn: str, vocabulary: str) -> Response:
    """ Retrieves sentence ID and matching degree for each sentence in the query text. """
    vc: VocabularyCorpus = VocabularyCorpus[vocabulary]
    vocabulary_set: Set[str] = FileService.get_vocabulary_set(vc, frequency_upper_bound)
    # punctuation should count as a match because we don't want to count this as part of the vocabulary
    for char in string.punctuation:
        vocabulary_set.add(char)
    ar: AnnisResponse = CorpusService.get_corpus(cts_urn=query_urn, is_csm=False)
    sentences: List[Sentence] = check_vocabulary(ar.graph_data, vocabulary_set)
    return NetworkService.make_json_response([x.to_dict() for x in sentences])
예제 #4
0
def post(vocabulary_data: dict):
    """ Indicates for each token of a corpus whether it is covered by a reference vocabulary. """
    vf: VocabularyForm = VocabularyForm.from_dict(vocabulary_data)
    vc: VocabularyCorpus = VocabularyCorpus[vf.vocabulary]
    vocabulary_set: Set[str] = FileService.get_vocabulary_set(vc, vf.frequency_upper_bound)
    # punctuation should count as a match because we don't want to count this as part of the vocabulary
    for char in string.punctuation:
        vocabulary_set.add(char)
    ar: AnnisResponse = CorpusService.get_corpus(cts_urn=vf.query_urn, is_csm=False)
    for node in ar.graph_data.nodes:
        if not is_match(target_lemma=node.udep_lemma, vocabulary_set=vocabulary_set):
            node.is_oov = True
    ar: AnnisResponse = AnnisResponse(
        solutions=[], uri="", exercise_id="", graph_data=ar.graph_data)
    ar.text_complexity = TextComplexityService.text_complexity(
        TextComplexityMeasure.all.name, vf.query_urn, False, ar.graph_data).to_dict()
    return NetworkService.make_json_response(ar.to_dict())
예제 #5
0
def get(eid: str) -> Union[Response, ConnexionResponse]:
    exercise: TExercise = DatabaseService.query(Exercise,
                                                filter_by=dict(eid=eid),
                                                first=True)
    if not exercise:
        return connexion.problem(404, Config.ERROR_TITLE_NOT_FOUND,
                                 Config.ERROR_MESSAGE_EXERCISE_NOT_FOUND)
    ar: AnnisResponse = CorpusService.get_corpus(cts_urn=exercise.urn,
                                                 is_csm=False)
    if not ar.graph_data.nodes:
        return connexion.problem(404, Config.ERROR_TITLE_NOT_FOUND,
                                 Config.ERROR_MESSAGE_CORPUS_NOT_FOUND)
    exercise.last_access_time = datetime.utcnow().timestamp()
    DatabaseService.commit()
    exercise_type: ExerciseType = ExerciseType(exercise.exercise_type)
    ar.solutions = json.loads(exercise.solutions)
    ar.uri = NetworkService.get_exercise_uri(exercise)
    ar.exercise_id = exercise.eid
    ar.exercise_type = exercise_type.value
    return NetworkService.make_json_response(ar.to_dict())
예제 #6
0
 def update_exercises(is_csm: bool) -> None:
     """Deletes old exercises."""
     if DatabaseService.has_table(Config.DATABASE_TABLE_EXERCISE):
         exercises: List[Exercise] = DatabaseService.query(Exercise)
         now: datetime = datetime.utcnow()
         for exercise in exercises:
             exercise_datetime: datetime = datetime.fromtimestamp(
                 exercise.last_access_time)
             # delete exercises that have not been accessed for a while, are not compatible anymore, or contain
             # corrupted / empty data
             if (now - exercise_datetime).total_seconds() > Config.INTERVAL_EXERCISE_DELETE or \
                     not exercise.urn or not json.loads(exercise.solutions):
                 db.session.delete(exercise)
                 DatabaseService.commit()
             # manually add text complexity measures for old exercises
             elif not exercise.text_complexity:
                 ar: AnnisResponse = CorpusService.get_corpus(exercise.urn,
                                                              is_csm=is_csm)
                 tc: TextComplexity = TextComplexityService.text_complexity(
                     TextComplexityMeasure.all.name, exercise.urn, is_csm,
                     ar.graph_data)
                 exercise.text_complexity = tc.all
                 DatabaseService.commit()
예제 #7
0
def get(measure: str, urn: str):
    """Gives users measures of text complexity for a given text."""
    ar: AnnisResponse = CorpusService.get_corpus(urn, is_csm=False)
    tc: TextComplexity = TextComplexityService.text_complexity(
        measure, urn, False, ar.graph_data)
    return NetworkService.make_json_response(tc.to_dict())