Skip to content

Commit

Permalink
Handle additional edge cases in the check function (e.g., duplicate g…
Browse files Browse the repository at this point in the history
…rammatical features), update error message, and fix queries.
  • Loading branch information
OmarAI2003 committed Nov 14, 2024
1 parent 39815f9 commit 38361b8
Show file tree
Hide file tree
Showing 51 changed files with 405 additions and 403 deletions.
10 changes: 6 additions & 4 deletions src/scribe_data/check/check_query_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,21 +507,23 @@ def check_optional_qid_order(query_file: str) -> str:
"""
forms = extract_forms_from_sparql(query_file)
error_messages = []
statement_index = 0
for form_text in forms:
statement_index += 1
if "ontolex:lexicalForm" in form_text and "ontolex:representation" in form_text:
# Extract the actual QIDs and label for the current form.
actual_qids = extract_form_qids(form_text=form_text)
form_label = extract_form_rep_label(form_text)
label_components = decompose_label_features(form_label)
expected_qids = [qid_label_dict[key] for key in label_components]

# Keep PastParticiple and imperfective QIDs as is in the query since we have duplicate qids for it.
for i in ["Q12717679", "Q1230649", "Q2898727", "Q54556033"]:
if i in actual_qids and i not in expected_qids:
expected_qids[actual_qids.index(i)] = i
# Check if the actual QIDs match the expected order.
if actual_qids != expected_qids:
if len(actual_qids) == len(expected_qids) and actual_qids != expected_qids:
formatted_qids = ", ".join(f"wd:{qid}" for qid in expected_qids) + " ."
error_messages.append(
f"QIDs in optional statement number {statement_index} should be ordered this way: \n {formatted_qids}"
f"\nThe QIDs in optional statement for {form_label} should be ordered:\n{formatted_qids}"
)
return "\n".join(error_messages) if error_messages else ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,81 +46,77 @@ WHERE {
OPTIONAL {
?lexeme ontolex:lexicalForm ?nominativeFeminineIndefiniteSingularForm .
?nominativeFeminineIndefiniteSingularForm ontolex:representation ?nominativeFeminineIndefiniteSingular ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q110786, wd:Q131105, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q131105, wd:Q1775415, wd:Q53997857, wd:Q110786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?nominativeFeminineIndefinitePluralForm .
?nominativeFeminineIndefinitePluralForm ontolex:representation ?nominativeFeminineIndefinitePlural ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q146786, wd:Q131105, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q131105, wd:Q1775415, wd:Q53997857, wd:Q146786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?nominativeFeminineIndefiniteDualForm .
?nominativeFeminineIndefiniteDualForm ontolex:representation ?nominativeFeminineIndefiniteDual ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q110022, wd:Q131105, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q131105, wd:Q1775415, wd:Q53997857, wd:Q110022 .
}

# Masculine

OPTIONAL {
?lexeme ontolex:lexicalForm ?nominativeMasculineIndefiniteSingularForm .
?nominativeMasculineIndefiniteSingularForm ontolex:representation ?nominativeMasculineIndefiniteSingular ;
wikibase:grammaticalFeature wd:Q499327, wd:Q110786, wd:Q131105, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q131105, wd:Q499327, wd:Q53997857, wd:Q110786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?nominativeMasculineIndefinitePluralForm .
?nominativeMasculineIndefinitePluralForm ontolex:representation ?nominativeMasculineIndefinitePlural ;
wikibase:grammaticalFeature wd:Q499327, wd:Q146786, wd:Q131105, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q131105, wd:Q499327, wd:Q53997857, wd:Q146786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?nominativeMasculineIndefiniteDualForm .
?nominativeMasculineIndefiniteDualForm ontolex:representation ?nominativeMasculineIndefiniteDual ;
wikibase:grammaticalFeature wd:Q499327, wd:Q110022, wd:Q131105, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q131105, wd:Q499327, wd:Q53997857, wd:Q110022 .
}

# MARK: Genitive

# Feminine

OPTIONAL {
?lexeme ontolex:lexicalForm ?genitiveFeminineIndefiniteSingularForm .
?genitiveFeminineIndefiniteSingularForm ontolex:representation ?genitiveFeminineIndefiniteSingular ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q110786, wd:Q146233, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146233, wd:Q1775415, wd:Q53997857, wd:Q110786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?genitiveFeminineIndefinitePluralForm .
?genitiveFeminineIndefinitePluralForm ontolex:representation ?genitiveFeminineIndefinitePlural ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q146786, wd:Q146233, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146233, wd:Q1775415, wd:Q53997857, wd:Q146786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?genitiveFeminineIndefiniteDualForm .
?genitiveFeminineIndefiniteDualForm ontolex:representation ?genitiveFeminineIndefiniteDual ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q110022, wd:Q146233, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146233, wd:Q1775415, wd:Q53997857, wd:Q110022 .
}

# Masculine

OPTIONAL {
?lexeme ontolex:lexicalForm ?genitiveMasculineIndefiniteSingularForm .
?genitiveMasculineIndefiniteSingularForm ontolex:representation ?genitiveMasculineIndefiniteSingular ;
wikibase:grammaticalFeature wd:Q499327, wd:Q110786, wd:Q146233, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146233, wd:Q499327, wd:Q53997857, wd:Q110786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?genitiveMasculineIndefinitePluralForm .
?genitiveMasculineIndefinitePluralForm ontolex:representation ?genitiveMasculineIndefinitePlural ;
wikibase:grammaticalFeature wd:Q499327, wd:Q146786, wd:Q146233, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146233, wd:Q499327, wd:Q53997857, wd:Q146786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?genitiveMasculineIndefiniteDualForm .
?genitiveMasculineIndefiniteDualForm ontolex:representation ?genitiveMasculineIndefiniteDual ;
wikibase:grammaticalFeature wd:Q499327, wd:Q110022, wd:Q146233, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146233, wd:Q499327, wd:Q53997857, wd:Q110022 .
}

# MARK: Accusative
Expand All @@ -130,39 +126,39 @@ WHERE {
OPTIONAL {
?lexeme ontolex:lexicalForm ?accusativeFeminineIndefiniteSingularForm .
?accusativeFeminineIndefiniteSingularForm ontolex:representation ?accusativeFeminineIndefiniteSingular ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q110786, wd:Q146078, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146078, wd:Q1775415, wd:Q53997857, wd:Q110786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?accusativeFeminineIndefinitePluralForm .
?accusativeFeminineIndefinitePluralForm ontolex:representation ?accusativeFeminineIndefinitePlural ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q146786, wd:Q146078, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146078, wd:Q1775415, wd:Q53997857, wd:Q146786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?accusativeFeminineIndefiniteDualForm .
?accusativeFeminineIndefiniteDualForm ontolex:representation ?accusativeFeminineIndefiniteDual ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q110022, wd:Q146078, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146078, wd:Q1775415, wd:Q53997857, wd:Q110022 .
}

# Masculine

OPTIONAL {
?lexeme ontolex:lexicalForm ?accusativeMasculineIndefiniteSingularForm .
?accusativeMasculineIndefiniteSingularForm ontolex:representation ?accusativeMasculineIndefiniteSingular ;
wikibase:grammaticalFeature wd:Q499327, wd:Q110786, wd:Q146078, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146078, wd:Q499327, wd:Q53997857, wd:Q110786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?accusativeMasculineIndefinitePluralForm .
?accusativeMasculineIndefinitePluralForm ontolex:representation ?accusativeMasculineIndefinitePlural ;
wikibase:grammaticalFeature wd:Q499327, wd:Q146786, wd:Q146078, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146078, wd:Q499327, wd:Q53997857, wd:Q146786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?accusativeMasculineIndefiniteDualForm .
?accusativeMasculineIndefiniteDualForm ontolex:representation ?accusativeMasculineIndefiniteDual ;
wikibase:grammaticalFeature wd:Q499327, wd:Q110022, wd:Q146078, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q146078, wd:Q499327, wd:Q53997857, wd:Q110022 .
}

# MARK: Pausal
Expand All @@ -172,38 +168,40 @@ WHERE {
OPTIONAL {
?lexeme ontolex:lexicalForm ?pausalFeminineIndefiniteSingularForm .
?pausalFeminineIndefiniteSingularForm ontolex:representation ?pausalFeminineIndefiniteSingular ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q110786, wd:Q117262361, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q117262361, wd:Q1775415, wd:Q53997857, wd:Q110786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?pausalFeminineIndefinitePluralForm .
?pausalFeminineIndefinitePluralForm ontolex:representation ?pausalFeminineIndefinitePlural ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q146786, wd:Q117262361, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q117262361, wd:Q1775415, wd:Q53997857, wd:Q146786 .
}


OPTIONAL {
?lexeme ontolex:lexicalForm ?pausalFeminineIndefiniteDualForm .
?pausalFeminineIndefiniteDualForm ontolex:representation ?pausalFeminineIndefiniteDual ;
wikibase:grammaticalFeature wd:Q1775415, wd:Q110022, wd:Q117262361, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q117262361, wd:Q1775415, wd:Q53997857, wd:Q110022 .
}


# Masculine

OPTIONAL {
?lexeme ontolex:lexicalForm ?pausalMasculineIndefiniteSingularForm .
?pausalMasculineIndefiniteSingularForm ontolex:representation ?pausalMasculineIndefiniteSingular ;
wikibase:grammaticalFeature wd:Q499327, wd:Q110786, wd:Q117262361, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q117262361, wd:Q499327, wd:Q53997857, wd:Q110786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?pausalMasculineIndefinitePluralForm .
?pausalMasculineIndefinitePluralForm ontolex:representation ?pausalMasculineIndefinitePlural ;
wikibase:grammaticalFeature wd:Q499327, wd:Q146786, wd:Q117262361, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q117262361, wd:Q499327, wd:Q53997857, wd:Q146786 .
}

OPTIONAL {
?lexeme ontolex:lexicalForm ?pausalMasculineIndefiniteDualForm .
?pausalMasculineIndefiniteDualForm ontolex:representation ?pausalMasculineIndefiniteDual ;
wikibase:grammaticalFeature wd:Q499327, wd:Q110022, wd:Q117262361, wd:Q53997857 .
wikibase:grammaticalFeature wd:Q117262361, wd:Q499327, wd:Q53997857, wd:Q110022 .
}
}
Loading

0 comments on commit 38361b8

Please sign in to comment.