Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorcgueret <christophe.gueret@gmail.com>2012-02-27 07:42:28 (GMT)
committer cgueret <christophe.gueret@gmail.com>2012-02-27 07:42:28 (GMT)
commit14e65e3d3b4c366f6b959783f042775ea196040a (patch)
tree21762cde634cd743a61ba3257405b4b6d618561a /common
parent4cb08de9849f155e697bb40cf14d9f7d3d3f1c65 (diff)
Refactored the creation of object entries
Diffstat (limited to 'common')
-rw-r--r--common/src/semanticxo/semanticdatastore.py53
1 files changed, 24 insertions, 29 deletions
diff --git a/common/src/semanticxo/semanticdatastore.py b/common/src/semanticxo/semanticdatastore.py
index 91997fe..d119fe4 100644
--- a/common/src/semanticxo/semanticdatastore.py
+++ b/common/src/semanticxo/semanticdatastore.py
@@ -21,16 +21,17 @@ class SemanticDSEntry(object):
A Semantic DataStore entry is the description of a single resource
'''
- def __init__(self, uid, category, metadata=None):
+ def __init__(self, graph, uid, category, metadata=None):
'''
Constructor
'''
self.resource_uri = OLPC_RESOURCE[uid]
- self.graph = ConjunctiveGraph()
+ self.graph = graph
self.graph.add((self.resource_uri, RDF.type, OLPC_TERMS[category]))
self.graph.add((self.resource_uri, OLPC_TERMS['uid'], uid))
# Process the meta data as RDF triples
+ # TODO move in "parse" method
if metadata != None:
for key, value in metadata.items():
# Hack to support activities that still pass properties named as
@@ -56,12 +57,6 @@ class SemanticDSEntry(object):
'''
return self.resource_uri
- def as_ntriples(self):
- return self.graph.serialize(format='nt')
-
- def as_rdfxml(self):
- return self.graph.serialize()
-
def add_link_to(self, link_name, target):
'''
Create a triple that points to the SemanticDSEntry target
@@ -92,25 +87,34 @@ class SemanticDSObject(object):
return self.graph_iri
def as_ntriples(self):
- graph = ConjunctiveGraph()
- for entry in self.entries.itervalues():
- graph.parse(entry.as_rdfxml())
- graph.parse(self.graph.serialize())
- return graph.serialize(format='nt')
+ return self.graph.serialize(format='nt')
def as_rdfxml(self):
- graph = ConjunctiveGraph()
- for entry in self.entries.itervalues():
- graph.parse(data=entry.as_rdfxml())
- graph.parse(data=self.graph.serialize())
- return graph.serialize()
+ return self.graph.serialize()
def add(self, s, p, o):
+ '''
+ Add a raw triple
+ '''
self.graph.add((s, p, o))
def add_entry(self, entry):
+ '''
+ Add SemanticDSEntry in this object
+ '''
self.entries[entry.get_resource_uri()] = entry
-
+
+ def create_entry(self, uid=None, category=None, metadata=None):
+ '''
+ Return a new object entry to be added to an instance of SemanticDSObject
+ '''
+ if category == None:
+ category = 'GenericEntry'
+ if uid == None:
+ str(uuid.uuid4())
+ entry = SemanticDSEntry(self.graph, uid, category, metadata)
+ return entry
+
class SemanticDS(object):
'''
The Semantic DataStore is an interface to the triple store.
@@ -177,15 +181,6 @@ class SemanticDS(object):
graph_iri = OLPC_GRAPHS[uid]
return SemanticDSObject(graph_iri)
- def create_object_entry(self, uid=None, category=None, metadata=None):
- '''
- Return a new object entry to be added to an instance of SemanticDSObject
- '''
- if category == None:
- category = 'GenericEntry'
- if uid == None:
- str(uuid.uuid4())
- return SemanticDSEntry(uid, category, metadata)
def get_metadata(self, uid, properties=None):
resource_iri = OLPC_RESOURCE[uid]
@@ -197,7 +192,7 @@ class SemanticDS(object):
for result in sparql.query().convert():
if result['p'].startswith(OLPC_TERMS):
key = result['p'].split(OLPC_TERMS)[1]
- if properties==None or key in properties:
+ if properties == None or key in properties:
# TODO type data
metadata[key] = str(result['o'])