summaryrefslogtreecommitdiff
path: root/gstudio/testloop.py
diff options
context:
space:
mode:
authorshefali shetty <sshefali44@gmail.com>2012-05-03 12:01:36 +0530
committershefali shetty <sshefali44@gmail.com>2012-05-03 12:01:36 +0530
commit45fb5f2bdda2bbe5fd6bae887a6dfa230e69bb62 (patch)
tree9f5df1d11055497324f26e948907500fbe338a66 /gstudio/testloop.py
parent850672379e02b758d89ed609e7f8a9c009853104 (diff)
downloadgnowsys-45fb5f2bdda2bbe5fd6bae887a6dfa230e69bb62.tar.gz
a gnowsys-studio/
Diffstat (limited to 'gstudio/testloop.py')
-rw-r--r--gstudio/testloop.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/gstudio/testloop.py b/gstudio/testloop.py
new file mode 100644
index 0000000..8455387
--- /dev/null
+++ b/gstudio/testloop.py
@@ -0,0 +1,59 @@
+import rdflib
+from rdflib.graph import ConjunctiveGraph as Graph
+from rdflib import plugin
+from rdflib.store import Store, NO_STORE, VALID_STORE
+from rdflib.namespace import Namespace
+from rdflib.term import Literal
+from rdflib.term import URIRef
+from tempfile import mkdtemp
+from gstudio.models import *
+
+def rdf_description(name, notation='xml' ):
+ """
+ Funtion takes title of node, and rdf notation.
+ """
+ valid_formats = ["xml", "n3", "ntriples", "trix"]
+ default_graph_uri = "http://gstudio.gnowledge.org/rdfstore"
+ configString = "/var/tmp/rdfstore"
+
+ # Get the Sleepycat plugin.
+ store = plugin.get('IOMemory', Store)('rdfstore')
+
+ # Open previously created store, or create it if it doesn't exist yet
+ graph = Graph(store="IOMemory",
+ identifier = URIRef(default_graph_uri))
+ path = mkdtemp()
+ rt = graph.open(path, create=False)
+ if rt == NO_STORE:
+ #There is no underlying Sleepycat infrastructure, create it
+ graph.open(path, create=True)
+ else:
+ assert rt == VALID_STORE, "The underlying store is corrupt"
+
+
+ # Now we'll add some triples to the graph & commit the changes
+ rdflib = Namespace('http://sbox.gnowledge.org/gstudio/')
+ graph.bind("gstudio", "http://gnowledge.org/")
+ exclusion_fields = ["id", "rght", "node_ptr_id", "image", "lft", "_state", "_altnames_cache", "_tags_cache", "nid_ptr_id", "_mptt_cached_fields"]
+ node=NID.objects.get(title=name)
+ node_dict=node.__dict__
+
+ subject=str(node_dict['id'])
+ for key in node_dict:
+ if key not in exclusion_fields:
+ predicate=str(key)
+ pobject=str(node_dict[predicate])
+ graph.add((rdflib[subject], rdflib[predicate], Literal(pobject)))
+
+
+ graph.commit()
+
+ print graph.serialize(format=notation)
+
+ graph.close()
+i=0
+p=NID.objects.all()
+for each in p:
+ rdf_description(p[i])
+ i=i+1
+