[DRAFT] Add all importable RDFLib namespaces and ones needed for EU project#144
[DRAFT] Add all importable RDFLib namespaces and ones needed for EU project#144amy-jenn wants to merge 13 commits intoVisualMeaning:masterfrom
Conversation
There was a problem hiding this comment.
Please make sure there is no type or syntax error. Especially, please ensure that the automatic GitHub verifications are good: they seem to have failed.
Other comments would improve the code and its maintainability. It is not mandatory but the sooner, the better :)
| g.bind('vann', rdflib.namespace.VANN) | ||
| g.bind('void', rdflib.namespace.VOID) | ||
| g.bind('wgs', rdflib.namespace.WGS) | ||
| g.bind('xsd', rdflib.namespace.XSD) |
There was a problem hiding this comment.
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)There was a problem hiding this comment.
Will leave in more explicit solution as is - as discussed
sheet_to_triples/rdf.py
Outdated
| g.bind('patent', rdflib.namespace.('http://data.epo.org/linked-data/def/patent/')) | ||
| g.bind('schema', rdflib.namespace.('http://schema.org/')) | ||
| g.bind('turtle', rdflib.namespace.('http://www.semanticweb.org/owl/owlapi/turtle/')) | ||
| g.bind('xml', rdflib.namespace.('http://www.w3.org/XML/1998/namespace')) |
There was a problem hiding this comment.
For readability, I would introduce a dictionary:
prefix2namespace = {
#custom defined rdflib namespaces
'gist' : 'https://ontologies.semanticarts.com/gist/',
#custom defined rdflib namespaces for eu project
'adms' : 'http://www.w3.org/ns/adms/',
...
}
for prefix, namespace in prefix2namespace.items():
g.bind(prefix, rdflib.Namespace(namespace))The advantage is that it makes the code one step closer to have these namespaces defined in a dedicated JSON file.
Additionally, using loops implies less risks of copy paste errors like the error mentioned below:
There was a problem hiding this comment.
I think I've done this, but partially incorrectly - I need to check this with Achille
sheet_to_triples/rdf.py
Outdated
| #custom defined rdflib namespaces | ||
| g.bind('gist', rdflib.Namespace('https://ontologies.semanticarts.com/gist/')) | ||
| #custom defined rdflib namespaces for eu project | ||
| g.bind('adms', rdflib.namespace.('http://www.w3.org/ns/adms/')) |
There was a problem hiding this comment.
This should fail in many ways:
Cell In[54], line 2
rdflib.namespace.(namespace)
^
SyntaxError: invalid syntaxor
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[52], line 2
1 namespace= 'https://ontologies.semanticarts.com/gist/'
----> 2 rdflib.namespace(namespace)
TypeError: 'module' object is not callableExplanation:
A dot . sneaked between namespace and the parenthesis, leading to a SyntaxError.
Additionally, Namespace with a capital letter is the class constructor, so it's what you want. namespace all in lower case is referring to a module instead, so it triggers a TypeError.
The example you should follow is given line 144:
g.bind('gist', rdflib.Namespace('https://ontologies.semanticarts.com/gist/'))There was a problem hiding this comment.
Additional note: the syntax rdflib.namespace.FOAF is correct because this refers to a stored namespace in the module rdflib.namespace. You can see it as a sort of dictionary. In your case, you want the class constructor rdflib.Namespace because you want to build a new namespace from a string.
There was a problem hiding this comment.
Thanks - I couldn't figure this out - I've addressed this
…d up from other ontologies
|
As discussed, this change is not required - if a specific set of prefixes/bindings are required, simply create a .ttl file with your preferred prefix definitions and add them via |
Jira ticket: SMP-3243
I have no idea what I am doing and this is a best guess make-existing-shape apply to believed new-things - someone needs to review this as though my whole premise and udnerstanding may be flawed.
We need to refer to the following ontologies in the EU project:
In turn, those ontologies refer to the following prefixes:
Further, RDFLib refers to several of the above as "Importable Namespces" - I have tried to link in explanations, but am not sure I have correctly identified everything:
Lastly, the sm_platform makes reference to the following prefixes:
dc: "http://purl.org/dc/elements/1.1/", - included in RDFLib section above
dcat: "http://www.w3.org/ns/dcat#", - included in RDFLib section above
dcterms: "http://purl.org/dc/terms/", - included in RDFLib section above
gist: "https://ontologies.semanticarts.com/gist/", - already included in sheet-to-triples
foaf: "http://xmlns.com/foaf/0.1/", - already included in sheet-to-triples
oa: "http://www.w3.org/ns/oa#", - not included above
org: "http://www.w3.org/ns/org#", - included in RDFLib section above
owl: "http://www.w3.org/2002/07/owl#", - already included in sheet-to-triples
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", - included in RDFLib section above
rdfs: "http://www.w3.org/2000/01/rdf-schema#", - included in RDFLib section above
skos: "http://www.w3.org/2004/02/skos/core#", - included in RDFLib section above
vm: "http://visual-meaning.com/rdf/", - already included in sheet-to-triples
webprotege: "http://webprotege.stanford.edu/", - not included above
These prefixes aren't included in our sheet-to-triples, and I suspect probably should be. I could be wrong here.