Ejemplo n.º 1
0
def test_search(repo):
    results = LexData.search_lexemes(repo, "first", LexData.language.en,
                                     "Q1084")
    assert len(results) == 1
    assert results[0].get("id") == "L2"

    result = LexData.get_or_create_lexeme(repo, "first", LexData.language.en,
                                          "Q1084")
    assert result["id"] == "L2"
Ejemplo n.º 2
0
# Open a Lexeme
L2 = LexData.Lexeme(repo, "L2")

# Access the claims
print(L2.claims.keys())
# and Forms
print(len(L2.forms))
F1 = L2.forms[0]
print(F1.claims.keys())
# and senses
print(len(L2.senses))
S1 = L2.senses[0]
print(S1.claims.keys())

# Find or create a Lexeme by lemma, language and grammatical form
L2 = LexData.get_or_create_lexeme(repo, "first", lang_en, "Q1084")

# You can easily create forms…
if len(L2.forms) == 0:
    L2.create_form("firsts", ["Q146786"])

# …or senses, with or without additional claims
if len(L2.senses) == 0:
    L2.create_sense(
        {
            "en":
            "Element in an ordered list which comes before all others according to the ordering",
            "de": "einer Ordnung folgend das Element vor allen anderen",
        },
        claims={"P5137": ["Q19269277"]},
    )
Ejemplo n.º 3
0
        repo = LexData.WikidataSession(config.user, config.botpassword)
        # first execute creation of lexemes
        if new_lexeme_count > 0:
            for lexeme in data["new_lexemes"]:
                lemma = lexeme["lemma"]
                forms = lexeme["forms"]
                claims = lexeme["claims"]
                wikimedia_language_code = lexeme["language_code"]
                language_item_id = lexeme["language_item_id"]
                lexical_category = lexeme["lexical_category"]
                console.info(f"Creating {lemma} with {len(forms)} forms and {len(claims)} claims")
                # Find or create a Lexeme by lemma, language and lexical category
                # Configure languages of LexData
                lang = LexData.language.Language(wikimedia_language_code, language_item_id)
                # Try finding it or create a new lexeme
                new_lexeme = LexData.get_or_create_lexeme(repo, lemma, lang, lexical_category)
                pprint(new_lexeme)
                for form in forms:
                    # FIXME only supports 1 representation
                    form_representation: Tuple = form["form_representations"][0] # list of tuples
                    word: str = form_representation[1]
                    grammatical_features = form["grammatical_features"] # list of strings
                    pprint(grammatical_features)
                    result = new_lexeme.createForm(form_representation[1], grammatical_features)
                    pprint(result)

                # lexeme_data = {
                #     'type': 'lexeme',
                #     #'forms': forms,
                #     'lemmas': {lang: {'language': lang, 'value': lemma}},
                #     'language': language_item_id,