Skip to content
Closed
63 changes: 61 additions & 2 deletions sheet_to_triples/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,44 @@

VM = rdflib.Namespace('http://visual-meaning.com/rdf/')
VMHE = VM['HE/']
PREFIX2NAMESPACE = {
# namespaces already included elsewhere in VM code,
# but that could be directly imported using rdfLib instead
'dc' : 'http://purl.org/dc/elements/1.1/',
'dcat' : 'http://www.w3.org/ns/dcat#',
'dct' : 'http://purl.org/dc/terms/',
'dcterms' : 'http://purl.org/dc/terms/',
'org' : 'http://www.w3.org/ns/org#',
'rdf' : 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs' : 'http://www.w3.org/2000/01/rdf-schema#',
'skos' : 'http://www.w3.org/2004/02/skos/core#',
# custom defined rdflib namespaces
'gist' : 'https://ontologies.semanticarts.com/gist/',
'oa' : 'http://www.w3.org/ns/oa/',
'webprotege' : 'http://webprotege.stanford.edu/',
# custom defined rdflib namespaces for eu project
'adms' : 'http://www.w3.org/ns/adms#',
'adms1' : 'http://purl.org/adms#',
'dc11' : 'http://purl.org/dc/elements/1.1/',
'dg' : 'https://w3id.org/dingo/',
'eccf' : 'http://data.europa.eu/54i/',
'eubud' : 'http://data.europa.eu/3rx/ontology/budget#',
'dctype' : 'http://purl.org/dc/dcmitype/>',
'eurio' : 'http://data.europa.eu/s66#',
'fabio' : 'http://purl.org/spar/fabio/',
'frapo' : 'http://purl.org/cerif/frapo/',
'geo' : 'http://www.w3.org/2003/01/geo/wgs84_pos#',
'gr' : 'http://purl.org/goodrelations/v1#',
'locn' : 'http://www.w3.org/ns/locn/',
'ns0' : 'http://www.w3.org/2003/06/sw-vocab-status/ns#',
'patent' : 'http://data.epo.org/linked-data/def/patent/',
'schema' : 'http://schema.org/',
'turtle' : 'http://www.semanticweb.org/owl/owlapi/turtle#',
'vcard' : 'http://www.w3.org/2006/vcard/ns#',
'wot' : 'http://xmlns.com/wot/0.1/',
'xml' : 'http://www.w3.org/XML/1998/namespace',
}

_ISSUES_PREFIX = VM['issues/']
_USES_MAP_TILES = VM.usesMapTiles

Expand Down Expand Up @@ -112,10 +150,31 @@ def _new_graph():
g = rdflib.Graph()
g.bind('vm', VM)
g.bind('vmhe', VMHE)

# rdflib namespaces available for direct import
g.bind('brick', rdflib.namespace.BRICK)
g.bind('csvw', rdflib.namespace.CSVW)
g.bind('dcmitype', rdflib.namespace.DCMITYPE)
g.bind('dcam', rdflib.namespace.DCAM)
g.bind('doap', rdflib.namespace.DOAP)
g.bind('foaf', rdflib.namespace.FOAF)
g.bind('skos', rdflib.namespace.SKOS)
g.bind('odrl2', rdflib.namespace.ODRL2)
g.bind('owl', rdflib.namespace.OWL)
g.bind('gist', rdflib.Namespace('https://ontologies.semanticarts.com/gist/'))
g.bind('prof', rdflib.namespace.PROF)
g.bind('prov', rdflib.namespace.PROV)
g.bind('qb', rdflib.namespace.QB)
g.bind('sdo', rdflib.namespace.SDO)
g.bind('sh', rdflib.namespace.SH)
g.bind('sosa', rdflib.namespace.SOSA)
g.bind('ssn', rdflib.namespace.SSN)
g.bind('time', rdflib.namespace.TIME)
g.bind('vann', rdflib.namespace.VANN)
g.bind('void', rdflib.namespace.VOID)
g.bind('wgs', rdflib.namespace.WGS)
g.bind('xsd', rdflib.namespace.XSD)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be more synthetic:

import re
import rdflib

for prefix, namespace in rdflib.namespace.__dict__.items(): # This is how you iterate across all the components of a Python module.
    if re.match('[A-Z0-9]+$', prefix):                      # The convention seems to be: namespaces are referred with name in upper case and numbers. 
                                                            # Filtering through type was subject to special cases.
        g.bind(prefix.lower(), namespace)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will leave in more explicit solution as is - as discussed


for prefix, namespace in PREFIX2NAMESPACE.items():
g.bind(prefix, rdflib.Namespace(namespace))
return g


Expand Down