summaryrefslogtreecommitdiff
path: root/schema/surf-test.py
blob: 0f0fab872f98a020d8521df2d6b76080de35dbae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Test of various things you can do with an RDF schema for definitions.
# Using SurfRDF: https://github.com/cosminbasca/surfrdf


import rdflib
import surf
import yaml

import os
import warnings

import parse


DATABASE = 'memory'
#DATABASE = 'virtuoso'


surf.ns.register(baserock='http://baserock.org/definitions/example-schema#')


if DATABASE == 'memory':
    # For testing
    store = surf.Store(reader='rdflib', writer='rdflib', rdflib_store='IOMemory')

elif DATABASE == 'virtuoso':
    # For importing into Virtuoso database
    # See: https://pythonhosted.org/SuRF/integration/virtuoso.html
    # Note that you need to work around a bug in Virtuoso in order to
    # use this. See https://github.com/RDFLib/rdflib/issues/298 for more
    # info. Virtuoso expects the url parameter in the SPARQL update
    # request to be called 'query' rather than 'update'. You can change
    # this on line 488 of SPARQLWrapper/Wrapper.py of
    # <https://github.com/RDFLib/sparqlwrapper/> as a nasty workaround.
    store = surf.Store(reader='sparql_protocol',
                       writer='sparql_protocol',
                       endpoint='http://localhost:8890/sparql',
                       default_context='http://example.com')


session = surf.Session(store)

parse.load_all_morphologies(session, store)

Cluster = session.get_class(surf.ns.BASEROCK.Cluster)
cluster = Cluster.all()
for s in cluster:
    s.load()
    # hack
    text = s.serialize('json')
    import json
    data = json.loads(text)
    print json.dumps(data, indent=4)
    break