Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(v2-ontologies): add remove cardinalities from class if property …
…not used in resources (DSP-1700) (#1869)
  • Loading branch information
subotic committed Aug 11, 2021
1 parent 1bd42fe commit a30668b
Show file tree
Hide file tree
Showing 69 changed files with 15,896 additions and 12,478 deletions.
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
```
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

0 comments on commit a30668b

Please sign in to comment.