Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2-ontologies): add remove cardinalities from class if property not used in resources (DSP-1700) #1869

Merged
merged 32 commits into from Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ce591c7
feat (v2-ontologies): improve removing cardinalities from class
subotic Jun 5, 2021
ebed616
refactor(v2-ontology): move things into subpackage (ongoing)
subotic Jun 17, 2021
07ff0d7
Merge branch 'main' into wip/DSP-1700-Remove-cardinalities-from-class
subotic Jun 17, 2021
e0782ff
refactor(v2-ontology): move things into subpackage (ongoing)
subotic Jun 17, 2021
130d2c6
refactor(v2-ontology): move things into subpackage (ongoing)
subotic Jun 18, 2021
2e7c7d3
refactor(v2-ontology): move things into subpackage
subotic Jun 19, 2021
d7e36f7
chore(scalafmt): add additional format settings
subotic Jun 21, 2021
0461e70
refactor(v2-ontology): move things into subpackage
subotic Jun 21, 2021
d9b821a
refactor(v2-ontology): move things into subpackage
subotic Jun 21, 2021
ffd86c6
refactor(v2-ontology): move things into subpackage
subotic Jun 27, 2021
ddfe9dd
Merge branch 'main' into wip/DSP-1700-Remove-cardinalities-from-class
subotic Jun 27, 2021
761f475
feat(ontologies): add route to remove cardinalities from class if pro…
subotic Jun 29, 2021
4029fd4
feat(ontologies): add route to remove cardinalities from class if pro…
subotic Jul 9, 2021
70c0360
feat(ontologies): add route to remove cardinalities from class if pro…
subotic Jul 12, 2021
124aab4
Merge branch 'main' into wip/DSP-1700-Remove-cardinalities-from-class
subotic Jul 12, 2021
3e6ad44
fix: after merge
subotic Jul 12, 2021
d6a52a3
refactor(ontologies): use ASK instead of SELECT
subotic Jul 16, 2021
959afdc
Merge branch 'main' into wip/DSP-1700-Remove-cardinalities-from-class
subotic Jul 21, 2021
4fe81ba
feat(ontologies): add route to remove cardinalities from class if pro…
subotic Jul 21, 2021
92a88be
feat(ontologies): add route to remove cardinalities from class if pro…
subotic Aug 2, 2021
dd0ba4c
feat(ontologies): add route to remove cardinalities from class if pro…
subotic Aug 2, 2021
e774aed
feat(ontologies): add route to remove cardinalities from class if pro…
subotic Aug 3, 2021
e89cab4
refactor: fix deprecations
subotic Aug 4, 2021
402966d
test: add regenerated test responses
subotic Aug 4, 2021
c32495f
feat(ontologies): add route to remove cardinalities from class if pro…
subotic Aug 4, 2021
a668e8d
test(ontologies): add remove cardinalities from class if property is …
subotic Aug 5, 2021
e75deae
test(ontologies): add remove cardinalities from class if property is …
subotic Aug 5, 2021
12a5b54
Merge branch 'main' into wip/DSP-1700-Remove-cardinalities-from-class
subotic Aug 5, 2021
79a6c09
refactor: fix deprecations
subotic Aug 6, 2021
67f3b42
docs(v2-ontology): remove braces
subotic Aug 10, 2021
6343889
chore: remove unneeded comments
subotic Aug 10, 2021
e6b9edd
refactor: rename variables to singular
subotic Aug 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
@@ -1 +1 @@
rolling
4.1.0
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,5 +1,6 @@
/.project
.ijwb
.vscode
**/.idea
**/*.iml
**/*.ipr
Expand Down Expand Up @@ -56,3 +57,5 @@ dump.rdb
dependencies.txt
/client-test-data.zip
/db_staging_dump.trig
cleandeps.sh
/.metals
20 changes: 20 additions & 0 deletions .scalafmt.conf
@@ -1 +1,21 @@
version = "2.7.5"
maxColumn = 120
align.preset = most
align.multiline = false
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = JavaDoc
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses.preset = true
optIn.annotationNewlines = true
newlines.alwaysBeforeMultilineDef = false

rewrite.rules = [RedundantBraces]

rewrite.redundantBraces.generalExpressions = false
rewriteTokens = {
"⇒": "=>"
"→": "->"
"←": "<-"
}
2 changes: 1 addition & 1 deletion WORKSPACE
Expand Up @@ -109,7 +109,7 @@ http_archive(
# scala_config(scala_version = "2.11.12")
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(scala_version = "2.13.5")
scala_config(scala_version = "2.13.6")

# register default and our custom scala toolchain
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
Expand Down
85 changes: 76 additions & 9 deletions docs/03-apis/api-v2/ontology-information.md
Expand Up @@ -1541,15 +1541,13 @@ HTTP PUT to http://host/v2/ontologies/cardinalities
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
{
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:subClassOf" : {
"@type": "owl:Restriction",
"OWL_CARDINALITY_PREDICATE": "OWL_CARDINALITY_VALUE",
"owl:onProperty": {
"@id" : "PROPERTY_IRI"
}
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:subClassOf" : {
"@type": "owl:Restriction",
"OWL_CARDINALITY_PREDICATE": "OWL_CARDINALITY_VALUE",
"owl:onProperty": {
"@id" : "PROPERTY_IRI"
}
}
} ],
Expand Down Expand Up @@ -1592,6 +1590,75 @@ The response will look like this:
}
```


### Delete a single cardinality from a class

If a class is used in data, it is only allowed to delete a cardinality, if the
property a cardinality refers to, is not used inside the data. Also, the property
isn't allowed to be used inside the data in any subclasses of this class.

```
HTTP DELETE to http://host/v2/ontologies/cardinalities
```

```jsonld
{
"@id" : "ONTOLOGY_IRI",
"@type" : "owl:Ontology",
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "ONTOLOGY_LAST_MODIFICATION_DATE"
},
"@graph" : [ {
"@id" : "CLASS_IRI",
"@type" : "owl:Class",
"rdfs:subClassOf" : {
"@type": "owl:Restriction",
"OWL_CARDINALITY_PREDICATE": "OWL_CARDINALITY_VALUE",
"owl:onProperty": {
"@id" : "PROPERTY_IRI"
}
}
} ],
"@context" : {
"knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
"owl" : "http://www.w3.org/2002/07/owl#",
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
"xsd" : "http://www.w3.org/2001/XMLSchema#"
}
}
```

`OWL_CARDINALITY_PREDICATE` and `OWL_CARDINALITY_VALUE` must correspond
to the supported combinations given in
[OWL Cardinalities](../../02-knora-ontologies/knora-base.md#owl-cardinalities). (The placeholder
`OWL_CARDINALITY_VALUE` is shown here in quotes, but it should be an
unquoted integer.)

When a cardinality on a link property is submitted, an identical cardinality
on the corresponding link value property is automatically added (see
[Links Between Resources](../../02-knora-ontologies/knora-base.md#links-between-resources)).

A successful response will be a JSON-LD document providing the new class
definition (but not any of the other entities in the ontology).

To check whether a class's cardinality can be deleted:

```
HTTP POST to http://host/v2/ontologies/candeletedinalities
subotic marked this conversation as resolved.
Show resolved Hide resolved
```

The response will look like this:

```jsonld
{
"knora-api:canDo": false,
"@context": {
"knora-api": "http://api.knora.org/ontology/knora-api/v2#"
}
}
```

### Changing the GUI Order of Cardinalities

To change the GUI order of one or more cardinalities in a class:
Expand Down
82 changes: 82 additions & 0 deletions test_data/all_data/freetest-data.ttl
@@ -0,0 +1,82 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix knora-base: <http://www.knora.org/ontology/knora-base#> .
@prefix knora-admin: <http://www.knora.org/ontology/knora-admin#> .
@prefix salsah-gui: <http://www.knora.org/ontology/salsah-gui#> .
@prefix freetest: <http://www.knora.org/ontology/0001/freetest#> .

<http://rdfh.ch/0001/free-test-instance-01> a freetest:FreeTest ;
knora-base:attachedToUser <http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q>;
knora-base:attachedToProject <http://rdfh.ch/projects/0001>;
knora-base:hasPermissions "V knora-admin:UnknownUser|M knora-admin:ProjectMember";
knora-base:creationDate "2019-11-29T10:00:00.673298Z"^^xsd:dateTime;

freetest:hasText <http://rdfh.ch/0001/free-test-instance-01/values/has-text-value-01> ;
freetest:hasBoolean <http://rdfh.ch/0001/free-test-instance-01/values/has-boolean-value-01>;
rdfs:label "a free test instance";
knora-base:isDeleted false .

<http://rdfh.ch/0001/free-test-instance-01/values/has-text-value-01> a knora-base:TextValue;
knora-base:valueHasUUID "SZyeLLmOTcCCuS3B0VksHQ"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2018-05-28T15:52:03.897Z"^^xsd:dateTime;
knora-base:valueHasOrder 0;
knora-base:valueHasString "test";
knora-base:hasPermissions "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ> .

<http://rdfh.ch/0001/free-test-instance-01/values/has-boolean-value-01> a knora-base:BooleanValue;
knora-base:valueHasUUID "IN4R19yYR0ygi3K2VEHpUQ"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2018-05-28T15:52:03.897Z"^^xsd:dateTime;
knora-base:valueHasBoolean true;
knora-base:valueHasOrder 0;
knora-base:valueHasString "true";
knora-base:hasPermissions "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ> .

## A resource of a subclass
<http://rdfh.ch/0001/short-free-test-instance-01> a freetest:ShortFreeTest ;
knora-base:attachedToUser <http://rdfh.ch/users/9XBCrDV3SRa7kS1WwynB4Q>;
knora-base:attachedToProject <http://rdfh.ch/projects/0001>;
knora-base:hasPermissions "V knora-admin:UnknownUser|M knora-admin:ProjectMember";
knora-base:creationDate "2019-11-29T10:00:00.673298Z"^^xsd:dateTime;

freetest:hasText <http://rdfh.ch/0001/short-free-test-instance-01/values/has-text-value-01> ;
freetest:hasBoolean <http://rdfh.ch/0001/short-free-test-instance-01/values/has-boolean-value-01>;
freetest:hasDecimal <http://rdfh.ch/0001/short-free-test-instance-01/values/has-decimal-value-01>;
rdfs:label "a short free test instance";
knora-base:isDeleted false .

<http://rdfh.ch/0001/short-free-test-instance-01/values/has-text-value-01> a knora-base:TextValue;
knora-base:valueHasUUID "SZyeLLmOTcCCuS3B0VksHQ"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2018-05-28T15:52:03.897Z"^^xsd:dateTime;
knora-base:valueHasOrder 0;
knora-base:valueHasString "test";
knora-base:hasPermissions "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ> .

<http://rdfh.ch/0001/short-free-test-instance-01/values/has-boolean-value-01> a knora-base:BooleanValue;
knora-base:valueHasUUID "IN4R19yYR0ygi3K2VEHpUQ"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2018-05-28T15:52:03.897Z"^^xsd:dateTime;
knora-base:valueHasBoolean true;
knora-base:valueHasOrder 0;
knora-base:valueHasString "true";
knora-base:hasPermissions "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ> .

<http://rdfh.ch/0001/short-free-test-instance-01/values/has-decimal-value-01> a knora-base:DecimalValue;
knora-base:valueHasUUID "bXMwnrHvQH2DMjOFrGmNzg"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2018-05-28T15:52:03.897Z"^^xsd:dateTime;
knora-base:valueHasDecimal "1.5"^^xsd:decimal;
knora-base:valueHasOrder 0;
knora-base:valueHasString "1.5";
knora-base:hasPermissions "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/BhkfBc3hTeS_IDo-JgXRbQ> .
143 changes: 143 additions & 0 deletions test_data/ontologies/freetest-onto.ttl
@@ -0,0 +1,143 @@
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix knora-base: <http://www.knora.org/ontology/knora-base#> .
@prefix salsah-gui: <http://www.knora.org/ontology/salsah-gui#> .
@base <http://www.knora.org/ontology/0001/freetest#> .

# A trivial ontology, used only for testing Knora.

@prefix : <http://www.knora.org/ontology/0001/freetest#> .
<http://www.knora.org/ontology/0001/freetest> rdf:type owl:Ontology ;
rdfs:label "The free test ontology" ;
knora-base:attachedToProject <http://rdfh.ch/projects/0001> ;
knora-base:lastModificationDate "2012-12-12T12:12:12.12Z"^^xsd:dateTime .





:hasText rdf:type owl:ObjectProperty ;

rdfs:subPropertyOf knora-base:hasValue ;

rdfs:label "Text"@de ,
"Texte"@fr ,
"Testo"@it ,
"Text"@en ;

knora-base:subjectClassConstraint :FreeTest ;

knora-base:objectClassConstraint knora-base:TextValue ;

salsah-gui:guiElement salsah-gui:SimpleText ;

salsah-gui:guiAttribute "size=80" ,
"maxlength=255" .


:hasInteger rdf:type owl:ObjectProperty ;

rdfs:subPropertyOf knora-base:hasValue ;

rdfs:label "Ganzzahl"@de ,
"Nombre entier"@fr ,
"Intero"@it ,
"Integer"@en ;

knora-base:subjectClassConstraint :FreeTest ;

knora-base:objectClassConstraint knora-base:IntValue ;

salsah-gui:guiElement salsah-gui:Spinbox ;

salsah-gui:guiAttribute "min=0" ,
"max=-1" .



:hasDecimal rdf:type owl:ObjectProperty ;

rdfs:subPropertyOf knora-base:hasValue ;

rdfs:label "Dezimalzahl"@de ,
"Nombre décimal"@fr ,
"Numero decimale"@it ,
"Decimal number"@en ;

knora-base:subjectClassConstraint :FreeTest ;

knora-base:objectClassConstraint knora-base:DecimalValue ;

salsah-gui:guiElement salsah-gui:SimpleText ;

salsah-gui:guiAttribute "size=80" ,
"maxlength=255" .



:hasBoolean rdf:type owl:ObjectProperty ;

rdfs:subPropertyOf knora-base:hasValue ;

rdfs:label "Boolescher Wert"@de ,
"Valeur booléenne"@fr ,
"Valore booleano"@it ,
"Boolean value"@en ;

knora-base:subjectClassConstraint :FreeTest ;

knora-base:objectClassConstraint knora-base:BooleanValue ;

salsah-gui:guiElement salsah-gui:Checkbox .


:FreeTest rdf:type owl:Class ;

rdfs:subClassOf knora-base:Resource ,
[
rdf:type owl:Restriction ;
owl:onProperty :hasText ;
owl:minCardinality "1"^^xsd:nonNegativeInteger ;
salsah-gui:guiOrder "1"^^xsd:nonNegativeInteger
] ,
[
rdf:type owl:Restriction ;
owl:onProperty :hasBoolean ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger ;
salsah-gui:guiOrder "2"^^xsd:nonNegativeInteger
] ,
[
rdf:type owl:Restriction ;
owl:onProperty :hasDecimal ;
owl:minCardinality "0"^^xsd:nonNegativeInteger ;
salsah-gui:guiOrder "3"^^xsd:nonNegativeInteger
] ,
[
rdf:type owl:Restriction ;
owl:onProperty :hasInteger ;
owl:minCardinality "0"^^xsd:nonNegativeInteger ;
salsah-gui:guiOrder "4"^^xsd:nonNegativeInteger
] ;

knora-base:resourceIcon "thing.png" ;

rdfs:label "FT de"@de ,
"FT fr"@fr ,
"FT it"@it ,
"FT en"@en ;

rdfs:comment """A comment for FT."""@de .


:ShortFreeTest rdf:type owl:Class ;
rdfs:subClassOf :FreeTest ;
rdfs:label "SFT de"@de ,
"SFT fr"@fr ,
"SFT it"@it ,
"SFT en"@en ;

rdfs:comment """A comment for SFT."""@de .
12 changes: 12 additions & 0 deletions test_data/ontologyR2RV2/allOntologyMetadata.jsonld
Expand Up @@ -13,6 +13,18 @@
"@type": "owl:Ontology",
"@id": "http://0.0.0.0:3333/ontology/0001/anything/v2"
},
{
"knora-api:lastModificationDate": {
"@value": "2012-12-12T12:12:12.120Z",
"@type": "xsd:dateTimeStamp"
},
"rdfs:label": "The free test ontology",
"knora-api:attachedToProject": {
"@id": "http://rdfh.ch/projects/0001"
},
"@type": "owl:Ontology",
"@id": "http://0.0.0.0:3333/ontology/0001/freetest/v2"
},
{
"knora-api:lastModificationDate": {
"@value": "2019-09-10T08:57:46.633162Z",
Expand Down