{ "property": "cert:key" }, { "property": "wot:hasKey" }, { "property": "schema:employee" }, { "property": "schema:employee", "hydra:reversed": True } ] } parse_graph_safely(schema_graph, data=json.dumps(local_person_def), format="json-ld") local_rsa_key_def = { "@context": [ { "myvoc": MY_VOC, "rdfs": RDFS, "cert": CERT }, #"http://www.w3.org/ns/hydra/core" json.load(open(path.join(path.dirname(__file__), "hydra_core.jsonld")))["@context"] ], "@id": "myvoc:LocalRSAPublicKey", "@type": "hydra:Class", "subClassOf": "cert:RSAPublicKey", "supportedProperty": [
] . ex:ParentClass a hydra:Class ; rdfs:subClassOf ex:GrandParentClass ; hydra:supportedProperty [ hydra:property ex:mediumProperty ] . ex:ChildClass a hydra:Class ; rdfs:subClassOf ex:ParentClass, ex:GrandParentClass ; hydra:supportedProperty [ hydra:property ex:newProperty ] . """ % format(EXAMPLE) parse_graph_safely(schema_graph, data=schema_ttl, format="turtle") context = { "@context": { "ex": EXAMPLE, "xsd": "http://www.w3.org/2001/XMLSchema#", "id": "@id", "type": "@type", "ChildClass": "ex:ChildClass", "ParentClass": "ex:ParentClass", "GrandParentClass": "ex:GrandParentClass", "old_number_value": { "@id": "ex:oldProperty", "@type": "xsd:int" }, "mid_values": {
}, { "property": "rel:parentOf", "hydra:reversed": True }, { "property": "cert:key" }, { "property": "wot:hasKey" }, { "property": "schema:employee" }, { "property": "schema:employee", "hydra:reversed": True }] } parse_graph_safely(schema_graph, data=json.dumps(local_person_def), format="json-ld") local_rsa_key_def = { "@context": [ { "myvoc": MY_VOC, "rdfs": RDFS, "cert": CERT }, #"http://www.w3.org/ns/hydra/core" json.load(open(path.join(path.dirname(__file__), "hydra_core.jsonld"))) ["@context"] ], "@id": "myvoc:LocalRSAPublicKey",
json.load(open(path.join(path.dirname(__file__), "hydra_core.jsonld"))) ["@context"] ], "@id": "ex:BadClass", "@type": "hydra:Class", "supportedProperty": [{ "property": "ex:badProperty", "readonly": True, "writeonly": True }] } parse_graph_safely(schema_graph, data=json.dumps(local_class_def), format="json-ld") parse_graph_safely(schema_graph, data=json.dumps(bad_class_def), format="json-ld") context = { "@context": { "ex": EXAMPLE, "xsd": "http://www.w3.org/2001/XMLSchema#", "id": "@id", "types": "@type", "LocalClass": "ex:LocalClass", "BadClass": "ex:BadClass", "required_property": { "@id": "ex:requiredProperty",
}, #"http://www.w3.org/ns/hydra/core" json.load(open(path.join(path.dirname(__file__), "hydra_core.jsonld")))["@context"] ], "@id": "ex:BadClass", "@type": "hydra:Class", "supportedProperty": [ { "property": "ex:badProperty", "readonly": True, "writeonly": True } ] } parse_graph_safely(schema_graph, data=json.dumps(local_class_def), format="json-ld") parse_graph_safely(schema_graph, data=json.dumps(bad_class_def), format="json-ld") context = { "@context": { "ex": EXAMPLE, "xsd": "http://www.w3.org/2001/XMLSchema#", "id": "@id", "types": "@type", "LocalClass": "ex:LocalClass", "BadClass": "ex:BadClass", "required_property": { "@id": "ex:requiredProperty", "@type": "xsd:string" },
from rdflib import Graph from oldman import ClientResourceManager, parse_graph_safely, SPARQLDataStore # In-memory store store = "default" # from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore # store = SPARQLUpdateStore(queryEndpoint="http://localhost:3030/test/query", # update_endpoint="http://localhost:3030/test/update") # Graph containing all the schema RDF triples schema_graph = Graph(store) # Load the schema schema_url = "https://raw.githubusercontent.com/oldm/OldMan/master/examples/quickstart_schema.ttl" parse_graph_safely(schema_graph, schema_url, format="turtle") ctx_iri = "https://raw.githubusercontent.com/oldm/OldMan/master/examples/quickstart_context.jsonld" data_graph = Graph() data_store = SPARQLDataStore(data_graph, schema_graph=schema_graph) # Only for SPARQL data stores data_store.extract_prefixes(schema_graph) # LocalPerson model data_store.create_model( "LocalPerson", ctx_iri, iri_prefix="http://localhost/persons/", iri_fragment="me", incremental_iri=True ) # Client resource manager client_manager = ClientResourceManager(data_store)
from rdflib import Graph from oldman import ClientResourceManager, parse_graph_safely, SPARQLDataStore # In-memory store store = "default" # from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore # store = SPARQLUpdateStore(queryEndpoint="http://localhost:3030/test/query", # update_endpoint="http://localhost:3030/test/update") # Graph containing all the schema RDF triples schema_graph = Graph(store) # Load the schema schema_url = "https://raw.githubusercontent.com/oldm/OldMan/master/examples/quickstart_schema.ttl" parse_graph_safely(schema_graph, schema_url, format="turtle") ctx_iri = "https://raw.githubusercontent.com/oldm/OldMan/master/examples/quickstart_context.jsonld" data_graph = Graph() data_store = SPARQLDataStore(data_graph, schema_graph=schema_graph) # Only for SPARQL data stores data_store.extract_prefixes(schema_graph) #LocalPerson model data_store.create_model("LocalPerson", ctx_iri, iri_prefix="http://localhost/persons/", iri_fragment="me", incremental_iri=True) #Client resource manager client_manager = ClientResourceManager(data_store) client_manager.import_store_models()
from rdflib import Graph from oldman import SPARQLDataStore, ClientResourceManager, parse_graph_safely from oldman.rest.controller import HTTPController from os import path import unittest schema_graph = Graph() schema_file = path.join(path.dirname(__file__), "controller-schema.ttl") schema_graph = parse_graph_safely(schema_graph, schema_file, format="turtle") context_file = "file://" + path.join(path.dirname(__file__), "controller-context.jsonld") data_graph = Graph() data_store = SPARQLDataStore(data_graph, schema_graph=schema_graph) data_store.create_model("Collection", context_file, iri_prefix="http://localhost/collections/", incremental_iri=True) data_store.create_model("Item", context_file, iri_prefix="http://localhost/items/", incremental_iri=True) client_manager = ClientResourceManager(data_store) client_manager.import_store_models() collection_model = client_manager.get_model("Collection") item_model = client_manager.get_model("Item") collection1 = collection_model.create() controller = HTTPController(client_manager) class ControllerTest(unittest.TestCase):
from os import path from unittest import TestCase from rdflib import Graph from oldman import HttpDataStore, ClientResourceManager, parse_graph_safely directory = path.dirname(__file__) schema_graph = parse_graph_safely(Graph(), path.join(directory, 'api_schema.ttl'), format="turtle") schema_graph.namespace_manager.bind("hydra", "http://www.w3.org/ns/hydra/core#") context_uri = path.join(directory, 'api_documentation.json') data_store = HttpDataStore(schema_graph=schema_graph) data_store.create_model('ApiDocumentation', context_uri) manager = ClientResourceManager(data_store) manager.import_store_models() doc_model = manager.get_model('ApiDocumentation') class HttpStoreTest(TestCase): def test_get(self): iri = u"http://www.markus-lanthaler.com/hydra/api-demo/vocab" doc = doc_model.get(iri) self.assertTrue(doc is not None) self.assertEquals(doc.id, iri) expected_classes = {u'http://www.markus-lanthaler.com/hydra/api-demo/vocab#User', u'http://www.w3.org/ns/hydra/core#Collection', u'http://www.w3.org/ns/hydra/core#Resource', u'http://www.markus-lanthaler.com/hydra/api-demo/vocab#Comment', u'http://www.markus-lanthaler.com/hydra/api-demo/vocab#EntryPoint',
from rdflib import Graph from oldman import SPARQLDataStore, ClientResourceManager, parse_graph_safely from oldman.rest.controller import HTTPController from os import path import unittest schema_graph = Graph() schema_file = path.join(path.dirname(__file__), "controller-schema.ttl") schema_graph = parse_graph_safely(schema_graph, schema_file, format="turtle") context_file = "file://" + path.join(path.dirname(__file__), "controller-context.jsonld") data_graph = Graph() data_store = SPARQLDataStore(data_graph, schema_graph=schema_graph) data_store.create_model("Collection", context_file, iri_prefix="http://localhost/collections/", incremental_iri=True) data_store.create_model("Item", context_file, iri_prefix="http://localhost/items/", incremental_iri=True) client_manager = ClientResourceManager(data_store) client_manager.import_store_models() collection_model = client_manager.get_model("Collection") item_model = client_manager.get_model("Item")