older librdf wanted to include type information when showing query strings.
authorDiane Trout <diane@caltech.edu>
Thu, 27 Sep 2012 18:46:56 +0000 (11:46 -0700)
committerDiane Trout <diane@caltech.edu>
Thu, 27 Sep 2012 18:46:56 +0000 (11:46 -0700)
So I ran everything through fromTypedNode to convert the nodes
to simple python types.

However fromTypedNode wasn't intended to handle non-literal nodes
so I had to adjust it a bit to return resource nodes safely.

htsworkflow/submission/submission.py
htsworkflow/util/rdfhelp.py

index c944b7612d127266ce62c973cda4a54356b0129d..01bdb17228689281b3f33e8aaaaa3af5ccda6d18 100644 (file)
@@ -308,6 +308,9 @@ class Submission(object):
         query = RDF.SPARQLQuery(str(formatted_query))
         rdfstream = query.execute(self.model)
         results = []
-        for r in rdfstream:
-            results.append(r)
+        for record in rdfstream:
+            d = {}
+            for key, value in record.items():
+                d[key] = fromTypedNode(value)
+            results.append(d)
         return results
index 6fa326d576c97d18a6e50d15998e6c866db5d6a2..e5c8718d8906897b86069be8e88baf19bcc2709c 100644 (file)
@@ -119,8 +119,10 @@ def toTypedNode(value):
 def fromTypedNode(node):
     """Convert a typed RDF Node to its closest python equivalent
     """
-    if node is None:
-        return None
+    if not isinstance(node, RDF.Node):
+        return node
+    if node.is_resource():
+        return node
 
     value_type = get_node_type(node)
     literal = node.literal_value['string']