Skip to content

Commit

Permalink
feat: improve prefix handling in json ontos (DEV-572) (#164)
Browse files Browse the repository at this point in the history
* 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"
  • Loading branch information
jnussbaum committed Feb 28, 2022
1 parent 5802db2 commit 8610885
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/dsp-tools-create-ontologies.md
Expand Up @@ -905,5 +905,5 @@ it is necessary to reference entities that are defined elsewhere. The following
[prefixes](dsp-tools-create.md#prefixes-object) and the prefix must be identical to the ontology's `name`.
- A different ontology defined in the same file: Within one data model file, multiple ontologies can be defined.
These will be created in the exact order they appear in the `ontologies` array. Once an ontology has been created,
it can be referenced by the following ontologies, provided it is added in the
[prefixes](dsp-tools-create.md#prefixes-object).
it can be referenced by the following ontologies via its name: `first-onto:hasName`. It is not necessary to add
`first-onto` to the prefixes.
4 changes: 2 additions & 2 deletions docs/dsp-tools-create.md
Expand Up @@ -66,8 +66,8 @@ full qualified IRI each time it is used. So, instead of writing a property calle
}
```

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

### "$schema" object

Expand Down
2 changes: 1 addition & 1 deletion knora/dsplib/models/helpers.py
Expand Up @@ -162,7 +162,7 @@ def __init__(self, context: Optional[dict[str, str]] = None):
# add ontologies from context, if any
if context:
for prefix, onto in context.items():
self._context[prefix] = OntoInfo(onto.removesuffix('#'), onto.endswith('#'))
self._context[prefix] = OntoInfo(onto.removesuffix('#'), onto.endswith('#') or onto.endswith('/v2'))

# add standard ontologies (rdf, rdfs, owl, xsl)
for k, v in self.base_ontologies.items():
Expand Down
1 change: 1 addition & 0 deletions knora/dsplib/utils/onto_create_ontology.py
Expand Up @@ -398,6 +398,7 @@ def create_ontology(input_file: str,
project=project,
label=ontology["label"],
name=ontology_name).create()
context.add_context(new_ontology.name, new_ontology.id + ('#' if not new_ontology.id.endswith('#') else ''))
last_modification_date = new_ontology.lastModificationDate
if verbose:
print(f"Created ontology '{ontology_name}'.")
Expand Down

0 comments on commit 8610885

Please sign in to comment.