Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.

Commit

Permalink
Merge branch 'prefix-import'
Browse files Browse the repository at this point in the history
  • Loading branch information
bcogrel committed Aug 31, 2014
2 parents 36af273 + 5d7b6cd commit 4af6331
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Here we create an in-memory RDF graph and use it as a SPARQL endpoint (:class:`~
data_graph = Graph()
data_store = SPARQLDataStore(data_graph)

We extract the prefix information from the schema graph::

data_store.extract_prefixes(schema_graph)

Then we instantiate the central object of this framework,
the :class:`~oldman.management.manager.ResourceManager` object.
Expand Down
2 changes: 2 additions & 0 deletions examples/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

data_graph = Graph()
data_store = SPARQLDataStore(data_graph)
# Only for SPARQL data stores
data_store.extract_prefixes(schema_graph)

#Resource manager (will generate the model objects)
manager = ResourceManager(schema_graph, data_store)
Expand Down
1 change: 0 additions & 1 deletion oldman/management/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def __init__(self, schema_graph, data_store, attr_extractor=None,
# Register it
self._data_store.manager = self


@property
def data_store(self):
""":class:`~oldman.store.datastore.DataStore` object. Supports CRUD operations on
Expand Down
8 changes: 8 additions & 0 deletions oldman/store/sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def __init__(self, data_graph, union_graph=None, cache_region=None):
self._data_graph = data_graph
self._union_graph = union_graph if union_graph is not None else data_graph

def extract_prefixes(self, other_graph):
"""Adds the RDF prefix (namespace) information from an other graph
to the namespace of the `data_graph`.
:param other_graph: `rdflib.graph.Graph` that some prefix information.
"""
for prefix, namespace in other_graph.namespace_manager.namespaces():
self._data_graph.bind(prefix, namespace)

def sparql_filter(self, query):
"""Finds the :class:`~oldman.resource.Resource` objects matching a given query.
Expand Down
12 changes: 6 additions & 6 deletions tests/default_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
logging.config.fileConfig(path.join(path.dirname(__file__), 'logging.ini'))



sesame_iri = "http://localhost:8080/openrdf-sesame/repositories/test"
#store = SPARQLUpdateStore(queryEndpoint=sesame_iri, update_endpoint=sesame_iri + "/statements")
#store.setCredentials("paul", "heyjude")
#store = SPARQLUpdateStore(queryEndpoint="http://localhost:3030/test/query",
# update_endpoint="http://localhost:3030/test/update")
store = 'default'
dataset = Dataset(store)
schema_graph = dataset.graph("http://localhost/schema")
data_graph = dataset.graph("http://localhost/data")

#schema_graph = dataset.graph("http://localhost/schema")
schema_graph = Graph()

BIO = "http://purl.org/vocab/bio/0.1/"
REL = "http://purl.org/vocab/relationship/"
Expand Down Expand Up @@ -245,16 +247,14 @@
}
}

dataset.namespace_manager.bind("foaf", FOAF)
dataset.namespace_manager.bind("wot", WOT)
dataset.namespace_manager.bind("rel", REL)
dataset.namespace_manager.bind("cert", CERT)

# Cache
#cache_region = None
cache_region = make_region().configure('dogpile.cache.memory_pickle')

data_store = SPARQLDataStore(data_graph, cache_region=cache_region)
# Takes the prefixes from the schema graph
data_store.extract_prefixes(schema_graph)

manager = ResourceManager(schema_graph, data_store)
# Model classes are generated here!
#lp_name_or_iri = "LocalPerson"
Expand Down

0 comments on commit 4af6331

Please sign in to comment.