def __top_result__(query_result, type_=None, class_=None):
"""Internal function takes a JSON query results and returns
the top result as a rdflib.URIRef IRI if more than one.
Args:
----
query_result(dict): Query result
"""
if query_result.get("totalResultsCount", 0) > 0:
print(query_result.get("geonames")[0])
top_result = query_result.get("geonames")[0]
geo_id = top_result.get("geonameId")
place_iri = rdflib.URIRef("{}{}/".format(IRI_BASE, geo_id))
if type_ is not None and type_.startswith("rdf"):
output = rdflib.Graph()
rdf_type = rdflib.RDFS.Resource
if class_ is not None:
rdf_type = class_
output.add((place_iri, rdflib.RDF.type, rdf_type))
output.add((place_iri,
rdflib.RDFS.label,
rdflib.Literal(top_result.get("name"))))
return output
return place_iri
评论列表
文章目录