From 3c55b0e9b88b5f41713f1c14211adbbbd886f459 Mon Sep 17 00:00:00 2001
From: Cornelia Michlits <cornelia.michlits@tuwien.ac.at>
Date: Sun, 5 Dec 2021 18:12:35 +0100
Subject: [PATCH] 104 ontology - adjust rdflib version

---
 fda-units-service/list.py          | 31 ++++++++++++++++++++++++------
 fda-units-service/requirements.txt |  2 +-
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/fda-units-service/list.py b/fda-units-service/list.py
index 12c20b5d03..889da99214 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 ae9776238a..f02b36dbab 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
-- 
GitLab