Author: whit
Date: 2007-07-25 14:34:06 -0400 (Wed, 25 Jul 2007)
New Revision: 7713

Modified:
   TaggerStore/trunk/taggerstore/rdf.py
Log:
add function for returning a single entry id for a single uri


Modified: TaggerStore/trunk/taggerstore/rdf.py
===================================================================
--- TaggerStore/trunk/taggerstore/rdf.py        2007-07-25 18:32:57 UTC (rev 
7712)
+++ TaggerStore/trunk/taggerstore/rdf.py        2007-07-25 18:34:06 UTC (rev 
7713)
@@ -249,6 +249,27 @@
 }
 """.strip()
 
+
+def entryid_for_link(graph, uri):
+    query = """
+    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+    PREFIX annotea: <http://www.w3.org/2000/10/annotation-ns#>
+    PREFIX atom: <http://www.w3.org/2005/Atom/>
+    
+    SELECT DISTINCT ?entry_id
+    WHERE {
+         ?annotation annotea:annotates <%s> .
+         ?annotation annotea:related ?entry_uri .      
+         ?entry_uri rdf:type atom:entry .
+         ?entry_uri rdf:ID ?entry_id .
+    }""" %uri
+    result = graph.query(query).serialize(format='entryid_list')
+    if result:
+        assert len(result) == 1
+        return result[0]
+
+
 def make_q(patterns, template=template_query):
     """
     allows a set of filter, optional or exact match statement to be



--
Archive: 
http://www.openplans.org/projects/opencore/lists/openplans-svn/archive/2007/07/1185388447170
To unsubscribe send an email with subject unsubscribe to [EMAIL PROTECTED]  
Please contact [EMAIL PROTECTED] for questions.

Reply via email to