Beispiel #1
0
def test_build_lexeme():
    template = {
        'language_item_id':
        'Q1860',
        'language_code':
        'en',
        'lexical_category_item_id':
        'Q1084',
        'forms': [
            {
                'grammatical_features_item_ids': ['Q110786'],
            },
            {
                'grammatical_features_item_ids': ['Q146786'],
            },
        ],
    }
    form_data = werkzeug.datastructures.ImmutableMultiDict([
        ('form_representation', 'noun'), ('form_representation', 'nouns')
    ])
    lexeme_data = lexeme_forms.build_lexeme(template, form_data)
    assert lexeme_data == {
        'type':
        'lexeme',
        'forms': [
            {
                'add': '',
                'representations': {
                    'en': {
                        'language': 'en',
                        'value': 'noun'
                    }
                },
                'grammaticalFeatures': ['Q110786'],
                'claims': {},
            },
            {
                'add': '',
                'representations': {
                    'en': {
                        'language': 'en',
                        'value': 'nouns'
                    }
                },
                'grammaticalFeatures': ['Q146786'],
                'claims': {},
            },
        ],
        'lemmas': {
            'en': {
                'language': 'en',
                'value': 'noun'
            }
        },
        'language':
        'Q1860',
        'lexicalCategory':
        'Q1084',
        'claims': {},
    }
Beispiel #2
0
def test_build_lexeme_blank_form(monkeypatch):
    monkeypatch.setattr(lexeme_forms, 'get_lexeme_data', lambda lexeme_id, wiki: {'language': 'Q1860', 'lexicalCategory': 'Q1084'})
    template = {
        'language_item_id': 'Q1860',
        'language_code': 'en',
        'lexical_category_item_id': 'Q1084',
        'forms': [
            {
                'grammatical_features_item_ids': ['Q110786'],
            },
            {
                'grammatical_features_item_ids': ['Q146786'],
            },
        ],
    }
    form_data = werkzeug.datastructures.ImmutableMultiDict([('lexeme_id', 'L123'), ('form_representation', ''), ('form_representation', 'nouns')])
    lexeme_data = lexeme_forms.build_lexeme(template, form_data)
    assert lexeme_data == {
        'type': 'lexeme',
        'forms': [
            {
                'add': '',
                'representations': {'en': {'language': 'en', 'value': 'nouns'}},
                'grammaticalFeatures': ['Q146786'],
                'claims': {},
            },
        ],
        'id': 'L123',
        'claims': {},
    }
Beispiel #3
0
def test_integration_edit(template_name):
    """Create a lexeme from a template, then match it against the same template.

    If this fails, then there might be a bug when creating or matching lexemes,
    or the template might have ambiguous forms."""
    template = templates[template_name]
    form_data = werkzeug.datastructures.ImmutableMultiDict([
        ('form_representation', str(index))
        for index in range(0, len(template['forms']))
    ])
    lexeme_data = lexeme_forms.build_lexeme(template, form_data)
    matched_template = matching.match_lexeme_forms_to_template(
        lexeme_data['forms'], template)
    assert matched_template.get('ambiguous_lexeme_forms') is None
    assert matched_template.get('unmatched_lexeme_forms') is None
    for index, form in enumerate(matched_template['forms']):
        assert len(form['lexeme_forms']) == 1
        assert form['lexeme_forms'][0]['representations'][
            template['language_code']]['value'] == str(index)
Beispiel #4
0
def test_build_lexeme_with_statements_for_existing_lexeme(monkeypatch):
    p5185 = [{
        'mainsnak': {
            'snaktype': 'value',
            'property': 'P5185',
            'datatype': 'wikibase-item',
            'datavalue': {
                'type': 'wikibase-entityid',
                'value': {
                    'entity-type': 'item',
                    'id': 'Q499327',
                },
            },
        },
        'type': 'statement',
        'rank': 'normal',
    }]
    p31 = [{
        'mainsnak': {
            'snaktype': 'value',
            'property': 'P31',
            'datatype': 'wikibase-item',
            'datavalue': {
                'type': 'wikibase-entityid',
                'value': {
                    'entity-type': 'item',
                    'id': 'Q604984',
                },
            },
        },
        'type': 'statement',
        'rank': 'normal',
    }]
    monkeypatch.setattr(
        lexeme_forms, 'get_lexeme_data', lambda lexeme_id, wiki: {
            'language': 'Q1860',
            'lexicalCategory': 'Q1084',
            'claims': {
                'P5185': p5185,
            },
        })
    template = {
        'language_item_id':
        'Q1860',
        'language_code':
        'en',
        'lexical_category_item_id':
        'Q1084',
        'forms': [
            {
                'grammatical_features_item_ids': ['Q110786'],
                'statements': 'singular test statements',
            },
            {
                'grammatical_features_item_ids': ['Q146786'],
                'statements': 'plural test statements',
            },
        ],
        'statements': {
            'P5185': p5185,
            'P31': p31,
        },
    }
    form_data = werkzeug.datastructures.ImmutableMultiDict([
        ('lexeme_id', 'L123'), ('form_representation', 'noun'),
        ('form_representation', 'nouns')
    ])
    lexeme_data = lexeme_forms.build_lexeme(template, form_data)
    assert lexeme_data == {
        'id':
        'L123',
        'type':
        'lexeme',
        'forms': [
            {
                'add': '',
                'representations': {
                    'en': {
                        'language': 'en',
                        'value': 'noun'
                    }
                },
                'grammaticalFeatures': ['Q110786'],
                'claims': 'singular test statements',
            },
            {
                'add': '',
                'representations': {
                    'en': {
                        'language': 'en',
                        'value': 'nouns'
                    }
                },
                'grammaticalFeatures': ['Q146786'],
                'claims': 'plural test statements',
            },
        ],
        'claims': {
            'P31': p31,
        },
    }