-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace_registry.py
87 lines (75 loc) · 3.77 KB
/
namespace_registry.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from namespaces import *
from namespace_cello import CelloOntologyNamespace
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class NamespaceRegistry:
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# instanciate local namespaces
cello = CelloOntologyNamespace(); cvcl = OurCellLineNamespace(); xref = OurXrefNamespace()
pub = OurPublicationNamespace(); orga = OurOrganizationNamespace(); db = OurDatabaseAndTerminologyNamespace()
# instanciate other used namespaces
xsd = XsdNamespace(); rdf = RdfNamespace(); rdfs = RdfsNamespace(); owl = OwlNamespace()
skos = SkosNamespace(); foaf = FoafNamespace(); dcterms = DctermsNamespace()
fabio = FabioNamespace(); up = UniProtCoreNamespace()
bibo = BiboNamespace(); widoco = WidocoNamespace()
vann = VannNamespace(); pubmed = PubMedNamespace()
oa = OaNamespace()
# org = W3OrgNamespace()
wdt = WikidataWdtNamespace(); wd = WikidataWdNamespace()
sh = ShaclNamespace();
schema = SchemaOrgNamespace()
#cello = CelloWebsiteNamespace()
help = HelpNamespace()
BAO = BAONamespace(); BTO = BTONamespace(); CLO = CLONamespace()
NCIt = NCItNamespace(); OBI = OBINamespace(); OMIT = OMITNamespace()
FBcv = FBcvNamespace(); OGG = OGGNamespace()
namespaces = [cello, cvcl, xref, pub, orga, db, xsd, rdf, rdfs, skos, owl, foaf, dcterms,
fabio, up, bibo, widoco, vann, oa, wdt, wd, sh, schema, help, pubmed,
BAO, BTO, CLO, NCIt, OBI, OMIT, FBcv , OGG ]
pfx2ns = dict()
for ns in namespaces: pfx2ns[ns.pfx] = ns
def getPrefixedIRI(IRI):
url = IRI
if url.startswith("<"): url = url[1:]
if url.endswith(">"): url = url[:-1]
for ns in NamespaceRegistry.namespaces:
if url.startswith(ns.url):
return ":".join([ns.pfx, url[len(ns.url):]])
return None
def getNamespace(IRI):
url = IRI
if url.startswith("<"): url = url[1:]
if url.endswith(">"): url = url[:-1]
for ns in NamespaceRegistry.namespaces:
if url.startswith(ns.url): return ns
if url.startswith(ns.pfx + ":"): return ns
return None
def describe(subj_prefixed_iri, prop_iri, value):
pfx = subj_prefixed_iri.split(":")[0]
NamespaceRegistry.pfx2ns[pfx].describe(subj_prefixed_iri, prop_iri, value)
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
if __name__ == '__main__':
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
ns = NamespaceRegistry
for space in [ns.up, ns.fabio, ns.dcterms, ns.cello, ns.FBcv]:
for id in space.terms:
term = space.terms[id]
for line in term.ttl_lines():
print(line)
print("----")
ns.up.registerClass("TestClass")
ns.describe("up:TestClass", ns.rdfs.comment, ns.xsd.string("""this is my " real comment"""))
ns.describe("up:TestClass", ns.rdfs.label, ns.xsd.string("Test Class label"))
ns.describe("up:TestClass", ns.skos.broadMatch, "OBI:broader")
ns.describe("up:TestClass", ns.skos.exactMatch, "OBI:exact")
ns.describe("up:TestClass", ns.skos.closeMatch, "OBI:close")
t = ns.up.terms["TestClass"]
print("\n".join(t.ttl_lines()))
print("----")
ns.cello.registerClass("TestClass")
ns.describe("cello:TestClass", ns.rdfs.comment, ns.xsd.string("""this is my " real comment"""))
ns.describe("cello:TestClass", ns.rdfs.label, ns.xsd.string("Test Class label"))
ns.describe("cello:TestClass", ns.skos.broadMatch, "OBI:broader")
ns.describe("cello:TestClass", ns.skos.exactMatch, "OBI:exact")
ns.describe("cello:TestClass", ns.skos.closeMatch, "OBI:close")
t = ns.cello.terms["TestClass"]
print("\n".join(t.ttl_lines()))