diff --git a/fda-units-service/list.py b/fda-units-service/list.py index 12c20b5d0326a22ac04cd863da34782d1366e1db..889da99214820deef9bda67ae9bd6884db02dec9 100644 --- a/fda-units-service/list.py +++ b/fda-units-service/list.py @@ -15,8 +15,10 @@ g.parse('onto/om-2.ttl', format='turtle') om = rdflib.Namespace('http://www.ontology-of-units-of-measure.org/resource/om-2/') rdf_schema = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#') -def list_units(string): - if bool(re.match('^[a-zA-Z0-9]+$',string)): +r={} + +def list_units(string,offset=0): + if bool(re.match('^[a-zA-Z0-9]+$',string)): l_query = """ SELECT ?symbol ?name ?comment WHERE { @@ -24,9 +26,26 @@ def list_units(string): ?unit <http://www.w3.org/2000/01/rdf-schema#label> ?name . ?unit <http://www.w3.org/2000/01/rdf-schema#comment> ?comment . FILTER regex(str(?unit),\""""+string+"""\","i") - } LIMIT 10 """ + } LIMIT 10 OFFSET """+str(offset) qres = g.query(l_query) + units = list() + for row in qres: + units.append({"symbol": str(row.symbol), "name": str(row.name), "comment": str(row.comment)}) + return units + else: + return None + +def get_uri(name): + if bool(re.match('^[a-zA-Z0-9]+$',name)): + uri_query = """ + SELECT ?uri + WHERE { + ?uri <http://www.w3.org/2000/01/rdf-schema#label> ?o . + FILTER (str(?o)=\""""+name+"""\") + } LIMIT 1 + """ + qres = g.query(uri_query) for row in qres: - print(f"{row.symbol} | {row.name} | {row.comment}") - else: - return 'not alphanumeric' \ No newline at end of file + return {"URI": row.uri} + else: + return None \ No newline at end of file diff --git a/fda-units-service/requirements.txt b/fda-units-service/requirements.txt index ae9776238a804662273fdbf5c63b2a03f2bb2697..f02b36dbab54b8a979ba54f0f743ef52ea0ea952 100644 --- a/fda-units-service/requirements.txt +++ b/fda-units-service/requirements.txt @@ -3,4 +3,4 @@ flasgger==0.9.5 py-eureka-client==0.9.1 docker==5.0.0 gevent==21.8.0 -rdflib==6.0.1 +rdflib==6.0.2