Skip to content

Commit

Permalink
Handling more edge cases in the order function and fixing all the que…
Browse files Browse the repository at this point in the history
…ries order issues
  • Loading branch information
OmarAI2003 committed Nov 9, 2024
1 parent 549d05f commit 98b79c0
Show file tree
Hide file tree
Showing 71 changed files with 1,991 additions and 1,892 deletions.
24 changes: 13 additions & 11 deletions src/scribe_data/check/check_query_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def validate_forms(query_text: str) -> str:

# Check if the order of variables matches, excluding lexeme and lexemeID.
elif select_vars != where_vars:
# print('select vars is ',select_vars, '\n where vars is \n', where_vars)
error_messages.append(
"The order of variables in the SELECT statement does not match their order in the WHERE clause."
)
Expand Down Expand Up @@ -399,22 +400,25 @@ def check_forms_order(query_text):
valid_components = []
temp_component = ""

for component in components:
temp_component += component.lower()
for index, component in enumerate(components):
temp_component += component.capitalize()

# Append valid components in lexeme_form_labels_order.
if temp_component in map(str.lower, lexeme_form_labels_order):
valid_components.append(temp_component)
temp_component = "" # Reset temp component.
if index + 1 != len(components):
if (
temp_component.lower() in map(str.lower, lexeme_form_labels_order)
and temp_component + components[index + 1]
not in lexeme_form_labels_order
):
valid_components.append(temp_component)
temp_component = "" # Reset temp component.
if temp_component:
valid_components.append(temp_component)

split_vars.append(valid_components)

# Create a map for fast component position lookup.
order_map = {
item.lower(): index for index, item in enumerate(lexeme_form_labels_order)
}
order_map = {item: index for index, item in enumerate(lexeme_form_labels_order)}

# Group columns by component length for sorting.
grouped_columns = {}
Expand All @@ -429,9 +433,7 @@ def compare_key(components):
sorted_columns = []
for length in sorted(grouped_columns.keys()):
sorted_group = sorted(grouped_columns[length], key=compare_key)
sorted_columns.extend(
"".join(comp.capitalize() for comp in col) for col in sorted_group
)
sorted_columns.extend("".join(comp for comp in col) for col in sorted_group)

# Append labeling service columns to the end.
sorted_columns.extend(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ SELECT
(REPLACE(STR(?lexeme), "http://www.wikidata.org/entity/", "") AS ?lexemeID)
?adjective
?nominativeFeminineIndefiniteSingular
?nominativeMasculineIndefiniteSingular
?nominativeFeminineIndefiniteDual
?nominativeMasculineIndefiniteDual
?nominativeFeminineIndefinitePlural
?nominativeFeminineIndefiniteDual
?nominativeMasculineIndefiniteSingular
?nominativeMasculineIndefinitePlural
?accusativeFeminineIndefiniteSingular
?accusativeMasculineIndefiniteSingular
?accusativeFeminineIndefiniteDual
?accusativeMasculineIndefiniteDual
?accusativeFeminineIndefinitePlural
?accusativeMasculineIndefinitePlural
?nominativeMasculineIndefiniteDual
?genitiveFeminineIndefiniteSingular
?genitiveMasculineIndefiniteSingular
?genitiveFeminineIndefiniteDual
?genitiveMasculineIndefiniteDual
?genitiveFeminineIndefinitePlural
?genitiveFeminineIndefiniteDual
?genitiveMasculineIndefiniteSingular
?genitiveMasculineIndefinitePlural
?genitiveMasculineIndefiniteDual
?accusativeFeminineIndefiniteSingular
?accusativeFeminineIndefinitePlural
?accusativeFeminineIndefiniteDual
?accusativeMasculineIndefiniteSingular
?accusativeMasculineIndefinitePlural
?accusativeMasculineIndefiniteDual
?pausalFeminineIndefiniteSingular
?pausalMasculineIndefiniteSingular
?pausalFeminineIndefiniteDual
?pausalMasculineIndefiniteDual
?pausalFeminineIndefinitePlural
?pausalFeminineIndefiniteDual
?pausalMasculineIndefiniteSingular
?pausalMasculineIndefinitePlural
?pausalMasculineIndefiniteDual


WHERE {
?lexeme dct:language wd:Q13955 ;
Expand All @@ -37,7 +38,7 @@ WHERE {

# MARK: Nominative

# Singular
# Feminine

OPTIONAL {
?lexeme ontolex:lexicalForm ?nominativeFeminineIndefiniteSingularForm .
Expand All @@ -46,31 +47,24 @@ WHERE {
}

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

# Dual

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

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

# Plural
# Masculine

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

OPTIONAL {
Expand All @@ -79,97 +73,100 @@ WHERE {
wikibase:grammaticalFeature wd:Q499327, wd:Q146786, wd:Q131105, wd:Q53997857 .
}

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

# Singular
# MARK: Genitive

# Feminine

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

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

# Dual

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

# Masculine

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

# Plural

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


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

# MARK: Genitive

# MARK: Accusative

# Singular

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

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

# Dual

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

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

# Plural

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

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


# MARK: Pausal

# Singular
# Feminine

OPTIONAL {
?lexeme ontolex:lexicalForm ?pausalFeminineIndefiniteSingularForm .
Expand All @@ -178,36 +175,36 @@ WHERE {
}

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

# Dual

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

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

# Plural
# Masculine

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

# Dual

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

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

0 comments on commit 98b79c0

Please sign in to comment.