Skip to content

Commit 8610885

Browse files
authored
feat: improve prefix handling in json ontos (DEV-572) (#164)
* implement first step of issue description * implement second step of issue description * adapt docs * only set hashtag to true if onto ends with "#" or "/v2"
1 parent 5802db2 commit 8610885

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎docs/dsp-tools-create-ontologies.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,5 +905,5 @@ it is necessary to reference entities that are defined elsewhere. The following
905905
[prefixes](dsp-tools-create.md#prefixes-object) and the prefix must be identical to the ontology's `name`.
906906
- A different ontology defined in the same file: Within one data model file, multiple ontologies can be defined.
907907
These will be created in the exact order they appear in the `ontologies` array. Once an ontology has been created,
908-
it can be referenced by the following ontologies, provided it is added in the
909-
[prefixes](dsp-tools-create.md#prefixes-object).
908+
it can be referenced by the following ontologies via its name: `first-onto:hasName`. It is not necessary to add
909+
`first-onto` to the prefixes.

‎docs/dsp-tools-create.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ full qualified IRI each time it is used. So, instead of writing a property calle
6666
}
6767
```
6868

69-
Note that prefixes can be defined for the ontologies defined in this file, but this is only necessary if the ontology
70-
needs to be referred to explicitly by another ontology within the same file.
69+
It is not necessary to define prefixes for the ontologies that are defined in this file. Ontologies in the same
70+
file can refer to each other via their name. See also [here](./dsp-tools-create-ontologies.md#referencing-ontologies).
7171

7272
### "$schema" object
7373

‎knora/dsplib/models/helpers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def __init__(self, context: Optional[dict[str, str]] = None):
162162
# add ontologies from context, if any
163163
if context:
164164
for prefix, onto in context.items():
165-
self._context[prefix] = OntoInfo(onto.removesuffix('#'), onto.endswith('#'))
165+
self._context[prefix] = OntoInfo(onto.removesuffix('#'), onto.endswith('#') or onto.endswith('/v2'))
166166

167167
# add standard ontologies (rdf, rdfs, owl, xsl)
168168
for k, v in self.base_ontologies.items():

‎knora/dsplib/utils/onto_create_ontology.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def create_ontology(input_file: str,
398398
project=project,
399399
label=ontology["label"],
400400
name=ontology_name).create()
401+
context.add_context(new_ontology.name, new_ontology.id + ('#' if not new_ontology.id.endswith('#') else ''))
401402
last_modification_date = new_ontology.lastModificationDate
402403
if verbose:
403404
print(f"Created ontology '{ontology_name}'.")

0 commit comments

Comments
 (0)