Skip to content
Permalink
Browse files
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 a30668b04201c29ed522ab3c48dcc0acea630f89
Showing with 15,896 additions and 12,478 deletions.
  1. +1 −1 .bazelversion
  2. +3 −0 .gitignore
  3. +20 −0 .scalafmt.conf
  4. +1 −1 WORKSPACE
  5. +76 −9 docs/03-apis/api-v2/ontology-information.md
  6. +82 −0 test_data/all_data/freetest-data.ttl
  7. +143 −0 test_data/ontologies/freetest-onto.ttl
  8. +12 −0 test_data/ontologyR2RV2/allOntologyMetadata.jsonld
  9. +84 −72 test_data/ontologyR2RV2/allOntologyMetadata.rdf
  10. +11 −5 test_data/ontologyR2RV2/allOntologyMetadata.ttl
  11. +12 −0 test_data/ontologyR2RV2/anythingOntologyMetadata.jsonld
  12. +28 −22 test_data/ontologyR2RV2/anythingOntologyMetadata.rdf
  13. +6 −0 test_data/ontologyR2RV2/anythingOntologyMetadata.ttl
  14. +446 −446 test_data/ontologyR2RV2/anythingOntologyWithValueObjects.ttl
  15. +86 −86 test_data/ontologyR2RV2/anythingThingWithAllLanguages.ttl
  16. +28 −28 test_data/ontologyR2RV2/boxOntologyWithValueObjects.ttl
  17. +83 −83 test_data/ontologyR2RV2/imagesBild.ttl
  18. +69 −69 test_data/ontologyR2RV2/incunabulaBook.ttl
  19. +86 −86 test_data/ontologyR2RV2/incunabulaOntologySimple.ttl
  20. +238 −238 test_data/ontologyR2RV2/incunabulaOntologyWithValueObjects.ttl
  21. +71 −71 test_data/ontologyR2RV2/incunabulaPage.ttl
  22. +143 −143 test_data/ontologyR2RV2/incunabulaPageAndBookWithValueObjects.ttl
  23. +29 −29 test_data/ontologyR2RV2/knoraApiDateValue.ttl
  24. +96 −96 test_data/ontologyR2RV2/knoraApiOntologySimple.ttl
  25. +1,110 −1,110 test_data/ontologyR2RV2/knoraApiOntologyWithValueObjects.ttl
  26. +396 −396 test_data/ontologyR2RV2/standoffOntologyWithValueObjects.ttl
  27. +7 −1 third_party/dependencies.bzl
  28. +1 −0 webapi/BUILD.bazel
  29. +2 −0 webapi/scripts/fuseki-init-knora-test.sh
  30. +6 −9 webapi/src/main/scala/org/knora/webapi/app/ApplicationActor.scala
  31. +0 −1 webapi/src/main/scala/org/knora/webapi/app/BUILD.bazel
  32. +15 −15 webapi/src/main/scala/org/knora/webapi/contributors/GenerateContributorsFile.scala
  33. +102 −80 webapi/src/main/scala/org/knora/webapi/messages/v2/responder/KnoraResponseV2.scala
  34. +1,813 −1,578 ...i/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala
  35. +1 −0 webapi/src/main/scala/org/knora/webapi/responders/BUILD.bazel
  36. +84 −82 webapi/src/main/scala/org/knora/webapi/responders/Responder.scala
  37. +2,122 −4,410 webapi/src/main/scala/org/knora/webapi/responders/v2/OntologyResponderV2.scala
  38. +27 −0 webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/BUILD.bazel
  39. +795 −0 webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/Cache.scala
  40. +518 −0 webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/Cardinalities.scala
  41. +2,208 −0 webapi/src/main/scala/org/knora/webapi/responders/v2/ontology/OntologyHelpers.scala
  42. +621 −552 webapi/src/main/scala/org/knora/webapi/routing/v2/OntologiesRouteV2.scala
  43. +28 −25 webapi/src/main/scala/org/knora/webapi/store/StoreManager.scala
  44. +11 −9 webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFManager.scala
  45. +17 −15 webapi/src/main/scala/org/knora/webapi/store/triplestore/TriplestoreManager.scala
  46. +81 −74 webapi/src/main/scala/org/knora/webapi/store/triplestore/embedded/JenaTDBActor.scala
  47. +329 −286 webapi/src/main/scala/org/knora/webapi/store/triplestore/http/HttpTriplestoreConnector.scala
  48. +1 −1 webapi/src/main/scala/org/knora/webapi/util/cache/CacheUtil.scala
  49. +28 −0 webapi/src/main/twirl/BUILD.bazel
  50. +52 −0 webapi/src/main/twirl/org/knora/webapi/queries/sparql/v2/isPropertyUsed.scala.txt
  51. +4 −2 webapi/src/test/scala/org/knora/webapi/BUILD.bazel
  52. +25 −28 webapi/src/test/scala/org/knora/webapi/CoreSpec.scala
  53. +32 −30 webapi/src/test/scala/org/knora/webapi/E2ESpec.scala
  54. +20 −17 webapi/src/test/scala/org/knora/webapi/ITKnoraFakeSpec.scala
  55. +63 −55 webapi/src/test/scala/org/knora/webapi/ITKnoraLiveSpec.scala
  56. +159 −0 webapi/src/test/scala/org/knora/webapi/IntegrationSpec.scala
  57. +33 −28 webapi/src/test/scala/org/knora/webapi/R2RSpec.scala
  58. +48 −0 webapi/src/test/scala/org/knora/webapi/TestContainerFuseki.scala
  59. +4 −4 webapi/src/test/scala/org/knora/webapi/{RedisTestContainer.scala → TestContainerRedis.scala}
  60. +13 −12 webapi/src/test/scala/org/knora/webapi/{TestContainers.scala → TestContainersAll.scala}
  61. +1 −0 webapi/src/test/scala/org/knora/webapi/e2e/v2/BUILD.bazel
  62. +219 −0 webapi/src/test/scala/org/knora/webapi/e2e/v2/OntologyModels.scala
  63. +1,119 −787 webapi/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala
  64. +360 −315 webapi/src/test/scala/org/knora/webapi/responders/v1/ResourcesResponderV1Spec.scala
  65. +1,389 −1,028 webapi/src/test/scala/org/knora/webapi/responders/v2/OntologyResponderV2Spec.scala
  66. +42 −0 webapi/src/test/scala/org/knora/webapi/responders/v2/ontology/BUILD.bazel
  67. +88 −0 webapi/src/test/scala/org/knora/webapi/responders/v2/ontology/DeleteCardinalitiesFromClassSpec.scala
  68. +30 −26 webapi/src/test/scala/org/knora/webapi/sharedtestdata/SharedOntologyTestDataADM.scala
  69. +18 −17 webapi/src/test/scala/org/knora/webapi/store/cacheservice/redis/CacheServiceRedisImplSpec.scala
@@ -1 +1 @@
rolling
4.1.0
@@ -1,5 +1,6 @@
/.project
.ijwb
.vscode
**/.idea
**/*.iml
**/*.ipr
@@ -56,3 +57,5 @@ dump.rdb
dependencies.txt
/client-test-data.zip
/db_staging_dump.trig
cleandeps.sh
/.metals
@@ -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 = {
"⇒": "=>"
"→": "->"
"←": "<-"
}
@@ -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")
@@ -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"
}
}
} ],
@@ -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:
@@ -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> .
@@ -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 .
@@ -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",

0 comments on commit a30668b

Please sign in to comment.