Skip to content

Commit

Permalink
rewrite: Add skip option which does nothing and rename one option to …
Browse files Browse the repository at this point in the history
…make it clear you get more information.
  • Loading branch information
dpriskorn committed Aug 7, 2024
1 parent 5da4bcf commit c4a437d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/models/enrich_hiking_trails.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ def __lookup_in_osm_wikidata_link__(trail_item: TrailItem) -> TrailItem:
@staticmethod
def __lookup_in_waymarked_trails__(trail_item: TrailItem) -> None:
trail_item.fetch_and_lookup_from_waymarked_trails_and_present_choice_to_user()
# if trail_item.questionary_return.quit:
# break
if trail_item.questionary_return.could_not_decide:
if trail_item.questionary_return.skip:
# return early
return
if trail_item.questionary_return.more_information:
if not trail_item.item:
raise NoItemError()
console.print(
Expand Down Expand Up @@ -144,6 +145,7 @@ def __iterate_items__(self):
# geometry from Overpass API and checking if
# each of them are in the right
# 1) country 2) region 3) municipality
# or just how near the centeroid of the QID is to the OSM one
self.__lookup_in_waymarked_trails__(trail_item=trail_item)
else:
logger.info(
Expand Down
4 changes: 2 additions & 2 deletions src/models/questionary_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

class QuestionaryReturn(ProjectBaseModel):
osm_id: int = 0
could_not_decide: bool = False
more_information: bool = False
no_match: bool = False
quit: bool = False
skip: bool = False
36 changes: 21 additions & 15 deletions src/models/trail_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ def __parse_not_found_in_osm_last_update_statement__(self):
except KeyError:
logger.info("No 'not found in'-claims on this item")

def __set_no_match__(self):
if not self.item:
raise NoItemError()
console.print(
f"No choices from Waymarked Trials "
f"API = no match for "
f"{self.item.get_entity_url()}"
)
return_ = QuestionaryReturn()
return_.no_match = True
self.questionary_return = return_

def __lookup_label_on_waymarked_trails_and_ask_user_to_choose_a_match__(
self,
) -> None:
Expand All @@ -201,31 +213,25 @@ def __lookup_label_on_waymarked_trails_and_ask_user_to_choose_a_match__(
self.__remove_waymaked_result_duplicates__()
self.__get_details_from_waymarked_trails__()
self.__prepare_choices__()
if len(self.choices) > 2:
# the last 3 choices are not matchable
if len(self.choices) > 3:
self.questionary_return = self.__ask_question__()
else:
if not self.item:
raise NoItemError()
console.print(
f"No choices from Waymarked Trials "
f"API = no match for "
f"{self.item.get_entity_url()}"
)
return_ = QuestionaryReturn()
return_.no_match = True
self.questionary_return = return_
# Assuming no match because we got nothing from WT API
self.__set_no_match__()

def __prepare_choices__(self):
self.__convert_waymarked_results_to_choices__()
self.choices.append(
Choice(
title="Unable to decide whether these match",
value=QuestionaryReturn(could_not_decide=True),
title="Unable to decide whether these match, show me more information",
value=QuestionaryReturn(more_information=True),
)
)
self.choices.append(
Choice(title="None of these match", value=QuestionaryReturn(no_match=True))
)
self.choices.append(Choice(title="Skip", value=QuestionaryReturn(skip=True)))

def __ask_question__(self) -> QuestionaryReturn:
"""This presents a choice and returns"""
Expand Down Expand Up @@ -589,7 +595,7 @@ def __remove_not_found_in_osm_claim__(self) -> None:
logger.debug("No NOT_FOUND_IN found on this item to remove")

def try_matching_again(self):
if self.questionary_return.could_not_decide is True:
if self.questionary_return.more_information is True:
result = questionary.select(
"Do you want to match again after manually ",
choices=[
Expand All @@ -607,7 +613,7 @@ def __verify_P402_claim_exists__(item: ItemEntity) -> bool:
for claim in item.claims:
property_numbers_found.append(claim.mainsnak.property_number)
if claim.mainsnak.property_number == Property.OSM_RELATION_ID.value:
print("P402 found")
logger.debug("P402 found")
found = True
# print(property_numbers_found)
return found

0 comments on commit c4a437d

Please sign in to comment.