Various improvements

This commit is contained in:
Edward Betts 2022-04-08 10:44:39 +01:00
parent 3b9ea473e4
commit e07af0b2a4

View file

@ -396,7 +396,6 @@ def add_isa_filter(q, isa_qids):
) )
subclass_qid = {qid for qid, in q_subclass.all()} subclass_qid = {qid for qid, in q_subclass.all()}
# print(subclass_qid)
isa = func.jsonb_path_query_array( isa = func.jsonb_path_query_array(
model.Item.claims, model.Item.claims,
@ -605,7 +604,11 @@ def find_osm_candidates(item, limit=80, max_distance=450, names=None):
item_id = item.item_id item_id = item.item_id
item_is_linear_feature = item.is_linear_feature() item_is_linear_feature = item.is_linear_feature()
item_is_street = item.is_street() item_is_street = item.is_street()
item_names = {n.lower() for n in item.names().keys()} item_names_dict = item.names()
if item_names_dict:
item_names = {n.lower() for n in item_names_dict.keys()}
else:
item_names = set()
check_is_street_number_first(item.locations[0].get_lat_lon()) check_is_street_number_first(item.locations[0].get_lat_lon())
@ -763,6 +766,11 @@ def check_is_street_number_first(latlng):
g.street_number_first = is_street_number_first(*latlng) g.street_number_first = is_street_number_first(*latlng)
def item_detail(item): def item_detail(item):
unsupported_relation_types = {
'Q194356', # wind farm
'Q2175765', # tram stop
}
locations = [list(i.get_lat_lon()) for i in item.locations] locations = [list(i.get_lat_lon()) for i in item.locations]
if not hasattr(g, 'street_number_first'): if not hasattr(g, 'street_number_first'):
g.street_number_first = is_street_number_first(*locations[0]) g.street_number_first = is_street_number_first(*locations[0])
@ -783,6 +791,11 @@ def item_detail(item):
}) })
isa_items = [get_item(isa["numeric-id"]) for isa in item.get_isa()] isa_items = [get_item(isa["numeric-id"]) for isa in item.get_isa()]
isa_lookup = {isa.qid: isa for isa in isa_items}
wikipedia_links = [{"lang": site[:-4], "title": link["title"]}
for site, link in sorted(item.sitelinks.items())
if site.endswith("wiki") and len(site) < 8]
d = { d = {
"qid": item.qid, "qid": item.qid,
@ -797,11 +810,20 @@ def item_detail(item):
"p1619": item.time_claim("P1619"), "p1619": item.time_claim("P1619"),
"p576": item.time_claim("P576"), "p576": item.time_claim("P576"),
"heritage_designation": heritage_designation, "heritage_designation": heritage_designation,
"wikipedia": wikipedia_links,
} }
if aliases := item.get_aliases(): if aliases := item.get_aliases():
d["aliases"] = aliases d["aliases"] = aliases
if "commonswiki" in item.sitelinks:
d["commons"] = item.sitelinks["commonswiki"]["title"]
unsupported = isa_lookup.keys() & unsupported_relation_types
if unsupported:
d["unsupported_relation_types"] = [isa for isa in d["isa_list"]
if isa.qid in isa_lookup]
return d return d