From a15f56943cab50e705f162ee551a250fd1b7a45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20B=2E=20D=C3=B8rm=C3=A6nen?= Date: Fri, 13 Mar 2020 18:00:51 +0100 Subject: [PATCH] Add documentation Various fixes: Made to_graph private Change format values to media types --- .gitignore | 3 + Pipfile | 5 +- Pipfile.lock | 77 +- concepttordf/__init__.py | 43 +- concepttordf/associativerelation.py | 2 +- concepttordf/collection.py | 8 +- concepttordf/concept.py | 78 +- concepttordf/contact.py | 6 +- concepttordf/genericrelation.py | 2 +- concepttordf/partitiverelation.py | 2 +- docs/alternativformulering.html | 101 ++ docs/associativerelation.html | 215 ++++ docs/betydningsbeskrivelse.html | 387 ++++++++ docs/collection.html | 393 ++++++++ docs/concept.html | 1432 +++++++++++++++++++++++++++ docs/conceptrelation.html | 165 +++ docs/contact.html | 334 +++++++ docs/definition.html | 101 ++ docs/genericrelation.html | 213 ++++ docs/index.html | 200 ++++ docs/partitiverelation.html | 213 ++++ setup.py | 7 +- tests/test_collection.py | 12 +- tests/test_concept.py | 50 +- tests/test_contact.py | 12 +- 25 files changed, 3997 insertions(+), 64 deletions(-) create mode 100644 docs/alternativformulering.html create mode 100644 docs/associativerelation.html create mode 100644 docs/betydningsbeskrivelse.html create mode 100644 docs/collection.html create mode 100644 docs/concept.html create mode 100644 docs/conceptrelation.html create mode 100644 docs/contact.html create mode 100644 docs/definition.html create mode 100644 docs/genericrelation.html create mode 100644 docs/index.html create mode 100644 docs/partitiverelation.html diff --git a/.gitignore b/.gitignore index b6e4761..7194c08 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,9 @@ instance/ # Sphinx documentation docs/_build/ +# Pdoc documentation +html + # PyBuilder target/ diff --git a/Pipfile b/Pipfile index 516576d..da73da8 100644 --- a/Pipfile +++ b/Pipfile @@ -11,10 +11,7 @@ rdflib-jsonld = "*" pytest = "*" flake8 = "*" pytest-cov = "*" +pdoc3 = "*" [requires] python_version = "3.8" - -[dev-packages.e1839a8] -path = "." -editable = true diff --git a/Pipfile.lock b/Pipfile.lock index ef1690d..4260a6d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "1b13421a111b4d35e756cc9e1b79fddd9930311b0dd464b95d0540448c11433f" + "sha256": "87a4ee6366756b61c6c00f215ef8cdeed5c3e152f900f0f273a9734360f3498d" }, "pipfile-spec": 6, "requires": { @@ -97,10 +97,6 @@ ], "version": "==5.0.3" }, - "e1839a8": { - "editable": true, - "path": "." - }, "entrypoints": { "hashes": [ "sha256:589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19", @@ -116,6 +112,58 @@ "index": "pypi", "version": "==3.7.9" }, + "mako": { + "hashes": [ + "sha256:3139c5d64aa5d175dbafb95027057128b5fbd05a40c53999f3905ceb53366d9d", + "sha256:8e8b53c71c7e59f3de716b6832c4e401d903af574f6962edbbbf6ecc2a5fe6c9" + ], + "version": "==1.1.2" + }, + "markdown": { + "hashes": [ + "sha256:90fee683eeabe1a92e149f7ba74e5ccdc81cd397bd6c516d93a8da0ef90b6902", + "sha256:e4795399163109457d4c5af2183fbe6b60326c17cfdf25ce6e7474c6624f725d" + ], + "version": "==3.2.1" + }, + "markupsafe": { + "hashes": [ + "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473", + "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", + "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", + "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", + "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42", + "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", + "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", + "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", + "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", + "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", + "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", + "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b", + "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", + "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15", + "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", + "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", + "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", + "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905", + "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735", + "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d", + "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e", + "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d", + "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c", + "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21", + "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2", + "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5", + "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b", + "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", + "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", + "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", + "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2", + "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7", + "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be" + ], + "version": "==1.1.1" + }, "mccabe": { "hashes": [ "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", @@ -132,10 +180,17 @@ }, "packaging": { "hashes": [ - "sha256:170748228214b70b672c581a3dd610ee51f733018650740e98c7df862a583f73", - "sha256:e665345f9eef0c621aa0bf2f8d78cf6d21904eef16a93f020240b704a57f1334" + "sha256:3c292b474fda1671ec57d46d739d072bfd495a4f51ad01a055121d81e952b7a3", + "sha256:82f77b9bee21c1bafbf35a84905d604d5d1223801d639cf3ed140bd651c08752" ], - "version": "==20.1" + "version": "==20.3" + }, + "pdoc3": { + "hashes": [ + "sha256:ebca75b7fcf23f3b4320abe23339834d3f08c28517718e9d29e555fc38eeb33c" + ], + "index": "pypi", + "version": "==0.7.5" }, "pluggy": { "hashes": [ @@ -174,11 +229,11 @@ }, "pytest": { "hashes": [ - "sha256:0d5fe9189a148acc3c3eb2ac8e1ac0742cb7618c084f3d228baaec0c254b318d", - "sha256:ff615c761e25eb25df19edddc0b970302d2a9091fbce0e7213298d85fb61fef6" + "sha256:0e5b30f5cb04e887b91b1ee519fa3d89049595f428c1db76e73bd7f17b09b172", + "sha256:84dde37075b8805f3d1f392cc47e38a0e59518fb46a431cfdaf7cf1ce805f970" ], "index": "pypi", - "version": "==5.3.5" + "version": "==5.4.1" }, "pytest-cov": { "hashes": [ diff --git a/concepttordf/__init__.py b/concepttordf/__init__.py index fe04536..9c337ce 100644 --- a/concepttordf/__init__.py +++ b/concepttordf/__init__.py @@ -1,8 +1,43 @@ -""" -Concept to rdf +"""Concept collection to rdf + +This library maps a concept collection to skos according to +[SKOS-AP-NO](https://doc.difi.no/data/begrep-skos-ap-no/), +a Norwegian application profile for [SKOS](https://www.w3.org/TR/skos-primer/). + +The library wraps [rdflib](https://rdflib.readthedocs.io/en/stable/). +The following serialization formats are available:\n + - `text/turtle` + - `application/rdf+xml` + - `application/ld+json` + - `application/n-triples` + - `text/n3` + +Typical usage example + + from concepttordf import Collection, Concept, Definition + + # Create collection object + collection = Collection() + collection.identifier = "http://example.com/collections/1" + collection.name = {"en": "A concept collection"} + collection.name = {"nb": "En begrepssamling"} + collection.publisher = "https://example.com/publishers/1" + + # Create a concept: + c = Concept() + c.identifier = "http://example.com/concepts/1" + c.term = {"name": {"nb": "inntekt", "en": "income"}} + definition = Definition() + definition.text = {"nb": "ting man skulle hatt mer av", + "en": "something you want more of"} + c.definition = definition + + # Add concept to collection: + collection.members.append(c) -Heading -------- + # get rdf representation in turtle (default) + rdf = collection.to_rdf() + print(rdf.decode()) """ from .alternativformulering import AlternativFormulering from .associativerelation import AssociativeRelation diff --git a/concepttordf/associativerelation.py b/concepttordf/associativerelation.py index d4d1b40..55bf800 100644 --- a/concepttordf/associativerelation.py +++ b/concepttordf/associativerelation.py @@ -27,7 +27,7 @@ def associatedconcepts(self) -> List: # --- - def to_graph(self) -> Graph: + def _to_graph(self) -> Graph: self._add_relation_to_graph() diff --git a/concepttordf/collection.py b/concepttordf/collection.py index daf202c..8da5307 100644 --- a/concepttordf/collection.py +++ b/concepttordf/collection.py @@ -56,7 +56,7 @@ def members(self) -> list: def members(self, members: list): self._members = members - def to_rdf(self, format='turtle', includeconcepts=True) -> str: + def to_rdf(self, format='text/turtle', includeconcepts=True) -> str: """Maps the collection to rdf and returns a serialization as a string according to format""" @@ -64,9 +64,9 @@ def to_rdf(self, format='turtle', includeconcepts=True) -> str: if includeconcepts: for concept in self.members: - self._g += concept.to_graph() + self._g += concept._to_graph() - return self._g.serialize(format=format, encoding='utf-8') + return self._g.serialize(format=format) # --- @@ -102,7 +102,7 @@ def _add_collection_to_graph(self) -> Graph: if hasattr(self, 'contactpoint'): contact = self.contactpoint contactPoint = BNode() - for s, p, o in contact.to_graph().triples((None, None, None)): + for s, p, o in contact._to_graph().triples((None, None, None)): self._g.add((contactPoint, p, o)) self._g.add((URIRef(self.identifier), DCAT.contactPoint, contactPoint)) diff --git a/concepttordf/concept.py b/concepttordf/concept.py index e5035a2..97d616a 100644 --- a/concepttordf/concept.py +++ b/concepttordf/concept.py @@ -21,7 +21,24 @@ class Concept: - """A class representing a concept""" + """A class representing a concept + + + Attributes: + identifier: the uri identifying the concept + term: a dictionary describing the + [anbefaltterm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_anbefaltterm) + , e.g.\n + ``` + {"name": {"en": "concept"}, "modified":"2020-01-01"} + ``` + alternativeterm: a dictionary describing the + [tillattTerm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_tillattterm) + + hiddenterm: a dictionary describing the + [frarådetTerm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_frar%C3%A5detterm) + + """ def __init__(self): self._g = Graph() @@ -54,6 +71,14 @@ def alternativeterm(self) -> dict: def alternativeterm(self, alternativeterm: dict): self._alternativeterm = alternativeterm + @property + def hiddenterm(self) -> dict: + return self._hiddenterm + + @hiddenterm.setter + def hiddenterm(self, hiddenterm: dict): + self._hiddenterm = hiddenterm + @property def datastrukturterm(self) -> dict: return self._datastrukturterm @@ -176,18 +201,49 @@ def hasPart(self, gr: PartitiveRelation): self._hasPart = gr # ---------------------------------------------- - def to_graph(self) -> Graph: - """Adds the concept to the Graph g and returns g""" + def _to_graph(self) -> Graph: + """Transforms the concept to an rdf graph + + Returns: + An RDF [graph](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#graph) representing the concept. + """ self._add_concept_to_graph() return self._g - def to_rdf(self, format='turtle') -> str: + def to_rdf(self, format='text/turtle') -> str: """Maps the concept to rdf and returns a serialization - as a string according to format""" - - return self.to_graph().serialize(format=format, encoding='utf-8') + as a string according to format + + Args: + format: a valid serialization format\n + - `text/turtle` (default) + - `application/rdf+xml` + - `application/ld+json` + - `application/n-triples` + - `text/n3` + + Returns: + A serialization of the RDF graph, for example: + ``` + @prefix dct: . + @prefix rdf: . + @prefix rdfs: . + @prefix skos: . + @prefix skosno: . + @prefix xml: . + @prefix xsd: . + + a skos:Concept ; + skosno:definisjon [ a skosno:Definisjon ; + skosno:forholdTilKilde skosno:egendefinert ] + . + ``` + + """ + + return self._to_graph().serialize(format=format) # ---------------------------------------------- @@ -287,7 +343,7 @@ def _add_concept_to_graph(self): if hasattr(self, 'contactpoint'): contact = self.contactpoint contactPoint = BNode() - for s, p, o in contact.to_graph().triples((None, None, None)): + for s, p, o in contact._to_graph().triples((None, None, None)): self._g.add((contactPoint, p, o)) self._g.add((URIRef(self.identifier), DCAT.contactPoint, contactPoint)) @@ -346,7 +402,7 @@ def _add_concept_to_graph(self): if hasattr(self, 'related'): _related = self.related ar = BNode() - for s, p, o in _related.to_graph().triples((None, None, None)): + for s, p, o in _related._to_graph().triples((None, None, None)): self._g.add((ar, p, o)) self._g.add((URIRef(self.identifier), SKOS.related, ar)) @@ -354,7 +410,7 @@ def _add_concept_to_graph(self): if hasattr(self, 'generalizes'): _generalizes = self.generalizes ar = BNode() - for s, p, o in _generalizes.to_graph().triples((None, None, None)): + for s, p, o in _generalizes._to_graph().triples((None, None, None)): self._g.add((ar, p, o)) self._g.add((URIRef(self.identifier), XKOS.generalizes, ar)) @@ -362,7 +418,7 @@ def _add_concept_to_graph(self): if hasattr(self, 'hasPart'): _hasPart = self.hasPart ar = BNode() - for s, p, o in _hasPart.to_graph().triples((None, None, None)): + for s, p, o in _hasPart._to_graph().triples((None, None, None)): self._g.add((ar, p, o)) self._g.add((URIRef(self.identifier), XKOS.hasPart, ar)) diff --git a/concepttordf/contact.py b/concepttordf/contact.py index c83aec3..075d630 100644 --- a/concepttordf/contact.py +++ b/concepttordf/contact.py @@ -45,17 +45,17 @@ def url(self) -> str: def url(self, url: str): self._url = url - def to_graph(self) -> Graph: + def _to_graph(self) -> Graph: self._add_contact_to_graph() return self._g - def to_rdf(self, format='turtle') -> str: + def to_rdf(self, format='text/turtle') -> str: """Maps the contact to rdf and returns a serialization as a string according to format""" - return self.to_graph().serialize(format=format, encoding='utf-8') + return self._to_graph().serialize(format=format) # ----- diff --git a/concepttordf/genericrelation.py b/concepttordf/genericrelation.py index d8c69e0..ab4d99d 100644 --- a/concepttordf/genericrelation.py +++ b/concepttordf/genericrelation.py @@ -26,7 +26,7 @@ def genericconcepts(self) -> List: return self._genericconcepts # --- - def to_graph(self) -> Graph: + def _to_graph(self) -> Graph: self._add_relation_to_graph() diff --git a/concepttordf/partitiverelation.py b/concepttordf/partitiverelation.py index 25c777c..8aa1ee2 100644 --- a/concepttordf/partitiverelation.py +++ b/concepttordf/partitiverelation.py @@ -26,7 +26,7 @@ def partconcepts(self) -> List: return self._partconcepts # --- - def to_graph(self) -> Graph: + def _to_graph(self) -> Graph: self._add_relation_to_graph() diff --git a/docs/alternativformulering.html b/docs/alternativformulering.html new file mode 100644 index 0000000..32458c7 --- /dev/null +++ b/docs/alternativformulering.html @@ -0,0 +1,101 @@ + + + + + + +concepttordf.alternativformulering API documentation + + + + + + + + + +
+
+
+

Module concepttordf.alternativformulering

+
+
+
+ +Expand source code + +
from .betydningsbeskrivelse import Betydningsbeskrivelse
+from rdflib import Namespace
+
+SKOSNO = Namespace('https://data.norge.no/vocabulary/skosno#')
+
+
+class AlternativFormulering(Betydningsbeskrivelse):
+
+    def __init__(self):
+        self.type = SKOSNO.AlternativFormulering
+        super().__init__()
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class AlternativFormulering +
+
+

Helper class that provides a standard way to create an ABC using +inheritance.

+
+ +Expand source code + +
class AlternativFormulering(Betydningsbeskrivelse):
+
+    def __init__(self):
+        self.type = SKOSNO.AlternativFormulering
+        super().__init__()
+
+

Ancestors

+ +
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/associativerelation.html b/docs/associativerelation.html new file mode 100644 index 0000000..bad8968 --- /dev/null +++ b/docs/associativerelation.html @@ -0,0 +1,215 @@ + + + + + + +concepttordf.associativerelation API documentation + + + + + + + + + +
+
+
+

Module concepttordf.associativerelation

+
+
+
+ +Expand source code + +
from .conceptrelation import ConceptRelation
+from rdflib import Graph, Literal, Namespace, RDF, URIRef
+from typing import List
+
+SKOSNO = Namespace('https://data.norge.no/vocabulary/skosno#')
+DCT = Namespace('http://purl.org/dc/terms/')
+XSD = Namespace('http://www.w3.org/2001/XMLSchema#')
+
+
+class AssociativeRelation(ConceptRelation):
+
+    def __init__(self):
+        self._associatedconcepts = list()
+        super().__init__()
+
+    @property
+    def description(self) -> dict:
+        return self._description
+
+    @description.setter
+    def description(self, description: dict):
+        self._description = description
+
+    @property
+    def associatedconcepts(self) -> List:
+        return self._associatedconcepts
+
+# ---
+
+    def _to_graph(self) -> Graph:
+
+        self._add_relation_to_graph()
+
+        return self._g
+
+# ---
+    def _add_relation_to_graph(self):
+
+        super(AssociativeRelation, self)._add_relation_to_graph()
+
+        self._g.add((self._relation, RDF.type, SKOSNO.AssosiativRelasjon))
+
+        # description
+        if hasattr(self, 'description'):
+            for key in self.description:
+                self._g.add((self._relation, DCT.description,
+                            Literal(self.description[key], lang=key)))
+
+        # associatedconcepts
+        if hasattr(self, 'associatedconcepts'):
+            # breakpoint()
+            for ac in self.associatedconcepts:
+                self._g.add((self._relation, SKOSNO.assosiertBegrep,
+                            URIRef(ac)))
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class AssociativeRelation +
+
+

Helper class that provides a standard way to create an ABC using +inheritance.

+
+ +Expand source code + +
class AssociativeRelation(ConceptRelation):
+
+    def __init__(self):
+        self._associatedconcepts = list()
+        super().__init__()
+
+    @property
+    def description(self) -> dict:
+        return self._description
+
+    @description.setter
+    def description(self, description: dict):
+        self._description = description
+
+    @property
+    def associatedconcepts(self) -> List:
+        return self._associatedconcepts
+
+# ---
+
+    def _to_graph(self) -> Graph:
+
+        self._add_relation_to_graph()
+
+        return self._g
+
+# ---
+    def _add_relation_to_graph(self):
+
+        super(AssociativeRelation, self)._add_relation_to_graph()
+
+        self._g.add((self._relation, RDF.type, SKOSNO.AssosiativRelasjon))
+
+        # description
+        if hasattr(self, 'description'):
+            for key in self.description:
+                self._g.add((self._relation, DCT.description,
+                            Literal(self.description[key], lang=key)))
+
+        # associatedconcepts
+        if hasattr(self, 'associatedconcepts'):
+            # breakpoint()
+            for ac in self.associatedconcepts:
+                self._g.add((self._relation, SKOSNO.assosiertBegrep,
+                            URIRef(ac)))
+
+

Ancestors

+ +

Instance variables

+
+
var associatedconcepts
+
+
+
+ +Expand source code + +
@property
+def associatedconcepts(self) -> List:
+    return self._associatedconcepts
+
+
+
var description
+
+
+
+ +Expand source code + +
@property
+def description(self) -> dict:
+    return self._description
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/betydningsbeskrivelse.html b/docs/betydningsbeskrivelse.html new file mode 100644 index 0000000..6449ea4 --- /dev/null +++ b/docs/betydningsbeskrivelse.html @@ -0,0 +1,387 @@ + + + + + + +concepttordf.betydningsbeskrivelse API documentation + + + + + + + + + +
+
+
+

Module concepttordf.betydningsbeskrivelse

+
+
+
+ +Expand source code + +
from abc import ABC
+from enum import Enum
+
+
+class RelationToSource(Enum):
+    sitatFraKilde = "quoteFromSource"
+    basertPåKilde = "basedOnSource"
+    egendefinert = "noSource"
+
+
+class Betydningsbeskrivelse(ABC):
+
+    def __init__(self):
+        pass
+
+    @property
+    def type(self):
+        return self._type
+
+    @type.setter
+    def type(self, type):
+        self._type = type
+
+    @property
+    def text(self) -> dict:
+        return self._text
+
+    @text.setter
+    def text(self, text: dict):
+        self._text = text
+
+    @property
+    def remark(self) -> dict:
+        return self._remark
+
+    @remark.setter
+    def remark(self, remark: dict):
+        self._remark = remark
+
+    @property
+    def scope(self) -> dict:
+        return self._scope
+
+    @scope.setter
+    def scope(self, scope: dict):
+        self._scope = scope
+
+    @property
+    def relationtosource(self) -> str:
+        return self._relationtosource
+
+    @relationtosource.setter
+    def relationtosource(self, relationtosource: str):
+        self._relationtosource = relationtosource
+
+    @property
+    def source(self) -> dict:
+        return self._source
+
+    @source.setter
+    def source(self, source: dict):
+        self._source = source
+
+    @property
+    def modified(self) -> dict:
+        return self._modified
+
+    @modified.setter
+    def modified(self, modified: dict):
+        self._modified = modified
+
+    @property
+    def example(self) -> dict:
+        return self._example
+
+    @example.setter
+    def example(self, example: dict):
+        self._example = example
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class Betydningsbeskrivelse +
+
+

Helper class that provides a standard way to create an ABC using +inheritance.

+
+ +Expand source code + +
class Betydningsbeskrivelse(ABC):
+
+    def __init__(self):
+        pass
+
+    @property
+    def type(self):
+        return self._type
+
+    @type.setter
+    def type(self, type):
+        self._type = type
+
+    @property
+    def text(self) -> dict:
+        return self._text
+
+    @text.setter
+    def text(self, text: dict):
+        self._text = text
+
+    @property
+    def remark(self) -> dict:
+        return self._remark
+
+    @remark.setter
+    def remark(self, remark: dict):
+        self._remark = remark
+
+    @property
+    def scope(self) -> dict:
+        return self._scope
+
+    @scope.setter
+    def scope(self, scope: dict):
+        self._scope = scope
+
+    @property
+    def relationtosource(self) -> str:
+        return self._relationtosource
+
+    @relationtosource.setter
+    def relationtosource(self, relationtosource: str):
+        self._relationtosource = relationtosource
+
+    @property
+    def source(self) -> dict:
+        return self._source
+
+    @source.setter
+    def source(self, source: dict):
+        self._source = source
+
+    @property
+    def modified(self) -> dict:
+        return self._modified
+
+    @modified.setter
+    def modified(self, modified: dict):
+        self._modified = modified
+
+    @property
+    def example(self) -> dict:
+        return self._example
+
+    @example.setter
+    def example(self, example: dict):
+        self._example = example
+
+

Ancestors

+
    +
  • abc.ABC
  • +
+

Subclasses

+ +

Instance variables

+
+
var example
+
+
+
+ +Expand source code + +
@property
+def example(self) -> dict:
+    return self._example
+
+
+
var modified
+
+
+
+ +Expand source code + +
@property
+def modified(self) -> dict:
+    return self._modified
+
+
+
var relationtosource
+
+
+
+ +Expand source code + +
@property
+def relationtosource(self) -> str:
+    return self._relationtosource
+
+
+
var remark
+
+
+
+ +Expand source code + +
@property
+def remark(self) -> dict:
+    return self._remark
+
+
+
var scope
+
+
+
+ +Expand source code + +
@property
+def scope(self) -> dict:
+    return self._scope
+
+
+
var source
+
+
+
+ +Expand source code + +
@property
+def source(self) -> dict:
+    return self._source
+
+
+
var text
+
+
+
+ +Expand source code + +
@property
+def text(self) -> dict:
+    return self._text
+
+
+
var type
+
+
+
+ +Expand source code + +
@property
+def type(self):
+    return self._type
+
+
+
+
+
+class RelationToSource +(value, names=None, *, module=None, qualname=None, type=None, start=1) +
+
+

An enumeration.

+
+ +Expand source code + +
class RelationToSource(Enum):
+    sitatFraKilde = "quoteFromSource"
+    basertPåKilde = "basedOnSource"
+    egendefinert = "noSource"
+
+

Ancestors

+
    +
  • enum.Enum
  • +
+

Class variables

+
+
var basertPåKilde
+
+
+
+
var egendefinert
+
+
+
+
var sitatFraKilde
+
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/collection.html b/docs/collection.html new file mode 100644 index 0000000..f7e8d0f --- /dev/null +++ b/docs/collection.html @@ -0,0 +1,393 @@ + + + + + + +concepttordf.collection API documentation + + + + + + + + + +
+
+
+

Module concepttordf.collection

+
+
+
+ +Expand source code + +
from rdflib import Graph, Literal, BNode, Namespace, RDF, RDFS, URIRef
+from .contact import Contact
+
+DCT = Namespace('http://purl.org/dc/terms/')
+SKOSXL = Namespace('http://www.w3.org/2008/05/skos-xl#')
+VCARD = Namespace('http://www.w3.org/2006/vcard/ns#')
+SKOS = Namespace('http://www.w3.org/2004/02/skos/core#')
+SKOSNO = Namespace('http://difi.no/skosno')
+DCAT = Namespace('http://www.w3.org/ns/dcat#')
+
+
+class Collection:
+    """" A class representing a concept collection"""
+
+    def __init__(self):
+        self._g = Graph()
+        self._members = []
+
+    @property
+    def name(self) -> str:
+        return self._name
+
+    @name.setter
+    def name(self, name: str):
+        self._name = name
+
+    @property
+    def publisher(self) -> str:
+        return self._publisher
+
+    @publisher.setter
+    def publisher(self, publisher: str):
+        self._publisher = publisher
+
+    @property
+    def description(self) -> str:
+        return self._description
+
+    @description.setter
+    def description(self, description: str):
+        self._description = description
+
+    @property
+    def contactpoint(self) -> Contact:
+        return self._contactpoint
+
+    @contactpoint.setter
+    def contactpoint(self, contact: Contact):
+        self._contactpoint = contact
+
+    @property
+    def members(self) -> list:
+        return self._members
+
+    @members.setter
+    def members(self, members: list):
+        self._members = members
+
+    def to_rdf(self, format='text/turtle', includeconcepts=True) -> str:
+        """Maps the collection to rdf and returns a serialization
+           as a string according to format"""
+
+        self._add_collection_to_graph()
+
+        if includeconcepts:
+            for concept in self.members:
+                self._g += concept._to_graph()
+
+        return self._g.serialize(format=format)
+
+    # ---
+
+    def _add_collection_to_graph(self) -> Graph:
+        """Adds the collection to the Graph _g"""
+
+        self._g.bind('dct', DCT)
+        self._g.bind('skos', SKOS)
+        self._g.bind('skosxl', SKOSXL)
+        self._g.bind('vcard', VCARD)
+        self._g.bind('skosno', SKOSNO)
+        self._g.bind('dcat', DCAT)
+
+        self._g.add((URIRef(self.identifier), RDF.type, SKOS.Collection))
+
+        # publisher
+        self._g.add((URIRef(self.identifier), DCT.publisher,
+                    URIRef(self.publisher)))
+
+        # name
+        if hasattr(self, 'name'):
+            for key in self.name:
+                self._g.add((URIRef(self.identifier), RDFS.label,
+                            Literal(self.name[key], lang=key)))
+
+        # description
+        if hasattr(self, 'description'):
+            for key in self.description:
+                self._g.add((URIRef(self.identifier), DCT.description,
+                            Literal(self.description[key], lang=key)))
+
+        # contactPoint
+        if hasattr(self, 'contactpoint'):
+            contact = self.contactpoint
+            contactPoint = BNode()
+            for s, p, o in contact._to_graph().triples((None, None, None)):
+                self._g.add((contactPoint, p, o))
+            self._g.add((URIRef(self.identifier), DCAT.contactPoint,
+                        contactPoint))
+
+        # members
+        if hasattr(self, 'members'):
+            for concept in self.members:
+                self._g.add((URIRef(self.identifier), SKOS.member,
+                             URIRef(concept.identifier)))
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class Collection +
+
+

" A class representing a concept collection

+
+ +Expand source code + +
class Collection:
+    """" A class representing a concept collection"""
+
+    def __init__(self):
+        self._g = Graph()
+        self._members = []
+
+    @property
+    def name(self) -> str:
+        return self._name
+
+    @name.setter
+    def name(self, name: str):
+        self._name = name
+
+    @property
+    def publisher(self) -> str:
+        return self._publisher
+
+    @publisher.setter
+    def publisher(self, publisher: str):
+        self._publisher = publisher
+
+    @property
+    def description(self) -> str:
+        return self._description
+
+    @description.setter
+    def description(self, description: str):
+        self._description = description
+
+    @property
+    def contactpoint(self) -> Contact:
+        return self._contactpoint
+
+    @contactpoint.setter
+    def contactpoint(self, contact: Contact):
+        self._contactpoint = contact
+
+    @property
+    def members(self) -> list:
+        return self._members
+
+    @members.setter
+    def members(self, members: list):
+        self._members = members
+
+    def to_rdf(self, format='text/turtle', includeconcepts=True) -> str:
+        """Maps the collection to rdf and returns a serialization
+           as a string according to format"""
+
+        self._add_collection_to_graph()
+
+        if includeconcepts:
+            for concept in self.members:
+                self._g += concept._to_graph()
+
+        return self._g.serialize(format=format)
+
+    # ---
+
+    def _add_collection_to_graph(self) -> Graph:
+        """Adds the collection to the Graph _g"""
+
+        self._g.bind('dct', DCT)
+        self._g.bind('skos', SKOS)
+        self._g.bind('skosxl', SKOSXL)
+        self._g.bind('vcard', VCARD)
+        self._g.bind('skosno', SKOSNO)
+        self._g.bind('dcat', DCAT)
+
+        self._g.add((URIRef(self.identifier), RDF.type, SKOS.Collection))
+
+        # publisher
+        self._g.add((URIRef(self.identifier), DCT.publisher,
+                    URIRef(self.publisher)))
+
+        # name
+        if hasattr(self, 'name'):
+            for key in self.name:
+                self._g.add((URIRef(self.identifier), RDFS.label,
+                            Literal(self.name[key], lang=key)))
+
+        # description
+        if hasattr(self, 'description'):
+            for key in self.description:
+                self._g.add((URIRef(self.identifier), DCT.description,
+                            Literal(self.description[key], lang=key)))
+
+        # contactPoint
+        if hasattr(self, 'contactpoint'):
+            contact = self.contactpoint
+            contactPoint = BNode()
+            for s, p, o in contact._to_graph().triples((None, None, None)):
+                self._g.add((contactPoint, p, o))
+            self._g.add((URIRef(self.identifier), DCAT.contactPoint,
+                        contactPoint))
+
+        # members
+        if hasattr(self, 'members'):
+            for concept in self.members:
+                self._g.add((URIRef(self.identifier), SKOS.member,
+                             URIRef(concept.identifier)))
+
+

Instance variables

+
+
var contactpoint
+
+
+
+ +Expand source code + +
@property
+def contactpoint(self) -> Contact:
+    return self._contactpoint
+
+
+
var description
+
+
+
+ +Expand source code + +
@property
+def description(self) -> str:
+    return self._description
+
+
+
var members
+
+
+
+ +Expand source code + +
@property
+def members(self) -> list:
+    return self._members
+
+
+
var name
+
+
+
+ +Expand source code + +
@property
+def name(self) -> str:
+    return self._name
+
+
+
var publisher
+
+
+
+ +Expand source code + +
@property
+def publisher(self) -> str:
+    return self._publisher
+
+
+
+

Methods

+
+
+def to_rdf(self, format='text/turtle', includeconcepts=True) +
+
+

Maps the collection to rdf and returns a serialization +as a string according to format

+
+ +Expand source code + +
def to_rdf(self, format='text/turtle', includeconcepts=True) -> str:
+    """Maps the collection to rdf and returns a serialization
+       as a string according to format"""
+
+    self._add_collection_to_graph()
+
+    if includeconcepts:
+        for concept in self.members:
+            self._g += concept._to_graph()
+
+    return self._g.serialize(format=format)
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/concept.html b/docs/concept.html new file mode 100644 index 0000000..b4d2632 --- /dev/null +++ b/docs/concept.html @@ -0,0 +1,1432 @@ + + + + + + +concepttordf.concept API documentation + + + + + + + + + +
+
+
+

Module concepttordf.concept

+
+
+
+ +Expand source code + +
from rdflib import Graph, Literal, BNode, Namespace, RDF, RDFS, URIRef
+from datetime import date
+from .contact import Contact
+from .definition import Definition
+from .alternativformulering import AlternativFormulering
+from .betydningsbeskrivelse import RelationToSource
+from .associativerelation import AssociativeRelation
+from .genericrelation import GenericRelation
+from .partitiverelation import PartitiveRelation
+
+
+DCT = Namespace('http://purl.org/dc/terms/')
+SKOSXL = Namespace('http://www.w3.org/2008/05/skos-xl#')
+VCARD = Namespace('http://www.w3.org/2006/vcard/ns#')
+SKOS = Namespace('http://www.w3.org/2004/02/skos/core#')
+SKOSNO = Namespace('https://data.norge.no/vocabulary/skosno#')
+DCAT = Namespace('http://www.w3.org/ns/dcat#')
+XSD = Namespace('http://www.w3.org/2001/XMLSchema#')
+SCHEMA = Namespace('http://schema.org/')
+XKOS = Namespace('http://rdf-vocabulary.ddialliance.org/xkos#')
+
+
+class Concept:
+    """A class representing a concept
+
+
+    Attributes:
+        identifier: the uri identifying the concept
+        term: a dictionary describing the
+            [anbefaltterm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_anbefaltterm)
+            , e.g.\n
+            ```
+            {"name": {"en": "concept"}, "modified":"2020-01-01"}
+            ```
+        alternativeterm: a dictionary describing the
+            [tillattTerm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_tillattterm)
+
+        hiddenterm: a dictionary describing the
+            [frarådetTerm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_frar%C3%A5detterm)
+
+    """
+
+    def __init__(self):
+        self._g = Graph()
+
+        self.seeAlso = []
+        self.replaces = []
+        self.replacedBy = []
+
+    @property
+    def identifier(self) -> str:
+        return self._identifier
+
+    @identifier.setter
+    def identifier(self, uri: str):
+        self._identifier = uri
+
+    @property
+    def term(self) -> dict:
+        return self._term
+
+    @term.setter
+    def term(self, term: dict):
+        self._term = term
+
+    @property
+    def alternativeterm(self) -> dict:
+        return self._alternativeterm
+
+    @alternativeterm.setter
+    def alternativeterm(self, alternativeterm: dict):
+        self._alternativeterm = alternativeterm
+
+    @property
+    def hiddenterm(self) -> dict:
+        return self._hiddenterm
+
+    @hiddenterm.setter
+    def hiddenterm(self, hiddenterm: dict):
+        self._hiddenterm = hiddenterm
+
+    @property
+    def datastrukturterm(self) -> dict:
+        return self._datastrukturterm
+
+    @datastrukturterm.setter
+    def datastrukturterm(self, datastrukturterm: dict):
+        self._datastrukturterm = datastrukturterm
+
+    @property
+    def subject(self) -> dict:
+        return self._subject
+
+    @subject.setter
+    def subject(self, subject: dict):
+        self._subject = subject
+
+    @property
+    def definition(self) -> Definition:
+        return self._definition
+
+    @definition.setter
+    def definition(self, definition: Definition):
+        self._definition = definition
+
+    @property
+    def alternativformulering(self) -> AlternativFormulering:
+        return self._alternativformulering
+
+    @alternativformulering.setter
+    def alternativformulering(self,
+                              alternativformulering: AlternativFormulering):
+        self._alternativformulering = alternativformulering
+
+    @property
+    def contactpoint(self) -> Contact:
+        return self._contactpoint
+
+    @contactpoint.setter
+    def contactpoint(self, contact: Contact):
+        self._contactpoint = contact
+
+    @property
+    def modified(self) -> date:
+        return self._modified
+
+    @modified.setter
+    def modified(self, modified: date):
+        self._modified = modified
+
+    @property
+    def bruksområde(self) -> dict:
+        return self._bruksområde
+
+    @bruksområde.setter
+    def bruksområde(self, bruksområde: dict):
+        self._bruksområde = bruksområde
+
+    @property
+    def validinperiod(self) -> dict:
+        return self._validinperiod
+
+    @validinperiod.setter
+    def validinperiod(self, validinperiod: dict):
+        self._validinperiod = validinperiod
+
+    @property
+    def publisher(self) -> str:
+        return self._publisher
+
+    @publisher.setter
+    def publisher(self, publisher: str):
+        self._publisher = publisher
+
+    @property
+    def seeAlso(self) -> list:
+        return self._seeAlso
+
+    @seeAlso.setter
+    def seeAlso(self, concepts: list):
+        self._seeAlso = concepts
+
+    @property
+    def replaces(self) -> list:
+        return self._replaces
+
+    @replaces.setter
+    def replaces(self, concepts: list):
+        self._replaces = concepts
+
+    @property
+    def replacedBy(self) -> list:
+        return self._replacedBy
+
+    @replacedBy.setter
+    def replacedBy(self, concepts: list):
+        self._replacedBy = concepts
+
+    @property
+    def related(self) -> AssociativeRelation:
+        return self._related
+
+    @related.setter
+    def related(self, ar: AssociativeRelation):
+        self._related = ar
+
+    @property
+    def generalizes(self) -> GenericRelation:
+        return self._generalizes
+
+    @generalizes.setter
+    def generalizes(self, gr: GenericRelation):
+        self._generalizes = gr
+
+    @property
+    def hasPart(self) -> PartitiveRelation:
+        return self._hasPart
+
+    @hasPart.setter
+    def hasPart(self, gr: PartitiveRelation):
+        self._hasPart = gr
+# ----------------------------------------------
+
+    def _to_graph(self) -> Graph:
+        """Transforms the concept to an rdf graph
+
+        Returns:
+            An RDF [graph](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#graph) representing the concept.
+        """
+
+        self._add_concept_to_graph()
+
+        return self._g
+
+    def to_rdf(self, format='text/turtle') -> str:
+        """Maps the concept to rdf and returns a serialization
+           as a string according to format
+
+        Args:
+            format: a valid serialization format\n
+                 - `text/turtle` (default)
+                 - `application/rdf+xml`
+                 - `application/ld+json`
+                 - `application/n-triples`
+                 - `text/n3`
+
+        Returns:
+            A serialization of the RDF graph, for example:
+            ```
+            @prefix dct: <http://purl.org/dc/terms/> .
+            @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+            @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+            @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
+            @prefix skosno: <https://data.norge.no/vocabulary/skosno#> .
+            @prefix xml: <http://www.w3.org/XML/1998/namespace> .
+            @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+            <http://example.com/concepts/1> a skos:Concept ;
+                    skosno:definisjon [ a skosno:Definisjon ;
+                    skosno:forholdTilKilde skosno:egendefinert ]
+                    .
+            ```
+
+           """
+
+        return self._to_graph().serialize(format=format)
+
+# ----------------------------------------------
+
+    def _add_concept_to_graph(self):
+        """Adds the concept to the Graph _g"""
+
+        self._g.bind('dct', DCT)
+        self._g.bind('skos', SKOS)
+        self._g.bind('skosxl', SKOSXL)
+        self._g.bind('vcard', VCARD)
+        self._g.bind('skosno', SKOSNO)
+        self._g.bind('dcat', DCAT)
+        self._g.bind('xsd', XSD)
+        self._g.bind('schema', SCHEMA)
+        self._g.bind('xkos', XKOS)
+
+        self._g.add((URIRef(self.identifier), RDF.type, SKOS.Concept))
+
+        # prefLabel
+        if hasattr(self, 'term'):
+            label = BNode()
+            self._g.add((label, RDF.type, SKOSXL.Label))
+            if 'name' in self.term:
+                _name = self.term['name']
+                for key in _name:
+                    self._g.add((label, SKOSXL.literalForm,
+                                 Literal(_name[key], lang=key)))
+            if 'modified' in self.term:
+                self._g.add((label, DCT.modified,
+                            Literal(self.term['modified'], datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier), SKOSXL.prefLabel, label))
+
+        # altLabel
+        if hasattr(self, 'alternativeterm'):
+            altLabel = BNode()
+            self._g.add((altLabel, RDF.type, SKOSXL.Label))
+            if 'name' in self.alternativeterm:
+                _name = self.alternativeterm['name']
+                for key in _name:
+                    for l in _name[key]:
+                        self._g.add((altLabel, SKOSXL.literalForm,
+                                     Literal(l, lang=key)))
+            if 'modified' in self.alternativeterm:
+                self._g.add((altLabel, DCT.modified,
+                             Literal(self.alternativeterm['modified'],
+                                     datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier), SKOSXL.altLabel, altLabel))
+
+        # hiddenLabel
+        if hasattr(self, 'hiddenterm'):
+            hiddenLabel = BNode()
+            self._g.add((hiddenLabel, RDF.type, SKOSXL.Label))
+            if 'name' in self.hiddenterm:
+                _name = self.hiddenterm['name']
+                for key in _name:
+                    for l in _name[key]:
+                        self._g.add((hiddenLabel, SKOSXL.literalForm,
+                                     Literal(l, lang=key)))
+            if 'modified' in self.hiddenterm:
+                self._g.add((hiddenLabel, DCT.modified,
+                             Literal(self.hiddenterm['modified'],
+                                     datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier),
+                         SKOSXL.hiddenLabel, hiddenLabel))
+
+        # datastrukturterm
+        if hasattr(self, 'datastrukturterm'):
+            datastrukturterm = BNode()
+            self._g.add((datastrukturterm, RDF.type, SKOSXL.Label))
+            if 'name' in self.datastrukturterm:
+                _name = self.datastrukturterm['name']
+                for key in _name:
+                    for l in _name[key]:
+                        self._g.add((datastrukturterm, SKOSXL.literalForm,
+                                     Literal(l, lang=key)))
+            if 'modified' in self.datastrukturterm:
+                self._g.add((datastrukturterm, DCT.modified,
+                             Literal(self.datastrukturterm['modified'],
+                                     datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier),
+                         SKOSNO.datastrukturterm, datastrukturterm))
+        # definition
+        if hasattr(self, 'definition'):
+            self._add_betydningsbeskrivelse_to_concept(self.definition)
+
+        # alternativformulering
+        if hasattr(self, 'alternativformulering'):
+            self._add_betydningsbeskrivelse_to_concept(
+                self.alternativformulering)
+
+        # publisher
+        if hasattr(self, 'publisher'):
+            self._g.add((URIRef(self.identifier), DCT.publisher,
+                         URIRef(self.publisher)))
+
+        # contactPoint
+        if hasattr(self, 'contactpoint'):
+            contact = self.contactpoint
+            contactPoint = BNode()
+            for s, p, o in contact._to_graph().triples((None, None, None)):
+                self._g.add((contactPoint, p, o))
+            self._g.add((URIRef(self.identifier), DCAT.contactPoint,
+                         contactPoint))
+
+        # subject
+        if hasattr(self, 'subject'):
+            for key in self.subject:
+                self._g.add((URIRef(self.identifier), DCT.subject,
+                             Literal(self.subject[key], lang=key)))
+
+        # modified
+        if hasattr(self, 'modified'):
+            self._g.add((URIRef(self.identifier), DCT.modified,
+                         Literal(self.modified, datatype=XSD.date)))
+
+        # bruksområde
+        if hasattr(self, 'bruksområde'):
+            for key in self.bruksområde:
+                for b in self.bruksområde[key]:
+                    self._g.add((URIRef(self.identifier), SKOSNO.bruksområde,
+                                 Literal(b, lang=key)))
+
+        # PeriodOfTime
+        if hasattr(self, 'validinperiod'):
+            periodOfTime = BNode()
+            self._g.add((periodOfTime, RDF.type, DCT.PeriodOfTime))
+            if 'startdate' in self.validinperiod:
+                self._g.add((periodOfTime, SCHEMA.startDate,
+                            Literal(self.validinperiod['startdate'],
+                                    datatype=XSD.date)))
+            if 'enddate' in self.validinperiod:
+                self._g.add((periodOfTime, SCHEMA.endDate,
+                            Literal(self.validinperiod['enddate'],
+                                    datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier), DCT.temporal, periodOfTime))
+
+        # seeAlso
+        if hasattr(self, 'seeAlso'):
+            for c in self.seeAlso:
+                self._g.add((URIRef(self.identifier), RDFS.seeAlso,
+                            URIRef(c.identifier)))
+
+        # replaces
+        if hasattr(self, 'replaces'):
+            for c in self.replaces:
+                self._g.add((URIRef(self.identifier), DCT.replaces,
+                             URIRef(c.identifier)))
+
+        # replacedBy
+        if hasattr(self, 'replacedBy'):
+            for c in self.replacedBy:
+                self._g.add((URIRef(self.identifier), DCT.replacedBy,
+                             URIRef(c.identifier)))
+
+        # related
+        if hasattr(self, 'related'):
+            _related = self.related
+            ar = BNode()
+            for s, p, o in _related._to_graph().triples((None, None, None)):
+                self._g.add((ar, p, o))
+            self._g.add((URIRef(self.identifier), SKOS.related, ar))
+
+        # generalizes
+        if hasattr(self, 'generalizes'):
+            _generalizes = self.generalizes
+            ar = BNode()
+            for s, p, o in _generalizes._to_graph().triples((None, None, None)):
+                self._g.add((ar, p, o))
+            self._g.add((URIRef(self.identifier), XKOS.generalizes, ar))
+
+        # hasPart
+        if hasattr(self, 'hasPart'):
+            _hasPart = self.hasPart
+            ar = BNode()
+            for s, p, o in _hasPart._to_graph().triples((None, None, None)):
+                self._g.add((ar, p, o))
+            self._g.add((URIRef(self.identifier), XKOS.hasPart, ar))
+
+# ------------
+# Helper methods:
+
+    def _add_betydningsbeskrivelse_to_concept(self, betydningsbeskrivelse):
+        # ---
+        _betydningsbeskrivelse = BNode()
+
+        self._g.add((_betydningsbeskrivelse, RDF.type,
+                     betydningsbeskrivelse.type))
+
+        # text
+        if hasattr(betydningsbeskrivelse, 'text'):
+            for key in betydningsbeskrivelse.text:
+                self._g.add((_betydningsbeskrivelse, RDFS.label,
+                            Literal(betydningsbeskrivelse.text[key],
+                                    lang=key)))
+
+        # remark
+        if hasattr(betydningsbeskrivelse, 'remark'):
+            for key in betydningsbeskrivelse.remark:
+                self._g.add((_betydningsbeskrivelse, SKOS.scopeNote,
+                            Literal(betydningsbeskrivelse.remark[key],
+                                    lang=key)))
+        # scope
+        if hasattr(betydningsbeskrivelse, 'scope'):
+            _scope = BNode()
+            if 'url' in betydningsbeskrivelse.scope:
+                self._g.add((_scope, RDFS.seeAlso,
+                            URIRef(betydningsbeskrivelse.scope['url'])))
+            if 'text' in betydningsbeskrivelse.scope:
+                _text = betydningsbeskrivelse.scope['text']
+                for key in _text:
+                    self._g.add((_scope, RDFS.label,
+                                Literal(_text[key], lang=key)))
+            self._g.add((_betydningsbeskrivelse, SKOSNO.omfang, _scope))
+
+        # relationtosource
+        if hasattr(betydningsbeskrivelse, 'relationtosource'):
+            # -
+            # sitatFraKilde = "quoteFromSource"
+            # basertPåKilde = "basedOnSource"
+            # egendefinert = "noSource"
+            # -
+            if (RelationToSource(betydningsbeskrivelse.relationtosource)
+               is RelationToSource.sitatFraKilde):
+                self._g.add((_betydningsbeskrivelse, SKOSNO.forholdTilKilde,
+                            SKOSNO.sitatFraKilde))
+            elif (RelationToSource(betydningsbeskrivelse.relationtosource)
+                  is RelationToSource.basertPåKilde):
+                self._g.add((_betydningsbeskrivelse, SKOSNO.forholdTilKilde,
+                            SKOSNO.basertPåKilde))
+            else:
+                self._g.add((_betydningsbeskrivelse, SKOSNO.forholdTilKilde,
+                            SKOSNO.egendefinert))
+
+        # source
+        if hasattr(betydningsbeskrivelse, 'source'):
+            _source = BNode()
+            if 'url' in betydningsbeskrivelse.source:
+                self._g.add((_source, RDFS.seeAlso,
+                            URIRef(betydningsbeskrivelse.source['url'])))
+            if 'text' in betydningsbeskrivelse.source:
+                _text = betydningsbeskrivelse.source['text']
+                for key in _text:
+                    self._g.add((_source, RDFS.label,
+                                Literal(_text[key], lang=key)))
+            self._g.add((_betydningsbeskrivelse, DCT.source, _source))
+
+        # modified
+        if hasattr(betydningsbeskrivelse, 'modified'):
+            self._g.add((_betydningsbeskrivelse, DCT.modified,
+                         Literal(betydningsbeskrivelse.modified,
+                                 datatype=XSD.date)))
+
+        # example
+        if hasattr(betydningsbeskrivelse, 'example'):
+            for key in betydningsbeskrivelse.example:
+                self._g.add((_betydningsbeskrivelse, SKOS.example,
+                             Literal(betydningsbeskrivelse.example[key],
+                                     lang=key)))
+
+        # Check type, and set correct property
+        if isinstance(betydningsbeskrivelse, Definition):
+            self._g.add((URIRef(self.identifier), SKOSNO.definisjon,
+                        _betydningsbeskrivelse))
+        else:
+            self._g.add((URIRef(self.identifier), SKOSNO.alternativFormulering,
+                        _betydningsbeskrivelse))
+        # ---
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class Concept +
+
+

A class representing a concept

+

Attributes

+
+
identifier
+
the uri identifying the concept
+
term
+
+

a dictionary describing the +anbefaltterm +, e.g.

+

{"name": {"en": "concept"}, "modified":"2020-01-01"}

+
+
alternativeterm
+
a dictionary describing the +tillattTerm
+
hiddenterm
+
a dictionary describing the +frarådetTerm
+
+
+ +Expand source code + +
class Concept:
+    """A class representing a concept
+
+
+    Attributes:
+        identifier: the uri identifying the concept
+        term: a dictionary describing the
+            [anbefaltterm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_anbefaltterm)
+            , e.g.\n
+            ```
+            {"name": {"en": "concept"}, "modified":"2020-01-01"}
+            ```
+        alternativeterm: a dictionary describing the
+            [tillattTerm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_tillattterm)
+
+        hiddenterm: a dictionary describing the
+            [frarådetTerm](https://doc.difi.no/data/begrep-skos-ap-no/#_begrep_frar%C3%A5detterm)
+
+    """
+
+    def __init__(self):
+        self._g = Graph()
+
+        self.seeAlso = []
+        self.replaces = []
+        self.replacedBy = []
+
+    @property
+    def identifier(self) -> str:
+        return self._identifier
+
+    @identifier.setter
+    def identifier(self, uri: str):
+        self._identifier = uri
+
+    @property
+    def term(self) -> dict:
+        return self._term
+
+    @term.setter
+    def term(self, term: dict):
+        self._term = term
+
+    @property
+    def alternativeterm(self) -> dict:
+        return self._alternativeterm
+
+    @alternativeterm.setter
+    def alternativeterm(self, alternativeterm: dict):
+        self._alternativeterm = alternativeterm
+
+    @property
+    def hiddenterm(self) -> dict:
+        return self._hiddenterm
+
+    @hiddenterm.setter
+    def hiddenterm(self, hiddenterm: dict):
+        self._hiddenterm = hiddenterm
+
+    @property
+    def datastrukturterm(self) -> dict:
+        return self._datastrukturterm
+
+    @datastrukturterm.setter
+    def datastrukturterm(self, datastrukturterm: dict):
+        self._datastrukturterm = datastrukturterm
+
+    @property
+    def subject(self) -> dict:
+        return self._subject
+
+    @subject.setter
+    def subject(self, subject: dict):
+        self._subject = subject
+
+    @property
+    def definition(self) -> Definition:
+        return self._definition
+
+    @definition.setter
+    def definition(self, definition: Definition):
+        self._definition = definition
+
+    @property
+    def alternativformulering(self) -> AlternativFormulering:
+        return self._alternativformulering
+
+    @alternativformulering.setter
+    def alternativformulering(self,
+                              alternativformulering: AlternativFormulering):
+        self._alternativformulering = alternativformulering
+
+    @property
+    def contactpoint(self) -> Contact:
+        return self._contactpoint
+
+    @contactpoint.setter
+    def contactpoint(self, contact: Contact):
+        self._contactpoint = contact
+
+    @property
+    def modified(self) -> date:
+        return self._modified
+
+    @modified.setter
+    def modified(self, modified: date):
+        self._modified = modified
+
+    @property
+    def bruksområde(self) -> dict:
+        return self._bruksområde
+
+    @bruksområde.setter
+    def bruksområde(self, bruksområde: dict):
+        self._bruksområde = bruksområde
+
+    @property
+    def validinperiod(self) -> dict:
+        return self._validinperiod
+
+    @validinperiod.setter
+    def validinperiod(self, validinperiod: dict):
+        self._validinperiod = validinperiod
+
+    @property
+    def publisher(self) -> str:
+        return self._publisher
+
+    @publisher.setter
+    def publisher(self, publisher: str):
+        self._publisher = publisher
+
+    @property
+    def seeAlso(self) -> list:
+        return self._seeAlso
+
+    @seeAlso.setter
+    def seeAlso(self, concepts: list):
+        self._seeAlso = concepts
+
+    @property
+    def replaces(self) -> list:
+        return self._replaces
+
+    @replaces.setter
+    def replaces(self, concepts: list):
+        self._replaces = concepts
+
+    @property
+    def replacedBy(self) -> list:
+        return self._replacedBy
+
+    @replacedBy.setter
+    def replacedBy(self, concepts: list):
+        self._replacedBy = concepts
+
+    @property
+    def related(self) -> AssociativeRelation:
+        return self._related
+
+    @related.setter
+    def related(self, ar: AssociativeRelation):
+        self._related = ar
+
+    @property
+    def generalizes(self) -> GenericRelation:
+        return self._generalizes
+
+    @generalizes.setter
+    def generalizes(self, gr: GenericRelation):
+        self._generalizes = gr
+
+    @property
+    def hasPart(self) -> PartitiveRelation:
+        return self._hasPart
+
+    @hasPart.setter
+    def hasPart(self, gr: PartitiveRelation):
+        self._hasPart = gr
+# ----------------------------------------------
+
+    def _to_graph(self) -> Graph:
+        """Transforms the concept to an rdf graph
+
+        Returns:
+            An RDF [graph](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#graph) representing the concept.
+        """
+
+        self._add_concept_to_graph()
+
+        return self._g
+
+    def to_rdf(self, format='text/turtle') -> str:
+        """Maps the concept to rdf and returns a serialization
+           as a string according to format
+
+        Args:
+            format: a valid serialization format\n
+                 - `text/turtle` (default)
+                 - `application/rdf+xml`
+                 - `application/ld+json`
+                 - `application/n-triples`
+                 - `text/n3`
+
+        Returns:
+            A serialization of the RDF graph, for example:
+            ```
+            @prefix dct: <http://purl.org/dc/terms/> .
+            @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+            @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+            @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
+            @prefix skosno: <https://data.norge.no/vocabulary/skosno#> .
+            @prefix xml: <http://www.w3.org/XML/1998/namespace> .
+            @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+            <http://example.com/concepts/1> a skos:Concept ;
+                    skosno:definisjon [ a skosno:Definisjon ;
+                    skosno:forholdTilKilde skosno:egendefinert ]
+                    .
+            ```
+
+           """
+
+        return self._to_graph().serialize(format=format)
+
+# ----------------------------------------------
+
+    def _add_concept_to_graph(self):
+        """Adds the concept to the Graph _g"""
+
+        self._g.bind('dct', DCT)
+        self._g.bind('skos', SKOS)
+        self._g.bind('skosxl', SKOSXL)
+        self._g.bind('vcard', VCARD)
+        self._g.bind('skosno', SKOSNO)
+        self._g.bind('dcat', DCAT)
+        self._g.bind('xsd', XSD)
+        self._g.bind('schema', SCHEMA)
+        self._g.bind('xkos', XKOS)
+
+        self._g.add((URIRef(self.identifier), RDF.type, SKOS.Concept))
+
+        # prefLabel
+        if hasattr(self, 'term'):
+            label = BNode()
+            self._g.add((label, RDF.type, SKOSXL.Label))
+            if 'name' in self.term:
+                _name = self.term['name']
+                for key in _name:
+                    self._g.add((label, SKOSXL.literalForm,
+                                 Literal(_name[key], lang=key)))
+            if 'modified' in self.term:
+                self._g.add((label, DCT.modified,
+                            Literal(self.term['modified'], datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier), SKOSXL.prefLabel, label))
+
+        # altLabel
+        if hasattr(self, 'alternativeterm'):
+            altLabel = BNode()
+            self._g.add((altLabel, RDF.type, SKOSXL.Label))
+            if 'name' in self.alternativeterm:
+                _name = self.alternativeterm['name']
+                for key in _name:
+                    for l in _name[key]:
+                        self._g.add((altLabel, SKOSXL.literalForm,
+                                     Literal(l, lang=key)))
+            if 'modified' in self.alternativeterm:
+                self._g.add((altLabel, DCT.modified,
+                             Literal(self.alternativeterm['modified'],
+                                     datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier), SKOSXL.altLabel, altLabel))
+
+        # hiddenLabel
+        if hasattr(self, 'hiddenterm'):
+            hiddenLabel = BNode()
+            self._g.add((hiddenLabel, RDF.type, SKOSXL.Label))
+            if 'name' in self.hiddenterm:
+                _name = self.hiddenterm['name']
+                for key in _name:
+                    for l in _name[key]:
+                        self._g.add((hiddenLabel, SKOSXL.literalForm,
+                                     Literal(l, lang=key)))
+            if 'modified' in self.hiddenterm:
+                self._g.add((hiddenLabel, DCT.modified,
+                             Literal(self.hiddenterm['modified'],
+                                     datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier),
+                         SKOSXL.hiddenLabel, hiddenLabel))
+
+        # datastrukturterm
+        if hasattr(self, 'datastrukturterm'):
+            datastrukturterm = BNode()
+            self._g.add((datastrukturterm, RDF.type, SKOSXL.Label))
+            if 'name' in self.datastrukturterm:
+                _name = self.datastrukturterm['name']
+                for key in _name:
+                    for l in _name[key]:
+                        self._g.add((datastrukturterm, SKOSXL.literalForm,
+                                     Literal(l, lang=key)))
+            if 'modified' in self.datastrukturterm:
+                self._g.add((datastrukturterm, DCT.modified,
+                             Literal(self.datastrukturterm['modified'],
+                                     datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier),
+                         SKOSNO.datastrukturterm, datastrukturterm))
+        # definition
+        if hasattr(self, 'definition'):
+            self._add_betydningsbeskrivelse_to_concept(self.definition)
+
+        # alternativformulering
+        if hasattr(self, 'alternativformulering'):
+            self._add_betydningsbeskrivelse_to_concept(
+                self.alternativformulering)
+
+        # publisher
+        if hasattr(self, 'publisher'):
+            self._g.add((URIRef(self.identifier), DCT.publisher,
+                         URIRef(self.publisher)))
+
+        # contactPoint
+        if hasattr(self, 'contactpoint'):
+            contact = self.contactpoint
+            contactPoint = BNode()
+            for s, p, o in contact._to_graph().triples((None, None, None)):
+                self._g.add((contactPoint, p, o))
+            self._g.add((URIRef(self.identifier), DCAT.contactPoint,
+                         contactPoint))
+
+        # subject
+        if hasattr(self, 'subject'):
+            for key in self.subject:
+                self._g.add((URIRef(self.identifier), DCT.subject,
+                             Literal(self.subject[key], lang=key)))
+
+        # modified
+        if hasattr(self, 'modified'):
+            self._g.add((URIRef(self.identifier), DCT.modified,
+                         Literal(self.modified, datatype=XSD.date)))
+
+        # bruksområde
+        if hasattr(self, 'bruksområde'):
+            for key in self.bruksområde:
+                for b in self.bruksområde[key]:
+                    self._g.add((URIRef(self.identifier), SKOSNO.bruksområde,
+                                 Literal(b, lang=key)))
+
+        # PeriodOfTime
+        if hasattr(self, 'validinperiod'):
+            periodOfTime = BNode()
+            self._g.add((periodOfTime, RDF.type, DCT.PeriodOfTime))
+            if 'startdate' in self.validinperiod:
+                self._g.add((periodOfTime, SCHEMA.startDate,
+                            Literal(self.validinperiod['startdate'],
+                                    datatype=XSD.date)))
+            if 'enddate' in self.validinperiod:
+                self._g.add((periodOfTime, SCHEMA.endDate,
+                            Literal(self.validinperiod['enddate'],
+                                    datatype=XSD.date)))
+            self._g.add((URIRef(self.identifier), DCT.temporal, periodOfTime))
+
+        # seeAlso
+        if hasattr(self, 'seeAlso'):
+            for c in self.seeAlso:
+                self._g.add((URIRef(self.identifier), RDFS.seeAlso,
+                            URIRef(c.identifier)))
+
+        # replaces
+        if hasattr(self, 'replaces'):
+            for c in self.replaces:
+                self._g.add((URIRef(self.identifier), DCT.replaces,
+                             URIRef(c.identifier)))
+
+        # replacedBy
+        if hasattr(self, 'replacedBy'):
+            for c in self.replacedBy:
+                self._g.add((URIRef(self.identifier), DCT.replacedBy,
+                             URIRef(c.identifier)))
+
+        # related
+        if hasattr(self, 'related'):
+            _related = self.related
+            ar = BNode()
+            for s, p, o in _related._to_graph().triples((None, None, None)):
+                self._g.add((ar, p, o))
+            self._g.add((URIRef(self.identifier), SKOS.related, ar))
+
+        # generalizes
+        if hasattr(self, 'generalizes'):
+            _generalizes = self.generalizes
+            ar = BNode()
+            for s, p, o in _generalizes._to_graph().triples((None, None, None)):
+                self._g.add((ar, p, o))
+            self._g.add((URIRef(self.identifier), XKOS.generalizes, ar))
+
+        # hasPart
+        if hasattr(self, 'hasPart'):
+            _hasPart = self.hasPart
+            ar = BNode()
+            for s, p, o in _hasPart._to_graph().triples((None, None, None)):
+                self._g.add((ar, p, o))
+            self._g.add((URIRef(self.identifier), XKOS.hasPart, ar))
+
+# ------------
+# Helper methods:
+
+    def _add_betydningsbeskrivelse_to_concept(self, betydningsbeskrivelse):
+        # ---
+        _betydningsbeskrivelse = BNode()
+
+        self._g.add((_betydningsbeskrivelse, RDF.type,
+                     betydningsbeskrivelse.type))
+
+        # text
+        if hasattr(betydningsbeskrivelse, 'text'):
+            for key in betydningsbeskrivelse.text:
+                self._g.add((_betydningsbeskrivelse, RDFS.label,
+                            Literal(betydningsbeskrivelse.text[key],
+                                    lang=key)))
+
+        # remark
+        if hasattr(betydningsbeskrivelse, 'remark'):
+            for key in betydningsbeskrivelse.remark:
+                self._g.add((_betydningsbeskrivelse, SKOS.scopeNote,
+                            Literal(betydningsbeskrivelse.remark[key],
+                                    lang=key)))
+        # scope
+        if hasattr(betydningsbeskrivelse, 'scope'):
+            _scope = BNode()
+            if 'url' in betydningsbeskrivelse.scope:
+                self._g.add((_scope, RDFS.seeAlso,
+                            URIRef(betydningsbeskrivelse.scope['url'])))
+            if 'text' in betydningsbeskrivelse.scope:
+                _text = betydningsbeskrivelse.scope['text']
+                for key in _text:
+                    self._g.add((_scope, RDFS.label,
+                                Literal(_text[key], lang=key)))
+            self._g.add((_betydningsbeskrivelse, SKOSNO.omfang, _scope))
+
+        # relationtosource
+        if hasattr(betydningsbeskrivelse, 'relationtosource'):
+            # -
+            # sitatFraKilde = "quoteFromSource"
+            # basertPåKilde = "basedOnSource"
+            # egendefinert = "noSource"
+            # -
+            if (RelationToSource(betydningsbeskrivelse.relationtosource)
+               is RelationToSource.sitatFraKilde):
+                self._g.add((_betydningsbeskrivelse, SKOSNO.forholdTilKilde,
+                            SKOSNO.sitatFraKilde))
+            elif (RelationToSource(betydningsbeskrivelse.relationtosource)
+                  is RelationToSource.basertPåKilde):
+                self._g.add((_betydningsbeskrivelse, SKOSNO.forholdTilKilde,
+                            SKOSNO.basertPåKilde))
+            else:
+                self._g.add((_betydningsbeskrivelse, SKOSNO.forholdTilKilde,
+                            SKOSNO.egendefinert))
+
+        # source
+        if hasattr(betydningsbeskrivelse, 'source'):
+            _source = BNode()
+            if 'url' in betydningsbeskrivelse.source:
+                self._g.add((_source, RDFS.seeAlso,
+                            URIRef(betydningsbeskrivelse.source['url'])))
+            if 'text' in betydningsbeskrivelse.source:
+                _text = betydningsbeskrivelse.source['text']
+                for key in _text:
+                    self._g.add((_source, RDFS.label,
+                                Literal(_text[key], lang=key)))
+            self._g.add((_betydningsbeskrivelse, DCT.source, _source))
+
+        # modified
+        if hasattr(betydningsbeskrivelse, 'modified'):
+            self._g.add((_betydningsbeskrivelse, DCT.modified,
+                         Literal(betydningsbeskrivelse.modified,
+                                 datatype=XSD.date)))
+
+        # example
+        if hasattr(betydningsbeskrivelse, 'example'):
+            for key in betydningsbeskrivelse.example:
+                self._g.add((_betydningsbeskrivelse, SKOS.example,
+                             Literal(betydningsbeskrivelse.example[key],
+                                     lang=key)))
+
+        # Check type, and set correct property
+        if isinstance(betydningsbeskrivelse, Definition):
+            self._g.add((URIRef(self.identifier), SKOSNO.definisjon,
+                        _betydningsbeskrivelse))
+        else:
+            self._g.add((URIRef(self.identifier), SKOSNO.alternativFormulering,
+                        _betydningsbeskrivelse))
+
+

Instance variables

+
+
var alternativeterm
+
+
+
+ +Expand source code + +
@property
+def alternativeterm(self) -> dict:
+    return self._alternativeterm
+
+
+
var alternativformulering
+
+
+
+ +Expand source code + +
@property
+def alternativformulering(self) -> AlternativFormulering:
+    return self._alternativformulering
+
+
+
var bruksområde
+
+
+
+ +Expand source code + +
@property
+def bruksområde(self) -> dict:
+    return self._bruksområde
+
+
+
var contactpoint
+
+
+
+ +Expand source code + +
@property
+def contactpoint(self) -> Contact:
+    return self._contactpoint
+
+
+
var datastrukturterm
+
+
+
+ +Expand source code + +
@property
+def datastrukturterm(self) -> dict:
+    return self._datastrukturterm
+
+
+
var definition
+
+
+
+ +Expand source code + +
@property
+def definition(self) -> Definition:
+    return self._definition
+
+
+
var generalizes
+
+
+
+ +Expand source code + +
@property
+def generalizes(self) -> GenericRelation:
+    return self._generalizes
+
+
+
var hasPart
+
+
+
+ +Expand source code + +
@property
+def hasPart(self) -> PartitiveRelation:
+    return self._hasPart
+
+
+
var hiddenterm
+
+
+
+ +Expand source code + +
@property
+def hiddenterm(self) -> dict:
+    return self._hiddenterm
+
+
+
var identifier
+
+
+
+ +Expand source code + +
@property
+def identifier(self) -> str:
+    return self._identifier
+
+
+
var modified
+
+
+
+ +Expand source code + +
@property
+def modified(self) -> date:
+    return self._modified
+
+
+
var publisher
+
+
+
+ +Expand source code + +
@property
+def publisher(self) -> str:
+    return self._publisher
+
+
+
var related
+
+
+
+ +Expand source code + +
@property
+def related(self) -> AssociativeRelation:
+    return self._related
+
+
+
var replacedBy
+
+
+
+ +Expand source code + +
@property
+def replacedBy(self) -> list:
+    return self._replacedBy
+
+
+
var replaces
+
+
+
+ +Expand source code + +
@property
+def replaces(self) -> list:
+    return self._replaces
+
+
+
var seeAlso
+
+
+
+ +Expand source code + +
@property
+def seeAlso(self) -> list:
+    return self._seeAlso
+
+
+
var subject
+
+
+
+ +Expand source code + +
@property
+def subject(self) -> dict:
+    return self._subject
+
+
+
var term
+
+
+
+ +Expand source code + +
@property
+def term(self) -> dict:
+    return self._term
+
+
+
var validinperiod
+
+
+
+ +Expand source code + +
@property
+def validinperiod(self) -> dict:
+    return self._validinperiod
+
+
+
+

Methods

+
+
+def to_rdf(self, format='text/turtle') +
+
+

Maps the concept to rdf and returns a serialization +as a string according to format

+

Args

+
+
format
+
+

a valid serialization format

+
    +
  • text/turtle (default)
  • +
  • application/rdf+xml
  • +
  • application/ld+json
  • +
  • application/n-triples
  • +
  • text/n3
  • +
+
+
+

Returns

+
+
A serialization of the RDF graph, for example:
+
 
+
+
@prefix dct: <http://purl.org/dc/terms/> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
+@prefix skosno: <https://data.norge.no/vocabulary/skosno#> .
+@prefix xml: <http://www.w3.org/XML/1998/namespace> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+<http://example.com/concepts/1> a skos:Concept ;
+        skosno:definisjon [ a skosno:Definisjon ;
+        skosno:forholdTilKilde skosno:egendefinert ]
+        .
+
+
+ +Expand source code + +
def to_rdf(self, format='text/turtle') -> str:
+    """Maps the concept to rdf and returns a serialization
+       as a string according to format
+
+    Args:
+        format: a valid serialization format\n
+             - `text/turtle` (default)
+             - `application/rdf+xml`
+             - `application/ld+json`
+             - `application/n-triples`
+             - `text/n3`
+
+    Returns:
+        A serialization of the RDF graph, for example:
+        ```
+        @prefix dct: <http://purl.org/dc/terms/> .
+        @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+        @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+        @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
+        @prefix skosno: <https://data.norge.no/vocabulary/skosno#> .
+        @prefix xml: <http://www.w3.org/XML/1998/namespace> .
+        @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+        <http://example.com/concepts/1> a skos:Concept ;
+                skosno:definisjon [ a skosno:Definisjon ;
+                skosno:forholdTilKilde skosno:egendefinert ]
+                .
+        ```
+
+       """
+
+    return self._to_graph().serialize(format=format)
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/conceptrelation.html b/docs/conceptrelation.html new file mode 100644 index 0000000..0308ebc --- /dev/null +++ b/docs/conceptrelation.html @@ -0,0 +1,165 @@ + + + + + + +concepttordf.conceptrelation API documentation + + + + + + + + + +
+
+
+

Module concepttordf.conceptrelation

+
+
+
+ +Expand source code + +
from abc import ABC
+from datetime import date
+from rdflib import Graph, Literal, BNode, Namespace
+
+SKOSNO = Namespace('https://data.norge.no/vocabulary/skosno#')
+DCT = Namespace('http://purl.org/dc/terms/')
+XSD = Namespace('http://www.w3.org/2001/XMLSchema#')
+
+
+class ConceptRelation(ABC):
+
+    def __init__(self):
+        self._g = Graph()
+        self._relation = BNode()
+        self._g.bind('skosno', SKOSNO)
+        self._g.bind('dct', DCT)
+        self._g.bind('xsd', XSD)
+
+    @property
+    def modified(self) -> date:
+        return self._modified
+
+    @modified.setter
+    def modified(self, modified: date):
+        self._modified = modified
+
+# ---
+    def _add_relation_to_graph(self):
+
+        # modified
+        if hasattr(self, 'modified'):
+            self._g.add((self._relation, DCT.modified,
+                         Literal(self.modified, datatype=XSD.date)))
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class ConceptRelation +
+
+

Helper class that provides a standard way to create an ABC using +inheritance.

+
+ +Expand source code + +
class ConceptRelation(ABC):
+
+    def __init__(self):
+        self._g = Graph()
+        self._relation = BNode()
+        self._g.bind('skosno', SKOSNO)
+        self._g.bind('dct', DCT)
+        self._g.bind('xsd', XSD)
+
+    @property
+    def modified(self) -> date:
+        return self._modified
+
+    @modified.setter
+    def modified(self, modified: date):
+        self._modified = modified
+
+# ---
+    def _add_relation_to_graph(self):
+
+        # modified
+        if hasattr(self, 'modified'):
+            self._g.add((self._relation, DCT.modified,
+                         Literal(self.modified, datatype=XSD.date)))
+
+

Ancestors

+
    +
  • abc.ABC
  • +
+

Subclasses

+ +

Instance variables

+
+
var modified
+
+
+
+ +Expand source code + +
@property
+def modified(self) -> date:
+    return self._modified
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/contact.html b/docs/contact.html new file mode 100644 index 0000000..cb0eb09 --- /dev/null +++ b/docs/contact.html @@ -0,0 +1,334 @@ + + + + + + +concepttordf.contact API documentation + + + + + + + + + +
+
+
+

Module concepttordf.contact

+
+
+
+ +Expand source code + +
from rdflib import Graph, Literal, BNode, Namespace, RDF, URIRef
+
+DCT = Namespace('http://purl.org/dc/terms/')
+SKOSXL = Namespace('http://www.w3.org/2008/05/skos-xl#')
+VCARD = Namespace('http://www.w3.org/2006/vcard/ns#')
+SKOS = Namespace('http://www.w3.org/2004/02/skos/core#')
+SKOSNO = Namespace('https://data.norge.no/vocabulary/skosno#')
+
+
+class Contact:
+    """A class representing a contact """
+
+    def __init__(self):
+        self._g = Graph()
+
+    @property
+    def name(self) -> dict:
+        return self._name
+
+    @name.setter
+    def name(self, name: dict):
+        self._name = name
+
+    @property
+    def email(self) -> str:
+        return self._email
+
+    @email.setter
+    def email(self, email: str):
+        self._email = email
+
+    @property
+    def telephone(self) -> str:
+        return self._telephone
+
+    @telephone.setter
+    def telephone(self, telephone: str):
+        self._telephone = telephone
+
+    @property
+    def url(self) -> str:
+        return self._url
+
+    @url.setter
+    def url(self, url: str):
+        self._url = url
+
+    def _to_graph(self) -> Graph:
+
+        self._add_contact_to_graph()
+
+        return self._g
+
+    def to_rdf(self, format='text/turtle') -> str:
+        """Maps the contact to rdf and returns a serialization
+           as a string according to format"""
+
+        return self._to_graph().serialize(format=format)
+
+    # -----
+
+    def _add_contact_to_graph(self):
+        """Adds the concept to the Graph _g"""
+
+        self._g.bind('vcard', VCARD)
+
+        if hasattr(self, 'identifier'):
+            _self = URIRef(self.identifier)
+        else:
+            _self = BNode()
+
+        self._g.add((_self, RDF.type, VCARD.Organization))
+
+        # name
+        if hasattr(self, 'name'):
+            for key in self.name:
+                self._g.add((_self, VCARD.hasOrganizationName,
+                            Literal(self.name[key], lang=key)))
+
+        # email
+        if hasattr(self, 'email'):
+            self._g.add((_self, VCARD.hasEmail,
+                        URIRef('mailto:' + self.email)))
+
+        # telephone
+        if hasattr(self, 'telephone'):
+            self._g.add((_self, VCARD.hasTelephone,
+                        URIRef('tel:' + self.telephone)))
+
+        # url
+        if hasattr(self, 'url'):
+            self._g.add((_self, VCARD.hasURL,
+                        URIRef(self.url)))
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class Contact +
+
+

A class representing a contact

+
+ +Expand source code + +
class Contact:
+    """A class representing a contact """
+
+    def __init__(self):
+        self._g = Graph()
+
+    @property
+    def name(self) -> dict:
+        return self._name
+
+    @name.setter
+    def name(self, name: dict):
+        self._name = name
+
+    @property
+    def email(self) -> str:
+        return self._email
+
+    @email.setter
+    def email(self, email: str):
+        self._email = email
+
+    @property
+    def telephone(self) -> str:
+        return self._telephone
+
+    @telephone.setter
+    def telephone(self, telephone: str):
+        self._telephone = telephone
+
+    @property
+    def url(self) -> str:
+        return self._url
+
+    @url.setter
+    def url(self, url: str):
+        self._url = url
+
+    def _to_graph(self) -> Graph:
+
+        self._add_contact_to_graph()
+
+        return self._g
+
+    def to_rdf(self, format='text/turtle') -> str:
+        """Maps the contact to rdf and returns a serialization
+           as a string according to format"""
+
+        return self._to_graph().serialize(format=format)
+
+    # -----
+
+    def _add_contact_to_graph(self):
+        """Adds the concept to the Graph _g"""
+
+        self._g.bind('vcard', VCARD)
+
+        if hasattr(self, 'identifier'):
+            _self = URIRef(self.identifier)
+        else:
+            _self = BNode()
+
+        self._g.add((_self, RDF.type, VCARD.Organization))
+
+        # name
+        if hasattr(self, 'name'):
+            for key in self.name:
+                self._g.add((_self, VCARD.hasOrganizationName,
+                            Literal(self.name[key], lang=key)))
+
+        # email
+        if hasattr(self, 'email'):
+            self._g.add((_self, VCARD.hasEmail,
+                        URIRef('mailto:' + self.email)))
+
+        # telephone
+        if hasattr(self, 'telephone'):
+            self._g.add((_self, VCARD.hasTelephone,
+                        URIRef('tel:' + self.telephone)))
+
+        # url
+        if hasattr(self, 'url'):
+            self._g.add((_self, VCARD.hasURL,
+                        URIRef(self.url)))
+
+

Instance variables

+
+
var email
+
+
+
+ +Expand source code + +
@property
+def email(self) -> str:
+    return self._email
+
+
+
var name
+
+
+
+ +Expand source code + +
@property
+def name(self) -> dict:
+    return self._name
+
+
+
var telephone
+
+
+
+ +Expand source code + +
@property
+def telephone(self) -> str:
+    return self._telephone
+
+
+
var url
+
+
+
+ +Expand source code + +
@property
+def url(self) -> str:
+    return self._url
+
+
+
+

Methods

+
+
+def to_rdf(self, format='text/turtle') +
+
+

Maps the contact to rdf and returns a serialization +as a string according to format

+
+ +Expand source code + +
def to_rdf(self, format='text/turtle') -> str:
+    """Maps the contact to rdf and returns a serialization
+       as a string according to format"""
+
+    return self._to_graph().serialize(format=format)
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/definition.html b/docs/definition.html new file mode 100644 index 0000000..2c99569 --- /dev/null +++ b/docs/definition.html @@ -0,0 +1,101 @@ + + + + + + +concepttordf.definition API documentation + + + + + + + + + +
+
+
+

Module concepttordf.definition

+
+
+
+ +Expand source code + +
from .betydningsbeskrivelse import Betydningsbeskrivelse
+from rdflib import Namespace
+
+SKOSNO = Namespace('https://data.norge.no/vocabulary/skosno#')
+
+
+class Definition(Betydningsbeskrivelse):
+
+    def __init__(self):
+        super().__init__()
+        self.type = SKOSNO.Definisjon
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class Definition +
+
+

Helper class that provides a standard way to create an ABC using +inheritance.

+
+ +Expand source code + +
class Definition(Betydningsbeskrivelse):
+
+    def __init__(self):
+        super().__init__()
+        self.type = SKOSNO.Definisjon
+
+

Ancestors

+ +
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/genericrelation.html b/docs/genericrelation.html new file mode 100644 index 0000000..049ec20 --- /dev/null +++ b/docs/genericrelation.html @@ -0,0 +1,213 @@ + + + + + + +concepttordf.genericrelation API documentation + + + + + + + + + +
+
+
+

Module concepttordf.genericrelation

+
+
+
+ +Expand source code + +
from .conceptrelation import ConceptRelation
+from rdflib import Graph, Literal, Namespace, RDF, URIRef
+from typing import List
+
+SKOSNO = Namespace('https://data.norge.no/vocabulary/skosno#')
+DCT = Namespace('http://purl.org/dc/terms/')
+XSD = Namespace('http://www.w3.org/2001/XMLSchema#')
+
+
+class GenericRelation(ConceptRelation):
+
+    def __init__(self):
+        self._genericconcepts = []
+        super().__init__()
+
+    @property
+    def criterium(self) -> dict:
+        return self._criterium
+
+    @criterium.setter
+    def criterium(self, criterium: dict):
+        self._criterium = criterium
+
+    @property
+    def genericconcepts(self) -> List:
+        return self._genericconcepts
+# ---
+
+    def _to_graph(self) -> Graph:
+
+        self._add_relation_to_graph()
+
+        return self._g
+
+# ---
+    def _add_relation_to_graph(self):
+
+        super(GenericRelation, self)._add_relation_to_graph()
+
+        self._g.add((self._relation, RDF.type, SKOSNO.GeneriskRelasjon))
+
+        # criterium
+        if hasattr(self, 'criterium'):
+            for key in self.criterium:
+                self._g.add((self._relation, SKOSNO.inndelingskriterium,
+                            Literal(self.criterium[key], lang=key)))
+
+        # genericconcepts
+        if hasattr(self, 'genericconcepts'):
+            # breakpoint()
+            for ac in self.genericconcepts:
+                self._g.add((self._relation, SKOSNO.overordnetBegrep,
+                            URIRef(ac)))
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class GenericRelation +
+
+

Helper class that provides a standard way to create an ABC using +inheritance.

+
+ +Expand source code + +
class GenericRelation(ConceptRelation):
+
+    def __init__(self):
+        self._genericconcepts = []
+        super().__init__()
+
+    @property
+    def criterium(self) -> dict:
+        return self._criterium
+
+    @criterium.setter
+    def criterium(self, criterium: dict):
+        self._criterium = criterium
+
+    @property
+    def genericconcepts(self) -> List:
+        return self._genericconcepts
+# ---
+
+    def _to_graph(self) -> Graph:
+
+        self._add_relation_to_graph()
+
+        return self._g
+
+# ---
+    def _add_relation_to_graph(self):
+
+        super(GenericRelation, self)._add_relation_to_graph()
+
+        self._g.add((self._relation, RDF.type, SKOSNO.GeneriskRelasjon))
+
+        # criterium
+        if hasattr(self, 'criterium'):
+            for key in self.criterium:
+                self._g.add((self._relation, SKOSNO.inndelingskriterium,
+                            Literal(self.criterium[key], lang=key)))
+
+        # genericconcepts
+        if hasattr(self, 'genericconcepts'):
+            # breakpoint()
+            for ac in self.genericconcepts:
+                self._g.add((self._relation, SKOSNO.overordnetBegrep,
+                            URIRef(ac)))
+
+

Ancestors

+ +

Instance variables

+
+
var criterium
+
+
+
+ +Expand source code + +
@property
+def criterium(self) -> dict:
+    return self._criterium
+
+
+
var genericconcepts
+
+
+
+ +Expand source code + +
@property
+def genericconcepts(self) -> List:
+    return self._genericconcepts
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..7273ebf --- /dev/null +++ b/docs/index.html @@ -0,0 +1,200 @@ + + + + + + +concepttordf API documentation + + + + + + + + + +
+
+
+

Module concepttordf

+
+
+

Concept collection to rdf

+

This library maps a concept collection to skos according to +SKOS-AP-NO, +a Norwegian application profile for SKOS.

+

The library wraps rdflib. +The following serialization formats are available:

+
    +
  • text/turtle
  • +
  • application/rdf+xml
  • +
  • application/ld+json
  • +
  • application/n-triples
  • +
  • text/n3
  • +
+

Typical usage example

+
from concepttordf import Collection, Concept, Definition
+
+# Create collection object
+collection = Collection()
+collection.identifier = "http://example.com/collections/1"
+collection.name = {"en": "A concept collection"}
+collection.name = {"nb": "En begrepssamling"}
+collection.publisher = "https://example.com/publishers/1"
+
+# Create a concept:
+c = Concept()
+c.identifier = "http://example.com/concepts/1"
+c.term = {"name": {"nb": "inntekt", "en": "income"}}
+definition = Definition()
+definition.text = {"nb": "ting man skulle hatt mer av",
+                   "en": "something you want more of"}
+c.definition = definition
+
+# Add concept to collection:
+collection.members.append(c)
+
+# get rdf representation in turtle (default)
+rdf = collection.to_rdf()
+print(rdf.decode())
+
+
+ +Expand source code + +
"""Concept collection to rdf
+
+This library maps a concept collection to skos according to
+[SKOS-AP-NO](https://doc.difi.no/data/begrep-skos-ap-no/),
+a Norwegian application profile for [SKOS](https://www.w3.org/TR/skos-primer/).
+
+The library wraps [rdflib](https://rdflib.readthedocs.io/en/stable/).
+The following serialization formats are available:\n
+ - `text/turtle`
+ - `application/rdf+xml`
+ - `application/ld+json`
+ - `application/n-triples`
+ - `text/n3`
+
+Typical usage example
+
+    from concepttordf import Collection, Concept, Definition
+
+    # Create collection object
+    collection = Collection()
+    collection.identifier = "http://example.com/collections/1"
+    collection.name = {"en": "A concept collection"}
+    collection.name = {"nb": "En begrepssamling"}
+    collection.publisher = "https://example.com/publishers/1"
+
+    # Create a concept:
+    c = Concept()
+    c.identifier = "http://example.com/concepts/1"
+    c.term = {"name": {"nb": "inntekt", "en": "income"}}
+    definition = Definition()
+    definition.text = {"nb": "ting man skulle hatt mer av",
+                       "en": "something you want more of"}
+    c.definition = definition
+
+    # Add concept to collection:
+    collection.members.append(c)
+
+    # get rdf representation in turtle (default)
+    rdf = collection.to_rdf()
+    print(rdf.decode())
+"""
+from .alternativformulering import AlternativFormulering
+from .associativerelation import AssociativeRelation
+from .betydningsbeskrivelse import Betydningsbeskrivelse
+from .collection import Collection
+from .concept import Concept
+from .conceptrelation import ConceptRelation
+from .contact import Contact
+from .definition import Definition
+from .genericrelation import GenericRelation
+from .partitiverelation import PartitiveRelation
+
+
+
+

Sub-modules

+
+
concepttordf.alternativformulering
+
+
+
+
concepttordf.associativerelation
+
+
+
+
concepttordf.betydningsbeskrivelse
+
+
+
+
concepttordf.collection
+
+
+
+
concepttordf.concept
+
+
+
+
concepttordf.conceptrelation
+
+
+
+
concepttordf.contact
+
+
+
+
concepttordf.definition
+
+
+
+
concepttordf.genericrelation
+
+
+
+
concepttordf.partitiverelation
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/docs/partitiverelation.html b/docs/partitiverelation.html new file mode 100644 index 0000000..ebcf61f --- /dev/null +++ b/docs/partitiverelation.html @@ -0,0 +1,213 @@ + + + + + + +concepttordf.partitiverelation API documentation + + + + + + + + + +
+
+
+

Module concepttordf.partitiverelation

+
+
+
+ +Expand source code + +
from .conceptrelation import ConceptRelation
+from rdflib import Graph, Literal, Namespace, RDF, URIRef
+from typing import List
+
+SKOSNO = Namespace('https://data.norge.no/vocabulary/skosno#')
+DCT = Namespace('http://purl.org/dc/terms/')
+XSD = Namespace('http://www.w3.org/2001/XMLSchema#')
+
+
+class PartitiveRelation(ConceptRelation):
+
+    def __init__(self):
+        self._partconcepts = []
+        super().__init__()
+
+    @property
+    def criterium(self) -> dict:
+        return self._criterium
+
+    @criterium.setter
+    def criterium(self, criterium: dict):
+        self._criterium = criterium
+
+    @property
+    def partconcepts(self) -> List:
+        return self._partconcepts
+# ---
+
+    def _to_graph(self) -> Graph:
+
+        self._add_relation_to_graph()
+
+        return self._g
+
+# ---
+    def _add_relation_to_graph(self):
+
+        super(PartitiveRelation, self)._add_relation_to_graph()
+
+        self._g.add((self._relation, RDF.type, SKOSNO.PartitivRelasjon))
+
+        # criterium
+        if hasattr(self, 'criterium'):
+            for key in self.criterium:
+                self._g.add((self._relation, SKOSNO.inndelingskriterium,
+                            Literal(self.criterium[key], lang=key)))
+
+        # partconcepts
+        if hasattr(self, 'partconcepts'):
+            # breakpoint()
+            for ac in self.partconcepts:
+                self._g.add((self._relation, SKOSNO.underordnetBegrep,
+                            URIRef(ac)))
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class PartitiveRelation +
+
+

Helper class that provides a standard way to create an ABC using +inheritance.

+
+ +Expand source code + +
class PartitiveRelation(ConceptRelation):
+
+    def __init__(self):
+        self._partconcepts = []
+        super().__init__()
+
+    @property
+    def criterium(self) -> dict:
+        return self._criterium
+
+    @criterium.setter
+    def criterium(self, criterium: dict):
+        self._criterium = criterium
+
+    @property
+    def partconcepts(self) -> List:
+        return self._partconcepts
+# ---
+
+    def _to_graph(self) -> Graph:
+
+        self._add_relation_to_graph()
+
+        return self._g
+
+# ---
+    def _add_relation_to_graph(self):
+
+        super(PartitiveRelation, self)._add_relation_to_graph()
+
+        self._g.add((self._relation, RDF.type, SKOSNO.PartitivRelasjon))
+
+        # criterium
+        if hasattr(self, 'criterium'):
+            for key in self.criterium:
+                self._g.add((self._relation, SKOSNO.inndelingskriterium,
+                            Literal(self.criterium[key], lang=key)))
+
+        # partconcepts
+        if hasattr(self, 'partconcepts'):
+            # breakpoint()
+            for ac in self.partconcepts:
+                self._g.add((self._relation, SKOSNO.underordnetBegrep,
+                            URIRef(ac)))
+
+

Ancestors

+ +

Instance variables

+
+
var criterium
+
+
+
+ +Expand source code + +
@property
+def criterium(self) -> dict:
+    return self._criterium
+
+
+
var partconcepts
+
+
+
+ +Expand source code + +
@property
+def partconcepts(self) -> List:
+    return self._partconcepts
+
+
+
+
+
+
+
+ +
+ + + + + \ No newline at end of file diff --git a/setup.py b/setup.py index 8db78d8..8997c8e 100644 --- a/setup.py +++ b/setup.py @@ -5,13 +5,18 @@ setuptools.setup( name="concepttordf", - version="1.0.0.rc4", + version="1.0.0.rc5", author="Stig B. Dørmænen", author_email="sbd@digdir.no", description=( "A small Python library for mapping a concept collection" " to the skos-ap-no specification" ), + project_urls={ + 'Documentation': 'https://Informasjonsforvaltning.github.io/concepttordf', + 'Source': 'https://github.com/Informasjonsforvaltning/concepttordf', + 'Tracker': 'https://github.com/Informasjonsforvaltning/concepttordf/issues' + }, long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/Informasjonsforvaltning/concepttordf", diff --git a/tests/test_collection.py b/tests/test_collection.py index 23a19ac..c896cae 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -40,10 +40,10 @@ def test_collection_to_rdf_should_return_skos_collection(): # Test g1 = Graph() - g1.parse(data=data, format='turtle') + g1.parse(data=data, format='text/turtle') # _dump_turtle(g1) g2 = Graph().parse("tests/collection.ttl", - format='turtle', encoding='utf-8') + format='text/turtle') _isomorphic = isomorphic(g1, g2) if not _isomorphic: @@ -83,10 +83,10 @@ def test_collection_to_rdf_should_return_skos_collection_with_no_concepts(): # Test g1 = Graph() - g1.parse(data=data, format='turtle') + g1.parse(data=data, format='text/turtle') # _dump_turtle(g1) g2 = Graph().parse("tests/collection_excluding_concepts.ttl", - format='turtle', encoding='utf-8') + format='text/turtle') _isomorphic = isomorphic(g1, g2) if not _isomorphic: @@ -109,12 +109,12 @@ def _dump_diff(g1, g2): def _dump_turtle_sorted(g): - for l in sorted(g.serialize(format='turtle').splitlines()): + for l in sorted(g.serialize(format='text/turtle').splitlines()): if l: print(l.decode()) def _dump_turtle(g): - for l in g.serialize(format='turtle').splitlines(): + for l in g.serialize(format='text/turtle').splitlines(): if l: print(l.decode()) diff --git a/tests/test_concept.py b/tests/test_concept.py index f55dd1d..1aee04c 100644 --- a/tests/test_concept.py +++ b/tests/test_concept.py @@ -7,7 +7,8 @@ import json from rdflib import Graph from rdflib.compare import isomorphic, graph_diff -# import pytest +from rdflib.plugin import PluginException +import pytest # @pytest.mark.skip(reason="no way of currently testing this") @@ -33,9 +34,9 @@ def test_simple_concept_to_rdf_should_return_skos_concept(): concept.contactpoint = contact g1 = Graph() - g1.parse(data=concept.to_rdf(), format='turtle') + g1.parse(data=concept.to_rdf(), format='text/turtle') # _dump_turtle(g1) - g2 = Graph().parse("tests/concept.ttl", format='turtle', encoding='utf-8') + g2 = Graph().parse("tests/concept.ttl", format='text/turtle') _isomorphic = isomorphic(g1, g2) if not _isomorphic: @@ -128,10 +129,10 @@ def test_concept_to_rdf_should_return_skos_concept(): # -- g1 = Graph() - g1.parse(data=concept.to_rdf(), format='turtle') + g1.parse(data=concept.to_rdf(), format='text/turtle') # _dump_turtle(g1) g2 = Graph().parse("tests/completeconcept.ttl", - format='turtle', encoding='utf-8') + format='text/turtle') _isomorphic = isomorphic(g1, g2) if not _isomorphic: @@ -155,7 +156,7 @@ def test_noSource_to_rdf_should_return_skos_definition(): concept.definition = definition g1 = Graph() - g1.parse(data=concept.to_rdf(), format='turtle') + g1.parse(data=concept.to_rdf(), format='text/turtle') # _dump_turtle(g1) # - src = ''' @@ -172,7 +173,7 @@ def test_noSource_to_rdf_should_return_skos_definition(): skosno:forholdTilKilde skosno:egendefinert ] . ''' # - - g2 = Graph().parse(data=src, format='turtle', encoding='utf-8') + g2 = Graph().parse(data=src, format='text/turtle') _isomorphic = isomorphic(g1, g2) if not _isomorphic: @@ -197,7 +198,7 @@ def test_quoteFromSource_to_rdf_should_return_skos_definition(): concept.definition = definition g1 = Graph() - g1.parse(data=concept.to_rdf(), format='turtle') + g1.parse(data=concept.to_rdf(), format='text/turtle') # _dump_turtle(g1) # - src = ''' @@ -219,7 +220,7 @@ def test_quoteFromSource_to_rdf_should_return_skos_definition(): ] . ''' # - - g2 = Graph().parse(data=src, format='turtle', encoding='utf-8') + g2 = Graph().parse(data=src, format='text/turtle') _isomorphic = isomorphic(g1, g2) if not _isomorphic: @@ -227,6 +228,33 @@ def test_quoteFromSource_to_rdf_should_return_skos_definition(): pass assert _isomorphic + +def test_serialization_formats_that_should_work(): + concept = Concept() + concept.identifier = 'http://example.com/concepts/1' + TURTLE = 'text/turtle' + XML = 'application/rdf+xml' + JSONLD = 'application/ld+json' + NT = 'application/n-triples' + N3 = 'text/n3' + + _g = Graph() + _g.parse(data=concept.to_rdf(format=TURTLE), format=TURTLE) + _g.parse(data=concept.to_rdf(format=XML), format=XML) + _g.parse(data=concept.to_rdf(format=JSONLD), format=JSONLD) + _g.parse(data=concept.to_rdf(format=NT), format=NT) + _g.parse(data=concept.to_rdf(format=N3), format=N3) + + +def test_serialization_format_that_should_fail(): + concept = Concept() + concept.identifier = 'http://example.com/concepts/1' + + _g = Graph() + with pytest.raises(PluginException): + _g.parse(data=concept.to_rdf(format='should_fail')) + + # ---------------------------------------------------------------------- # # Utils for displaying debug information @@ -242,12 +270,12 @@ def _dump_diff(g1, g2): def _dump_turtle_sorted(g): - for l in sorted(g.serialize(format='turtle').splitlines()): + for l in sorted(g.serialize(format='text/turtle').splitlines()): if l: print(l.decode()) def _dump_turtle(g): - for l in g.serialize(format='turtle').splitlines(): + for l in g.serialize(format='text/turtle').splitlines(): if l: print(l.decode()) diff --git a/tests/test_contact.py b/tests/test_contact.py index aa8dee7..9c65b55 100644 --- a/tests/test_contact.py +++ b/tests/test_contact.py @@ -16,8 +16,8 @@ def test_contact_to_rdf_should_return_skos_contact(): contact.telephone = _contact['telephone'] g1 = Graph() - g1.parse(data=contact.to_rdf(), format='turtle') - g2 = Graph().parse("tests/contact.ttl", format='turtle', encoding='utf-8') + g1.parse(data=contact.to_rdf(), format='text/turtle') + g2 = Graph().parse("tests/contact.ttl", format='text/turtle') _isomorphic = isomorphic(g1, g2) if not _isomorphic: @@ -37,8 +37,8 @@ def test_contact_without_id_to_rdf_should_return_skos_contact(): contact.telephone = _contact['telephone'] g1 = Graph() - g1.parse(data=contact.to_rdf(), format='turtle') - g2 = Graph().parse("tests/contact.ttl", format='turtle', encoding='utf-8') + g1.parse(data=contact.to_rdf(), format='text/turtle') + g2 = Graph().parse("tests/contact.ttl", format='text/turtle') assert len(g1) == len(g2) @@ -57,12 +57,12 @@ def _dump_diff(g1, g2): def _dump_turtle_sorted(g): - for l in sorted(g.serialize(format='turtle').splitlines()): + for l in sorted(g.serialize(format='text/turtle').splitlines()): if l: print(l.decode()) def _dump_turtle(g): - for l in g.serialize(format='turtle').splitlines(): + for l in g.serialize(format='text/turtle').splitlines(): if l: print(l.decode())