def test_match_template_to_lexeme_data_different_language():
    template = templates.templates['english-noun']
    match = templates.match_template_to_lexeme_data(
        template, lexeme_data_german_noun_neuter)

    assert not match['language']
    assert match['lexical_category']
Exemplo n.º 2
0
def match_templates_to_lexeme_id(wiki, lexeme_id):
    lexeme_data = get_lexeme_data(lexeme_id, wiki)

    return flask.jsonify({
        template_name: match_template_to_lexeme_data(template, lexeme_data)
        for template_name, template in templates.items()
    })
Exemplo n.º 3
0
def match_template_to_lexeme_id(wiki, lexeme_id, template_name):
    template = templates.get(template_name)
    if not template:
        return 'no such template\n', 404

    lexeme_data = get_lexeme_data(lexeme_id, wiki)

    return flask.jsonify(match_template_to_lexeme_data(template, lexeme_data))
Exemplo n.º 4
0
def build_lexeme(template, form_data):
    lang = template['language_code']
    forms = []
    form_representations = form_data.getlist('form_representation')
    for form_representation, form in zip(form_representations,
                                         template['forms']):
        if not form_representation:
            continue
        for form_representation_variant in form_representation.split('/'):
            if not form_representation_variant:
                flask.abort(400)
            forms.append({
                'add':
                '',
                'representations': {
                    lang: {
                        'language': lang,
                        'value': form_representation_variant
                    }
                },
                'grammaticalFeatures':
                form['grammatical_features_item_ids'],
                'claims':
                form.get('statements', {})
            })
    lexeme_data = {
        'type': 'lexeme',
        'forms': forms,
    }
    lexeme_id = form_data.get('lexeme_id', '')
    if lexeme_id:
        lexeme_data['id'] = lexeme_id
        wiki = 'test' if 'test' in template else 'www'
        match = match_template_to_lexeme_data(template,
                                              get_lexeme_data(lexeme_id, wiki))
        # TODO warn if match['conflicting_statements']?
        lexeme_data['claims'] = match['missing_statements']
    else:
        lemma = get_lemma(form_data)
        if lemma is None:
            flask.abort(400)
        lexeme_data.update({
            'lemmas': {
                lang: {
                    'language': lang,
                    'value': lemma
                }
            },
            'language':
            template['language_item_id'],
            'lexicalCategory':
            template['lexical_category_item_id'],
            'claims':
            template.get('statements', {}),
        })
    return lexeme_data
def test_match_template_to_lexeme_data_conflicting_statement():
    template = templates.templates['german-noun-masculine']
    match = templates.match_template_to_lexeme_data(
        template, lexeme_data_german_noun_neuter)

    assert match == {
        'language': True,
        'lexical_category': True,
        'matched_statements': {},
        'missing_statements': template['statements'],
        'conflicting_statements': lexeme_data_german_noun_neuter['claims'],
    }