Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChristophe Gueret <christophe.gueret@gmail.com>2012-10-02 09:42:59 (GMT)
committer Christophe Gueret <christophe.gueret@gmail.com>2012-10-02 09:42:59 (GMT)
commitbadcc1af9fbc0fb16ff1c77590a12cc7f29ddd0a (patch)
tree49c7d87f72a1be8af94a032546040c001ae0070f /common
parent0b6b4e7f9ec75026691f5aaed7b3aef0f53a2003 (diff)
Updated install bundle
Diffstat (limited to 'common')
-rw-r--r--common/src/semanticxo/graphstore.py8
-rw-r--r--common/src/semanticxo/namespace.py12
-rw-r--r--common/src/semanticxo/replicationservice.py32
3 files changed, 29 insertions, 23 deletions
diff --git a/common/src/semanticxo/graphstore.py b/common/src/semanticxo/graphstore.py
index 59c902b..464132f 100644
--- a/common/src/semanticxo/graphstore.py
+++ b/common/src/semanticxo/graphstore.py
@@ -64,15 +64,15 @@ class GSResource(object):
'''
Get the type of the resource
'''
- (_,_,o) = self._graph.triples((self._resource_uri, RDF.type, None))[0]
- return o
+ for (_,_,o) in self._graph.triples((self._resource_uri, RDF.type, None)):
+ return o
def get_uid(self):
'''
Return the UID
'''
- (_,_,o) = self._graph.triples((self._resource_uri, OLPC_TERMS['uid'], None))[0]
- return o
+ for (_,_,o) in self._graph.triples((self._resource_uri, OLPC_TERMS['uid'], None)):
+ return o
def get(self, prop):
'''
diff --git a/common/src/semanticxo/namespace.py b/common/src/semanticxo/namespace.py
index eb03387..abd548f 100644
--- a/common/src/semanticxo/namespace.py
+++ b/common/src/semanticxo/namespace.py
@@ -5,9 +5,13 @@ Created on 16 Sep 2012
'''
from rdflib.namespace import Namespace
-OLPC = Namespace("http://example.org/")
-OLPC_TERMS = Namespace("http://example.org/terms#")
-OLPC_RESOURCE = Namespace("http://example.org/resource/")
-OLPC_GRAPHS = Namespace("http://example.org/graphs/")
+# The base host name for everything
+OLPC = Namespace("http://semanticxo.appspot.com")
+# Vocabulary terms, resources and graphs
+OLPC_TERMS = Namespace(OLPC + "/terms#")
+OLPC_RESOURCE = Namespace(OLPC + "/resource/")
+OLPC_GRAPHS = Namespace(OLPC + "/graphs/")
+
+# Dublin Core
DC_TERMS = Namespace("http://purl.org/dc/terms/")
diff --git a/common/src/semanticxo/replicationservice.py b/common/src/semanticxo/replicationservice.py
index 158bc68..07e0f2e 100644
--- a/common/src/semanticxo/replicationservice.py
+++ b/common/src/semanticxo/replicationservice.py
@@ -13,8 +13,9 @@ from socket import gethostname
from semanticxo import util, graphstore
from SPARQLWrapper import SPARQLWrapper, Wrapper
from semanticxo.graphstore import GraphStore
+from semanticxo.namespace import DC_TERMS, OLPC_TERMS
-__all__ = ["PublicationService", "AddressBook"]
+__all__ = ["PublicationService", "AddressBook", "GraphReplicator"]
TYPE = "_sparql._tcp"
class PublicationService:
@@ -149,18 +150,17 @@ class GraphReplicator(object):
# Get the list of graphs to sync and their modification date
graphs = {}
- query_string = """
- SELECT DISTINCT ?graph ?date WHERE {
- ?graph a <http://example.org/terms#DataGraph> .
- ?graph <http://purl.org/dc/terms/modified> ?date .
- ?graph <http://example.org/terms#shared_with> ?v.
- FILTER (
- ?v = <http://example.org/resource/public>
- ||
- ?v = <%s>
- )
- }
- """ % util.device_uri()
+ query_string = ""
+ query_string +="SELECT DISTINCT ?graph ?date WHERE {"
+ query_string +="?graph a <%s> ." % OLPC_TERMS['DataGraph']
+ query_string +="?graph <%s> ?date ." % DC_TERMS['modified']
+ query_string +="?graph <%s> ?share." % OLPC_TERMS['shared_with']
+ query_string +="FILTER ("
+ query_string +="?share = <%s>" % util.public_uri()
+ query_string +="||"
+ query_string +="?share = <%s>" % util.device_uri()
+ query_string +=")"
+ query_string +="}"
print query_string
sparql = SPARQLWrapper("http://%s/sparql" % ip)
sparql.setReturnFormat(Wrapper.JSON)
@@ -170,10 +170,12 @@ class GraphReplicator(object):
graphs[result['graph']['value']] = result['date']['value']
print result
+ # Iterate over all the graphs, copy locally those that are not already
+ # stored or for which there is a new version
for (iri,date) in graphs.iteritems():
print date
- data_graph = remote_graph_store.get_object(iri)
- local_graph_store.persist_object(data_graph)
+ data_graph = remote_graph_store.get_graph(iri)
+ local_graph_store.persist_graph(data_graph)
self._lock = 0