diff --git a/integration/src/test/scala/org/knora/webapi/e2e/v2/OntologyFormatsE2ESpec.scala b/integration/src/test/scala/org/knora/webapi/e2e/v2/OntologyFormatsE2ESpec.scala index a99447ea21..90acbae336 100644 --- a/integration/src/test/scala/org/knora/webapi/e2e/v2/OntologyFormatsE2ESpec.scala +++ b/integration/src/test/scala/org/knora/webapi/e2e/v2/OntologyFormatsE2ESpec.scala @@ -43,7 +43,7 @@ class OntologyFormatsE2ESpec extends E2ESpec { private def makeFile(fileEnding: String = "jsonld"): Path = Paths.get("..", "test_data", "generated_test_data", "ontologyR2RV2", s"$fileBasename.$fileEnding") - def storeAsTtl: Unit = { + private def storeAsTtl(): Unit = { val jsonStr = readFile() val model = parseJsonLd(jsonStr) val ttlStr = RdfFormatUtil.format(model, Turtle) @@ -68,7 +68,7 @@ class OntologyFormatsE2ESpec extends E2ESpec { val newOutputFile = makeFile() Files.createDirectories(newOutputFile.getParent) FileUtil.writeTextFile(newOutputFile, responseStr) - if (persistTtl) storeAsTtl + if (persistTtl) storeAsTtl() else () } } diff --git a/webapi/src/main/scala/org/knora/webapi/LanguageCode.scala b/webapi/src/main/scala/org/knora/webapi/LanguageCode.scala new file mode 100644 index 0000000000..37fcb3b357 --- /dev/null +++ b/webapi/src/main/scala/org/knora/webapi/LanguageCode.scala @@ -0,0 +1,23 @@ +/* + * Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.knora.webapi + +/** + * Constants for language codes. + */ +enum LanguageCode(val code: String) { + case DE extends LanguageCode("de") + case EN extends LanguageCode("en") + case FR extends LanguageCode("fr") + case IT extends LanguageCode("it") + case RM extends LanguageCode("rm") +} + +object LanguageCode { + def from(value: String): Option[LanguageCode] = values.find(_.code == value) + def isSupported(value: String): Boolean = from(value).isDefined + def isNotSupported(value: String): Boolean = !isSupported(value) +} diff --git a/webapi/src/main/scala/org/knora/webapi/LanguageCodes.scala b/webapi/src/main/scala/org/knora/webapi/LanguageCodes.scala deleted file mode 100644 index 292ef5826d..0000000000 --- a/webapi/src/main/scala/org/knora/webapi/LanguageCodes.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.knora.webapi - -/** - * Constants for language codes. - */ -object LanguageCodes { - val DE: String = "de" - val EN: String = "en" - val FR: String = "fr" - val IT: String = "it" - val RM: String = "rm" - - val SupportedLanguageCodes: Set[String] = Set( - DE, - EN, - FR, - IT, - RM, - ) -} diff --git a/webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala b/webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala index 41b33535f9..6eafb8eda9 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/store/triplestoremessages/TriplestoreMessages.scala @@ -328,6 +328,9 @@ object StringLiteralV2 { implicit val codec: JsonCodec[StringLiteralV2] = DeriveJsonCodec.gen[StringLiteralV2] implicit val schema: Schema[StringLiteralV2] = Schema.derived[StringLiteralV2] + def from(value: String, lang: LanguageCode): StringLiteralV2 = + from(value, Some(lang.code)) + def from(value: String, language: Option[String]): StringLiteralV2 = language match { case Some(_) if value.isEmpty => throw BadRequestException("String value is missing.") case _ => StringLiteralV2(value, language) diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JsonLDUtil.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JsonLDUtil.scala index e23e8fe3b2..bfac54085b 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JsonLDUtil.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/rdf/JsonLDUtil.scala @@ -933,7 +933,7 @@ case class JsonLDArray(value: Seq[JsonLDValue]) extends JsonLDValue { (s, errFun) => Iri.toSparqlEncodedString(s).getOrElse(errFun) val lang = obj.requireStringWithValidation(JsonLDKeywords.LANGUAGE, validationFun) - if (!LanguageCodes.SupportedLanguageCodes(lang)) { + if (LanguageCode.isNotSupported(lang)) { throw BadRequestException(s"Unsupported language code: $lang") } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2ComplexTransformationRules.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2ComplexTransformationRules.scala index 494f469d53..0801f609e1 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2ComplexTransformationRules.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2ComplexTransformationRules.scala @@ -5,15 +5,23 @@ package org.knora.webapi.messages.v2.responder.ontologymessages +import org.eclipse.rdf4j.model.vocabulary.OWL +import org.eclipse.rdf4j.model.vocabulary.RDF +import org.eclipse.rdf4j.model.vocabulary.RDFS +import org.eclipse.rdf4j.model.vocabulary.XSD + import org.knora.webapi.* +import org.knora.webapi.LanguageCode.* import org.knora.webapi.messages.IriConversions.* import org.knora.webapi.messages.OntologyConstants +import org.knora.webapi.messages.OntologyConstants.KnoraApiV2Complex as KA import org.knora.webapi.messages.SmartIri import org.knora.webapi.messages.StringFormatter -import org.knora.webapi.messages.store.triplestoremessages.OntologyLiteralV2 -import org.knora.webapi.messages.store.triplestoremessages.SmartIriLiteralV2 -import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2 import org.knora.webapi.messages.v2.responder.ontologymessages.OwlCardinality.* +import org.knora.webapi.messages.v2.responder.ontologymessages.ReadPropertyInfoV2Builder.makeOwlAnnotationProperty +import org.knora.webapi.messages.v2.responder.ontologymessages.ReadPropertyInfoV2Builder.makeOwlDatatypeProperty +import org.knora.webapi.messages.v2.responder.ontologymessages.ReadPropertyInfoV2Builder.makeOwlObjectProperty +import org.knora.webapi.messages.v2.responder.ontologymessages.ReadPropertyInfoV2Builder.makeRdfProperty import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo import org.knora.webapi.slice.ontology.domain.model.Cardinality.* @@ -22,1479 +30,477 @@ import org.knora.webapi.slice.ontology.domain.model.Cardinality.* * See also [[OntologyConstants.CorrespondingIris]]. */ object KnoraBaseToApiV2ComplexTransformationRules extends OntologyTransformationRules { - private implicit val stringFormatter: StringFormatter = StringFormatter.getInstanceForConstantOntologies + private implicit val sf: StringFormatter = StringFormatter.getInstanceForConstantOntologies override val ontologyMetadata: OntologyMetadataV2 = OntologyMetadataV2( - ontologyIri = OntologyConstants.KnoraApiV2Complex.KnoraApiOntologyIri.toSmartIri, + ontologyIri = KA.KnoraApiOntologyIri.toSmartIri, projectIri = Some(KnoraProjectRepo.builtIn.SystemProject.id.value.toSmartIri), label = Some("The knora-api ontology in the complex schema"), ) - private val Label: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.Rdfs.Label, - propertyType = OntologyConstants.Owl.DatatypeProperty, - ) - - private val Result: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.Result, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.DE -> "Ergebnis", - LanguageCodes.EN -> "result", - LanguageCodes.FR -> "résultat", - LanguageCodes.IT -> "risultato", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides a message indicating that an operation was successful", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.String), - ) - - private val Error: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.Error, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "error", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides an error message", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.String), - ) - - private val CanDo: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.CanDo, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "can do", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether an operation can be performed", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val MayHaveMoreResults: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.MayHaveMoreResults, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "May have more results", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether more results may be available for a search query", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val UserHasPermission: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.UserHasPermission, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "user has permission", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides the requesting user's maximum permission on a resource or value.", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.String), - ) - - private val ArkUrl: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.ArkUrl, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "ARK URL", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides the ARK URL of a resource or value.", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Uri), - ) - - private val VersionArkUrl: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.VersionArkUrl, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "version ARK URL", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides the ARK URL of a particular version of a resource or value.", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Uri), - ) - - private val VersionDate: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.VersionDate, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "version date", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides the date of a particular version of a resource.", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Uri), - ) - - private val Author: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.Author, - propertyType = OntologyConstants.Owl.ObjectProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "author", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Specifies the author of a particular version of a resource.", - ), - ), - ), - objectType = Some(OntologyConstants.KnoraApiV2Complex.User), - ) - - private val IsShared: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsShared, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is shared", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether an ontology can be shared by multiple projects", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val IsBuiltIn: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsBuiltIn, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is shared", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether an ontology is built into Knora", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val IsEditable: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsEditable, - propertyType = OntologyConstants.Owl.AnnotationProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is editable", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether a property's values can be updated via the Knora API.", - ), - ), - ), - subjectType = Some(OntologyConstants.Rdf.Property), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val IsResourceClass: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsResourceClass, - propertyType = OntologyConstants.Owl.AnnotationProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is resource class", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether class is a subclass of Resource.", - ), - ), - ), - subjectType = Some(OntologyConstants.Owl.Class), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val IsValueClass: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsValueClass, - propertyType = OntologyConstants.Owl.AnnotationProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is value class", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether class is a subclass of Value.", - ), - ), - ), - subjectType = Some(OntologyConstants.Owl.Class), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val IsStandoffClass: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsStandoffClass, - propertyType = OntologyConstants.Owl.AnnotationProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is standoff class", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether class is a subclass of StandoffTag.", - ), - ), - ), - subjectType = Some(OntologyConstants.Owl.Class), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val IsLinkProperty: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsLinkProperty, - propertyType = OntologyConstants.Owl.AnnotationProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is link property", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether a property points to a resource", - ), - ), - ), - subjectType = Some(OntologyConstants.Owl.ObjectProperty), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val IsLinkValueProperty: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsLinkValueProperty, - propertyType = OntologyConstants.Owl.AnnotationProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is link value property", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether a property points to a link value (reification)", - ), - ), - ), - subjectType = Some(OntologyConstants.Owl.ObjectProperty), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val IsInherited: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IsInherited, - propertyType = OntologyConstants.Owl.AnnotationProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "is inherited", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether a cardinality has been inherited from a base class", - ), - ), - ), - subjectType = Some(OntologyConstants.Owl.Restriction), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) - - private val NewModificationDate: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.NewModificationDate, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "new modification date", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Specifies the new modification date of a resource", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.DateTimeStamp), - ) - - private val OntologyName: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.OntologyName, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "ontology name", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the short name of an ontology", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.String), - ) - - private val MappingHasName: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.MappingHasName, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Name of a mapping (will be part of the mapping's Iri)", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the name of a mapping", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.String), - ) - - private val HasIncomingLinkValue: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.HasIncomingLinkValue, - isResourceProp = true, - propertyType = OntologyConstants.Owl.ObjectProperty, - subjectType = Some(OntologyConstants.KnoraApiV2Complex.Resource), - objectType = Some(OntologyConstants.KnoraApiV2Complex.LinkValue), - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.HasLinkToValue), - isLinkValueProp = true, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.DE -> "hat eingehenden Verweis", - LanguageCodes.EN -> "has incoming link", - LanguageCodes.FR -> "liens entrants", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates that this resource referred to by another resource", - ), - ), - ), - ) - - private val ValueAsString: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.ValueAsString, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map(LanguageCodes.EN -> "A plain string representation of a value"), - ), - ), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.Value), - objectType = Some(OntologyConstants.Xsd.String), - ) - - private val SubjectType: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.SubjectType, - propertyType = OntologyConstants.Rdf.Property, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Subject type", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Specifies the required type of the subjects of a property", - ), - ), - ), - ) - - private val ObjectType: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.ObjectType, - propertyType = OntologyConstants.Rdf.Property, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Object type", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Specifies the required type of the objects of a property", - ), - ), - ), - ) - - private val TextValueHasMarkup: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.TextValueHasMarkup, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.TextValue), - objectType = Some(OntologyConstants.Xsd.Boolean), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "text value has markup", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "True if a text value has markup.", - ), - ), - ), - ) - - private val TextValueHasStandoff: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.TextValueHasStandoff, - propertyType = OntologyConstants.Owl.ObjectProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.TextValue), - objectType = Some(OntologyConstants.KnoraApiV2Complex.StandoffTag), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "text value has standoff", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Standoff markup attached to a text value.", - ), - ), - ), - ) - - private val TextValueHasMaxStandoffStartIndex: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.TextValueHasMaxStandoffStartIndex, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.TextValue), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "text value has max standoff start index", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The maximum knora-api:standoffTagHasStartIndex in a text value.", - ), - ), - ), - ) - - private val NextStandoffStartIndex: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.NextStandoffStartIndex, - propertyType = OntologyConstants.Owl.DatatypeProperty, - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "next standoff start index", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The next available knora-api:standoffTagHasStartIndex in a sequence of pages of standoff.", - ), - ), - ), - ) - - private val StandoffTagHasStartParentIndex: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.StandoffTagHasStartParentIndex, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subjectType = Some(OntologyConstants.KnoraApiV2Complex.StandoffTag), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "standoff tag has start parent index", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The next knora-api:standoffTagHasStartIndex of the start parent tag of a standoff tag.", - ), - ), - ), - ) - - private val StandoffTagHasEndParentIndex: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.StandoffTagHasEndParentIndex, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subjectType = Some(OntologyConstants.KnoraApiV2Complex.StandoffTag), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "standoff tag has end parent index", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The next knora-api:standoffTagHasStartIndex of the end parent tag of a standoff tag.", - ), - ), - ), - ) - - private val TextValueHasLanguage: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.TextValueHasLanguage, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.TextValue), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "text value has language", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Language code attached to a text value.", - ), - ), - ), - ) - - private val TextValueAsXml: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.TextValueAsXml, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.TextValue), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Text value as XML", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "A Text value represented in XML.", - ), - ), - ), - ) - - private val TextValueAsHtml: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.TextValueAsHtml, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.TextValue), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Text value as HTML", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "A text value represented in HTML.", - ), - ), - ), - ) + private val Label = ReadPropertyInfoV2Builder.make(RDFS.LABEL, OWL.DATATYPEPROPERTY) - private val TextValueHasMapping: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.TextValueHasMapping, - propertyType = OntologyConstants.Owl.ObjectProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.TextValue), - objectType = Some(OntologyConstants.KnoraApiV2Complex.XMLToStandoffMapping), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Text value has mapping", - ), + private val Result = makeOwlDatatypeProperty(KA.Result, XSD.STRING) + .withRdfLabel( + Map( + DE -> "Ergebnis", + EN -> "result", + FR -> "résultat", + IT -> "risultato", ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates the mapping that is used to convert a text value's markup from from XML to standoff.", - ), - ), - ), - ) - - private val DateValueHasStartYear: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasStartYear, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has start year", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the start year of a date value.", - ), - ), - ), - ) - - private val DateValueHasEndYear: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasEndYear, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has end year", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the end year of a date value.", - ), - ), - ), - ) - - private val DateValueHasStartMonth: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasStartMonth, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has start month", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the start month of a date value.", - ), - ), - ), - ) - - private val DateValueHasEndMonth: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasEndMonth, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has end month", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the end month of a date value.", - ), - ), - ), - ) - - private val DateValueHasStartDay: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasStartDay, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has start day", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the start day of a date value.", - ), - ), - ), - ) - - private val DateValueHasEndDay: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasEndDay, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has end day", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the end day of a date value.", - ), - ), - ), - ) - - private val DateValueHasStartEra: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasStartEra, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has start era", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the start era of a date value.", - ), - ), - ), - ) - - private val DateValueHasEndEra: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasEndEra, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has end era", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the end era of a date value.", - ), - ), - ), - ) - - private val DateValueHasCalendar: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DateValueHasCalendar, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DateBase), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date value has calendar", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the calendar of a date value.", - ), - ), - ), - ) - - private val LinkValueHasSource: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.LinkValueHasSource, - propertyType = OntologyConstants.Owl.ObjectProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.LinkValue), - objectType = Some(OntologyConstants.KnoraApiV2Complex.Resource), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Link value has source", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the source resource of a link value.", - ), - ), - ), - ) - - private val LinkValueHasSourceIri: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.LinkValueHasSourceIri, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.LinkValue), - objectType = Some(OntologyConstants.Xsd.Uri), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Link value has source IRI", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the IRI of the source resource of a link value.", - ), - ), - ), - ) - - private val LinkValueHasTarget: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.LinkValueHasTarget, - propertyType = OntologyConstants.Owl.ObjectProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.LinkValue), - objectType = Some(OntologyConstants.KnoraApiV2Complex.Resource), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Link value has target", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the target resource of a link value.", - ), - ), - ), - ) - - private val LinkValueHasTargetIri: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.LinkValueHasTargetIri, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.LinkValue), - objectType = Some(OntologyConstants.Xsd.Uri), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Link value has target IRI", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the IRI of the target resource of a link value.", - ), - ), - ), - ) - - private val IntValueAsInt: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IntValueAsInt, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.IntBase), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Integer value as integer", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the literal integer value of an IntValue.", - ), - ), - ), - ) - - private val DecimalValueAsDecimal: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.DecimalValueAsDecimal, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.DecimalBase), - objectType = Some(OntologyConstants.Xsd.Decimal), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Decimal value as decimal", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the literal decimal value of a DecimalValue.", - ), - ), - ), - ) - - private val IntervalValueHasStart: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IntervalValueHasStart, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.IntervalBase), - objectType = Some(OntologyConstants.Xsd.Decimal), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "interval value has start", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the start position of an interval.", - ), - ), - ), - ) - - private val IntervalValueHasEnd: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.IntervalValueHasEnd, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.IntervalBase), - objectType = Some(OntologyConstants.Xsd.Decimal), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "interval value has end", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the end position of an interval.", - ), - ), - ), - ) - - private val BooleanValueAsBoolean: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.BooleanValueAsBoolean, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.BooleanBase), - objectType = Some(OntologyConstants.Xsd.Boolean), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Boolean value as decimal", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the literal boolean value of a BooleanValue.", - ), - ), - ), - ) - - private val GeometryValueAsGeometry: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.GeometryValueAsGeometry, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.GeomValue), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Geometry value as JSON", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents a 2D geometry value as JSON.", - ), - ), - ), - ) - - private val ListValueAsListNode: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.ListValueAsListNode, - propertyType = OntologyConstants.Owl.ObjectProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.ListValue), - objectType = Some(OntologyConstants.KnoraApiV2Complex.ListNode), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Hierarchical list value as list node", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents a reference to a hierarchical list node.", - ), - ), - ), - ) - - private val ColorValueAsColor: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.ColorValueAsColor, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.ColorBase), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Color value as color", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the literal RGB value of a ColorValue.", - ), - ), - ), - ) - - private val UriValueAsUri: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.UriValueAsUri, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.UriBase), - objectType = Some(OntologyConstants.Xsd.Uri), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "URI value as URI", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the literal URI value of a UriValue.", - ), - ), - ), - ) - - private val GeonameValueAsGeonameCode: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.GeonameValueAsGeonameCode, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.GeonameValue), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Geoname value as Geoname code", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents the literal Geoname code of a GeonameValue.", - ), - ), - ), - ) - - private val FileValueAsUrl: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.FileValueAsUrl, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.FileValue), - objectType = Some(OntologyConstants.Xsd.Uri), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "File value as URL", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The URL at which the file can be accessed.", - ), - ), - ), - ) - - private val FileValueHasFilename: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.FileValueHasFilename, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.FileValue), - objectType = Some(OntologyConstants.Xsd.String), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "File value has filename", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The name of the file that a file value represents.", - ), - ), - ), - ) - - private val StillImageFileValueHasDimX: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasDimX, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.StillImageFileValue), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Still image file value has X dimension", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The horizontal dimension of a still image file value.", - ), - ), - ), - ) - - private val StillImageFileValueHasDimY: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasDimY, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.StillImageFileValue), - objectType = Some(OntologyConstants.Xsd.Integer), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Still image file value has Y dimension", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The vertical dimension of a still image file value.", - ), - ), - ), - ) - - private val StillImageFileValueHasIIIFBaseUrl: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasIIIFBaseUrl, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.StillImageFileValue), - objectType = Some(OntologyConstants.Xsd.Uri), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Still image file value has IIIF base URL", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The IIIF base URL of a still image file value.", - ), - ), - ), - ) - private val StillImageFileValueHasExternalUrl: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasExternalUrl, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subPropertyOf = Set(OntologyConstants.KnoraApiV2Complex.ValueHas), - subjectType = Some(OntologyConstants.KnoraApiV2Complex.StillImageExternalFileValue), - objectType = Some(OntologyConstants.Xsd.Uri), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map(LanguageCodes.EN -> "External Url to the image"), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map(LanguageCodes.EN -> "External Url to the image"), + ) + .withRdfCommentEn("Provides a message indicating that an operation was successful") + + private val Error = makeOwlDatatypeProperty(KA.Error, XSD.STRING) + .withRdfLabelEn("error") + .withRdfCommentEn("Provides an error message") + + private val CanDo = makeOwlDatatypeProperty(KA.CanDo, XSD.BOOLEAN) + .withRdfLabelEn("can do") + .withRdfCommentEn("Indicates whether an operation can be performed") + + private val MayHaveMoreResults = makeOwlDatatypeProperty(KA.MayHaveMoreResults, XSD.BOOLEAN) + .withRdfLabelEn("May have more results") + .withRdfCommentEn("Indicates whether more results may be available for a search query") + + private val UserHasPermission = makeOwlDatatypeProperty(KA.UserHasPermission, XSD.STRING) + .withRdfLabelEn("user has permission") + .withRdfCommentEn("Provides the requesting user's maximum permission on a resource or value.") + + private val ArkUrl = makeOwlDatatypeProperty(KA.ArkUrl, XSD.ANYURI) + .withRdfLabelEn("ARK URL") + .withRdfCommentEn("Provides the ARK URL of a resource or value.") + + private val VersionArkUrl = makeOwlDatatypeProperty(KA.VersionArkUrl, XSD.ANYURI) + .withRdfLabelEn("version ARK URL") + .withRdfCommentEn("Provides the ARK URL of a particular version of a resource or value.") + + private val VersionDate = makeOwlDatatypeProperty(KA.VersionDate, XSD.ANYURI) + .withRdfLabelEn("version date") + .withRdfCommentEn("Provides the date of a particular version of a resource.") + + private val Author = makeOwlObjectProperty(KA.Author, KA.User) + .withRdfLabelEn("author") + .withRdfCommentEn("Specifies the author of a particular version of a resource.") + + private val IsShared = makeOwlDatatypeProperty(KA.IsShared, XSD.BOOLEAN) + .withRdfLabelEn("is shared") + .withRdfCommentEn("Indicates whether an ontology can be shared by multiple projects") + + private val IsBuiltIn = makeOwlDatatypeProperty(KA.IsBuiltIn, XSD.BOOLEAN) + .withRdfLabelEn("is shared") + .withRdfCommentEn("Indicates whether an ontology is built into Knora") + + private val IsEditable = makeOwlAnnotationProperty(KA.IsEditable, XSD.BOOLEAN) + .withSubjectType(RDF.PROPERTY) + .withRdfLabelEn("is editable") + .withRdfCommentEn("Indicates whether a property's values can be updated via the Knora API.") + + private val IsResourceClass = makeOwlAnnotationProperty(KA.IsResourceClass, XSD.BOOLEAN) + .withSubjectType(OWL.CLASS) + .withRdfLabelEn("is resource class") + .withRdfCommentEn("Indicates whether class is a subclass of Resource.") + + private val IsValueClass = makeOwlAnnotationProperty(KA.IsValueClass, XSD.BOOLEAN) + .withSubjectType(OWL.CLASS) + .withRdfLabelEn("is value class") + .withRdfCommentEn("Indicates whether class is a subclass of Value.") + + private val IsStandoffClass = makeOwlAnnotationProperty(KA.IsStandoffClass, XSD.BOOLEAN) + .withSubjectType(OWL.CLASS) + .withRdfLabelEn("is standoff class") + .withRdfCommentEn("Indicates whether class is a subclass of StandoffTag.") + + private val IsLinkProperty = makeOwlAnnotationProperty(KA.IsLinkProperty, XSD.BOOLEAN) + .withSubjectType(OWL.OBJECTPROPERTY) + .withRdfLabelEn("is link property") + .withRdfCommentEn("Indicates whether a property points to a resource") + + private val IsLinkValueProperty = makeOwlAnnotationProperty(KA.IsLinkValueProperty, XSD.BOOLEAN) + .withSubjectType(OWL.OBJECTPROPERTY) + .withRdfLabelEn("is link value property") + .withRdfCommentEn("Indicates whether a property points to a link value (reification)") + + private val IsInherited = makeOwlAnnotationProperty(KA.IsInherited, XSD.BOOLEAN) + .withSubjectType(OWL.RESTRICTION) + .withRdfLabelEn("is inherited") + .withRdfCommentEn("Indicates whether a cardinality has been inherited from a base class") + + private val NewModificationDate = makeOwlDatatypeProperty(KA.NewModificationDate, XSD.DATETIMESTAMP) + .withRdfLabelEn("new modification date") + .withRdfCommentEn("Specifies the new modification date of a resource") + + private val OntologyName = makeOwlDatatypeProperty(KA.OntologyName, XSD.STRING) + .withRdfLabelEn("ontology name") + .withRdfCommentEn("Represents the short name of an ontology") + + private val MappingHasName = makeOwlDatatypeProperty(KA.MappingHasName, XSD.STRING) + .withRdfLabelEn("Name of a mapping (will be part of the mapping's Iri)") + .withRdfCommentEn("Represents the name of a mapping") + + private val HasIncomingLinkValue = makeOwlObjectProperty(KA.HasIncomingLinkValue, KA.LinkValue) + .withRdfCommentEn("Indicates that this resource referred to by another resource") + .withRdfLabel( + Map( + DE -> "hat eingehenden Verweis", + EN -> "has incoming link", + FR -> "liens entrants", ), - ), - ) + ) + .withSubjectType(KA.Resource) + .withSubPropertyOf(KA.HasLinkToValue) + .withIsResourceProp() + .withIsLinkValueProp() + + private val ValueAsString = makeOwlDatatypeProperty(KA.ValueAsString, XSD.STRING) + .withSubjectType(KA.Value) + .withRdfCommentEn("A plain string representation of a value") + + private val SubjectType = makeRdfProperty(KA.SubjectType) + .withRdfLabelEn("Subject type") + .withRdfCommentEn("Specifies the required type of the subjects of a property") + + private val ObjectType = makeRdfProperty(KA.ObjectType) + .withRdfLabelEn("Object type") + .withRdfCommentEn("Specifies the required type of the objects of a property") + + private val TextValueHasMarkup = makeOwlDatatypeProperty(KA.TextValueHasMarkup, XSD.BOOLEAN) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.TextValue) + .withRdfLabelEn("text value has markup") + .withRdfCommentEn("True if a text value has markup.") + + private val TextValueHasStandoff = makeOwlObjectProperty(KA.TextValueHasStandoff, KA.StandoffTag) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.TextValue) + .withRdfLabelEn("text value has standoff") + .withRdfCommentEn("Standoff markup attached to a text value.") + + private val TextValueHasMaxStandoffStartIndex = + makeOwlDatatypeProperty(KA.TextValueHasMaxStandoffStartIndex, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.TextValue) + .withRdfLabelEn("text value has max standoff start index") + .withRdfCommentEn("The maximum knora-api:standoffTagHasStartIndex in a text value.") + + private val NextStandoffStartIndex = makeOwlDatatypeProperty(KA.NextStandoffStartIndex, XSD.INTEGER) + .withRdfLabelEn("next standoff start index") + .withRdfCommentEn("The next available knora-api:standoffTagHasStartIndex in a sequence of pages of standoff.") + + private val StandoffTagHasStartParentIndex = makeOwlDatatypeProperty(KA.StandoffTagHasStartParentIndex, XSD.INTEGER) + .withSubjectType(KA.StandoffTag) + .withRdfLabelEn("standoff tag has start parent index") + .withRdfCommentEn("The next knora-api:standoffTagHasStartIndex of the start parent tag of a standoff tag.") + + private val StandoffTagHasEndParentIndex = makeOwlDatatypeProperty(KA.StandoffTagHasEndParentIndex, XSD.INTEGER) + .withSubjectType(KA.StandoffTag) + .withRdfLabelEn("standoff tag has end parent index") + .withRdfCommentEn("The next knora-api:standoffTagHasStartIndex of the end parent tag of a standoff tag.") + + private val TextValueHasLanguage = makeOwlDatatypeProperty(KA.TextValueHasLanguage, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.TextValue) + .withRdfLabelEn("text value has language") + .withRdfCommentEn("Language code attached to a text value.") + + private val TextValueAsXml = makeOwlDatatypeProperty(KA.TextValueAsXml, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.TextValue) + .withRdfLabelEn("Text value as XML") + .withRdfCommentEn("A Text value represented in XML.") + + private val TextValueAsHtml = makeOwlDatatypeProperty(KA.TextValueAsHtml, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.TextValue) + .withRdfLabelEn("Text value as HTML") + .withRdfCommentEn("A text value represented in HTML.") + + private val TextValueHasMapping = makeOwlObjectProperty(KA.TextValueHasMapping, KA.XMLToStandoffMapping) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.TextValue) + .withRdfLabelEn("Text value has mapping") + .withRdfCommentEn("Indicates the mapping that is used to convert a text value's markup from from XML to standoff.") + + private val DateValueHasStartYear = makeOwlDatatypeProperty(KA.DateValueHasStartYear, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has start year") + .withRdfCommentEn("Represents the start year of a date value.") + + private val DateValueHasEndYear = makeOwlDatatypeProperty(KA.DateValueHasEndYear, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has end year") + .withRdfCommentEn("Represents the end year of a date value.") + + private val DateValueHasStartMonth = makeOwlDatatypeProperty(KA.DateValueHasStartMonth, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has start month") + .withRdfCommentEn("Represents the start month of a date value.") + + private val DateValueHasEndMonth = makeOwlDatatypeProperty(KA.DateValueHasEndMonth, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has end month") + .withRdfCommentEn("Represents the end month of a date value.") + + private val DateValueHasStartDay = makeOwlDatatypeProperty(KA.DateValueHasStartDay, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has start day") + .withRdfCommentEn("Represents the start day of a date value.") + + private val DateValueHasEndDay = makeOwlDatatypeProperty(KA.DateValueHasEndDay, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has end day") + .withRdfCommentEn("Represents the end day of a date value.") + + private val DateValueHasStartEra = makeOwlDatatypeProperty(KA.DateValueHasStartEra, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has start era") + .withRdfCommentEn("Represents the start era of a date value.") + + private val DateValueHasEndEra = makeOwlDatatypeProperty(KA.DateValueHasEndEra, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has end era") + .withRdfCommentEn("Represents the end era of a date value.") + + private val DateValueHasCalendar = makeOwlDatatypeProperty(KA.DateValueHasCalendar, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DateBase) + .withRdfLabelEn("Date value has calendar") + .withRdfCommentEn("Represents the calendar of a date value.") + + private val LinkValueHasSource = makeOwlObjectProperty(KA.LinkValueHasSource, KA.Resource) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.LinkValue) + .withRdfLabelEn("Link value has source") + .withRdfCommentEn("Represents the source resource of a link value.") + + private val LinkValueHasSourceIri = makeOwlDatatypeProperty(KA.LinkValueHasSourceIri, XSD.ANYURI) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.LinkValue) + .withRdfLabelEn("Link value has source IRI") + .withRdfCommentEn("Represents the IRI of the source resource of a link value.") + + private val LinkValueHasTarget = makeOwlObjectProperty(KA.LinkValueHasTarget, KA.Resource) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.LinkValue) + .withRdfLabelEn("Link value has target") + .withRdfCommentEn("Represents the target resource of a link value.") + + private val LinkValueHasTargetIri = makeOwlDatatypeProperty(KA.LinkValueHasTargetIri, XSD.ANYURI) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.LinkValue) + .withRdfLabelEn("Link value has target IRI") + .withRdfCommentEn("Represents the IRI of the target resource of a link value.") + + private val IntValueAsInt = makeOwlDatatypeProperty(KA.IntValueAsInt, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.IntBase) + .withRdfLabelEn("Integer value as integer") + .withRdfCommentEn("Represents the literal integer value of an IntValue.") + + private val DecimalValueAsDecimal = makeOwlDatatypeProperty(KA.DecimalValueAsDecimal, XSD.DECIMAL) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.DecimalBase) + .withRdfLabelEn("Decimal value as decimal") + .withRdfCommentEn("Represents the literal decimal value of a DecimalValue.") + + private val IntervalValueHasStart = makeOwlDatatypeProperty(KA.IntervalValueHasStart, XSD.DECIMAL) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.IntervalBase) + .withRdfLabelEn("interval value has start") + .withRdfCommentEn("Represents the start position of an interval.") + + private val IntervalValueHasEnd = makeOwlDatatypeProperty(KA.IntervalValueHasEnd, XSD.DECIMAL) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.IntervalBase) + .withRdfLabelEn("interval value has end") + .withRdfCommentEn("Represents the end position of an interval.") + + private val BooleanValueAsBoolean = makeOwlDatatypeProperty(KA.BooleanValueAsBoolean, XSD.BOOLEAN) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.BooleanBase) + .withRdfLabelEn("Boolean value as decimal") + .withRdfCommentEn("Represents the literal boolean value of a BooleanValue.") + + private val GeometryValueAsGeometry = makeOwlDatatypeProperty(KA.GeometryValueAsGeometry, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.GeomValue) + .withRdfLabelEn("Geometry value as JSON") + .withRdfCommentEn("Represents a 2D geometry value as JSON.") + + private val ListValueAsListNode = makeOwlObjectProperty(KA.ListValueAsListNode, KA.ListNode) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.ListValue) + .withRdfLabelEn("Hierarchical list value as list node") + .withRdfCommentEn("Represents a reference to a hierarchical list node.") + + private val ColorValueAsColor = makeOwlDatatypeProperty(KA.ColorValueAsColor, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.ColorBase) + .withRdfLabelEn("Color value as color") + .withRdfCommentEn("Represents the literal RGB value of a ColorValue.") + + private val UriValueAsUri = makeOwlDatatypeProperty(KA.UriValueAsUri, XSD.ANYURI) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.UriBase) + .withRdfLabelEn("URI value as URI") + .withRdfCommentEn("Represents the literal URI value of a UriValue.") + + private val GeonameValueAsGeonameCode = makeOwlDatatypeProperty(KA.GeonameValueAsGeonameCode, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.GeonameValue) + .withRdfLabelEn("Geoname value as Geoname code") + .withRdfCommentEn("Represents the literal Geoname code of a GeonameValue.") + + private val FileValueAsUrl = makeOwlDatatypeProperty(KA.FileValueAsUrl, XSD.ANYURI) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.FileValue) + .withRdfLabelEn("File value as URL") + .withRdfCommentEn("The URL at which the file can be accessed.") + + private val FileValueHasFilename = makeOwlDatatypeProperty(KA.FileValueHasFilename, XSD.STRING) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.FileValue) + .withRdfLabelEn("File value has filename") + .withRdfCommentEn("The name of the file that a file value represents.") + + private val StillImageFileValueHasDimX = makeOwlDatatypeProperty(KA.StillImageFileValueHasDimX, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.StillImageFileValue) + .withRdfLabelEn("Still image file value has X dimension") + .withRdfCommentEn("The horizontal dimension of a still image file value.") + + private val StillImageFileValueHasDimY = makeOwlDatatypeProperty(KA.StillImageFileValueHasDimY, XSD.INTEGER) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.StillImageFileValue) + .withRdfLabelEn("Still image file value has Y dimension") + .withRdfCommentEn("The vertical dimension of a still image file value.") + + private val StillImageFileValueHasIIIFBaseUrl = + makeOwlDatatypeProperty(KA.StillImageFileValueHasIIIFBaseUrl, XSD.ANYURI) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.StillImageFileValue) + .withRdfLabelEn("Still image file value has IIIF base URL") + .withRdfCommentEn("The IIIF base URL of a still image file value.") + + private val StillImageFileValueHasExternalUrl = + makeOwlDatatypeProperty(KA.StillImageFileValueHasExternalUrl, XSD.ANYURI) + .withSubPropertyOf(KA.ValueHas) + .withSubjectType(KA.StillImageExternalFileValue) + .withRdfLabelEn("External Url to the image") + .withRdfCommentEn("External Url to the image") private val ResourceCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.HasIncomingLinkValue -> Unbounded, - OntologyConstants.KnoraApiV2Complex.ArkUrl -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.VersionArkUrl -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.VersionDate -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.UserHasPermission -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.IsDeleted -> ZeroOrOne, + KA.HasIncomingLinkValue -> Unbounded, + KA.ArkUrl -> ExactlyOne, + KA.VersionArkUrl -> ExactlyOne, + KA.VersionDate -> ZeroOrOne, + KA.UserHasPermission -> ExactlyOne, + KA.IsDeleted -> ZeroOrOne, ) private val DateBaseCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.DateValueHasStartYear -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.DateValueHasEndYear -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.DateValueHasStartMonth -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.DateValueHasEndMonth -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.DateValueHasStartDay -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.DateValueHasEndDay -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.DateValueHasStartEra -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.DateValueHasEndEra -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.DateValueHasCalendar -> ExactlyOne, + KA.DateValueHasStartYear -> ExactlyOne, + KA.DateValueHasEndYear -> ExactlyOne, + KA.DateValueHasStartMonth -> ZeroOrOne, + KA.DateValueHasEndMonth -> ZeroOrOne, + KA.DateValueHasStartDay -> ZeroOrOne, + KA.DateValueHasEndDay -> ZeroOrOne, + KA.DateValueHasStartEra -> ExactlyOne, + KA.DateValueHasEndEra -> ExactlyOne, + KA.DateValueHasCalendar -> ExactlyOne, ) private val UriBaseCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.UriValueAsUri -> ExactlyOne, + KA.UriValueAsUri -> ExactlyOne, ) private val BooleanBaseCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.BooleanValueAsBoolean -> ExactlyOne, + KA.BooleanValueAsBoolean -> ExactlyOne, ) private val IntBaseCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.IntValueAsInt -> ExactlyOne, + KA.IntValueAsInt -> ExactlyOne, ) private val DecimalBaseCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.DecimalValueAsDecimal -> ExactlyOne, + KA.DecimalValueAsDecimal -> ExactlyOne, ) private val IntervalBaseCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.IntervalValueHasStart -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.IntervalValueHasEnd -> ExactlyOne, + KA.IntervalValueHasStart -> ExactlyOne, + KA.IntervalValueHasEnd -> ExactlyOne, ) private val ColorBaseCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.ColorValueAsColor -> ExactlyOne, + KA.ColorValueAsColor -> ExactlyOne, ) private val ValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.ValueAsString -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.HasPermissions -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.UserHasPermission -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.ArkUrl -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.VersionArkUrl -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.IsDeleted -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.ValueHasUUID -> ExactlyOne, + KA.ValueAsString -> ZeroOrOne, + KA.HasPermissions -> ExactlyOne, + KA.UserHasPermission -> ExactlyOne, + KA.ArkUrl -> ExactlyOne, + KA.VersionArkUrl -> ExactlyOne, + KA.IsDeleted -> ZeroOrOne, + KA.ValueHasUUID -> ExactlyOne, ) private val TextValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.TextValueHasStandoff -> Unbounded, - OntologyConstants.KnoraApiV2Complex.TextValueHasMarkup -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.TextValueHasLanguage -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.TextValueAsXml -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.TextValueAsHtml -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.TextValueHasMapping -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.TextValueHasMaxStandoffStartIndex -> ZeroOrOne, + KA.TextValueHasStandoff -> Unbounded, + KA.TextValueHasMarkup -> ZeroOrOne, + KA.TextValueHasLanguage -> ZeroOrOne, + KA.TextValueAsXml -> ZeroOrOne, + KA.TextValueAsHtml -> ZeroOrOne, + KA.TextValueHasMapping -> ZeroOrOne, + KA.TextValueHasMaxStandoffStartIndex -> ZeroOrOne, ) private val StandoffTagCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.StandoffTagHasStartParentIndex -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.StandoffTagHasEndParentIndex -> ZeroOrOne, + KA.StandoffTagHasStartParentIndex -> ZeroOrOne, + KA.StandoffTagHasEndParentIndex -> ZeroOrOne, ) private val LinkValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.LinkValueHasSource -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.LinkValueHasTarget -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.LinkValueHasSourceIri -> ZeroOrOne, - OntologyConstants.KnoraApiV2Complex.LinkValueHasTargetIri -> ZeroOrOne, + KA.LinkValueHasSource -> ZeroOrOne, + KA.LinkValueHasTarget -> ZeroOrOne, + KA.LinkValueHasSourceIri -> ZeroOrOne, + KA.LinkValueHasTargetIri -> ZeroOrOne, ) private val GeomValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.GeometryValueAsGeometry -> ExactlyOne, + KA.GeometryValueAsGeometry -> ExactlyOne, ) private val ListValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.ListValueAsListNode -> ExactlyOne, + KA.ListValueAsListNode -> ExactlyOne, ) private val GeonameValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.GeonameValueAsGeonameCode -> ExactlyOne, + KA.GeonameValueAsGeonameCode -> ExactlyOne, ) private val FileValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.FileValueAsUrl -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.FileValueHasFilename -> ExactlyOne, + KA.FileValueAsUrl -> ExactlyOne, + KA.FileValueHasFilename -> ExactlyOne, ) private val StillImageFileValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasDimX -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasDimY -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasIIIFBaseUrl -> ExactlyOne, + KA.StillImageFileValueHasDimX -> ExactlyOne, + KA.StillImageFileValueHasDimY -> ExactlyOne, + KA.StillImageFileValueHasIIIFBaseUrl -> ExactlyOne, ) private val StillImageExternalFileValueCardinalities = Map( - OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasIIIFBaseUrl -> ExactlyOne, - OntologyConstants.KnoraApiV2Complex.StillImageFileValueHasExternalUrl -> ExactlyOne, + KA.StillImageFileValueHasIIIFBaseUrl -> ExactlyOne, + KA.StillImageFileValueHasExternalUrl -> ExactlyOne, ) /** @@ -1502,9 +508,9 @@ object KnoraBaseToApiV2ComplexTransformationRules extends OntologyTransformation * See also [[OntologyConstants.CorrespondingIris]]. */ override val internalPropertiesToRemove: Set[SmartIri] = Set( - OntologyConstants.Rdf.Subject, - OntologyConstants.Rdf.Predicate, - OntologyConstants.Rdf.Object, + RDF.SUBJECT.toString, + RDF.PREDICATE.toString, + RDF.OBJECT.toString, OntologyConstants.KnoraBase.OntologyVersion, OntologyConstants.KnoraBase.ObjectCannotBeMarkedAsDeleted, OntologyConstants.KnoraBase.ObjectDatatypeConstraint, @@ -1585,24 +591,24 @@ object KnoraBaseToApiV2ComplexTransformationRules extends OntologyTransformation * added to the specified classes to obtain `knora-api`. */ override val externalCardinalitiesToAdd: Map[SmartIri, Map[SmartIri, KnoraCardinalityInfo]] = Map( - OntologyConstants.KnoraApiV2Complex.Resource -> ResourceCardinalities, - OntologyConstants.KnoraApiV2Complex.DateBase -> DateBaseCardinalities, - OntologyConstants.KnoraApiV2Complex.UriBase -> UriBaseCardinalities, - OntologyConstants.KnoraApiV2Complex.BooleanBase -> BooleanBaseCardinalities, - OntologyConstants.KnoraApiV2Complex.IntBase -> IntBaseCardinalities, - OntologyConstants.KnoraApiV2Complex.DecimalBase -> DecimalBaseCardinalities, - OntologyConstants.KnoraApiV2Complex.IntervalBase -> IntervalBaseCardinalities, - OntologyConstants.KnoraApiV2Complex.ColorBase -> ColorBaseCardinalities, - OntologyConstants.KnoraApiV2Complex.Value -> ValueCardinalities, - OntologyConstants.KnoraApiV2Complex.TextValue -> TextValueCardinalities, - OntologyConstants.KnoraApiV2Complex.StandoffTag -> StandoffTagCardinalities, - OntologyConstants.KnoraApiV2Complex.LinkValue -> LinkValueCardinalities, - OntologyConstants.KnoraApiV2Complex.GeomValue -> GeomValueCardinalities, - OntologyConstants.KnoraApiV2Complex.ListValue -> ListValueCardinalities, - OntologyConstants.KnoraApiV2Complex.GeonameValue -> GeonameValueCardinalities, - OntologyConstants.KnoraApiV2Complex.FileValue -> FileValueCardinalities, - OntologyConstants.KnoraApiV2Complex.StillImageFileValue -> StillImageFileValueCardinalities, - OntologyConstants.KnoraApiV2Complex.StillImageExternalFileValue -> StillImageExternalFileValueCardinalities, + KA.Resource -> ResourceCardinalities, + KA.DateBase -> DateBaseCardinalities, + KA.UriBase -> UriBaseCardinalities, + KA.BooleanBase -> BooleanBaseCardinalities, + KA.IntBase -> IntBaseCardinalities, + KA.DecimalBase -> DecimalBaseCardinalities, + KA.IntervalBase -> IntervalBaseCardinalities, + KA.ColorBase -> ColorBaseCardinalities, + KA.Value -> ValueCardinalities, + KA.TextValue -> TextValueCardinalities, + KA.StandoffTag -> StandoffTagCardinalities, + KA.LinkValue -> LinkValueCardinalities, + KA.GeomValue -> GeomValueCardinalities, + KA.ListValue -> ListValueCardinalities, + KA.GeonameValue -> GeonameValueCardinalities, + KA.FileValue -> FileValueCardinalities, + KA.StillImageFileValue -> StillImageFileValueCardinalities, + KA.StillImageExternalFileValue -> StillImageExternalFileValueCardinalities, ).map { case (classIri, cardinalities) => classIri.toSmartIri -> cardinalities.map { case (propertyIri, cardinality) => propertyIri.toSmartIri -> KnoraCardinalityInfo(cardinality) @@ -1684,93 +690,5 @@ object KnoraBaseToApiV2ComplexTransformationRules extends OntologyTransformation StillImageFileValueHasDimY, StillImageFileValueHasIIIFBaseUrl, StillImageFileValueHasExternalUrl, - ).map { propertyInfo => - propertyInfo.entityInfoContent.propertyIri -> propertyInfo - }.toMap - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Convenience functions for building ontology entities, to make the code above more concise. - - /** - * Makes a [[PredicateInfoV2]]. - * - * @param predicateIri the IRI of the predicate. - * @param objects the non-language-specific objects of the predicate. - * @param objectsWithLang the language-specific objects of the predicate. - * @return a [[PredicateInfoV2]]. - */ - private def makePredicate( - predicateIri: IRI, - objects: Seq[OntologyLiteralV2] = Seq.empty[OntologyLiteralV2], - objectsWithLang: Map[String, String] = Map.empty[String, String], - ): PredicateInfoV2 = - PredicateInfoV2( - predicateIri = predicateIri.toSmartIri, - objects = objects ++ objectsWithLang.map { case (lang, str) => - StringLiteralV2.from(str, Some(lang)) - }, - ) - - /** - * Makes a [[ReadPropertyInfoV2]]. - * - * @param propertyIri the IRI of the property. - * @param propertyType the type of the property (owl:ObjectProperty, owl:DatatypeProperty, or rdf:Property). - * @param isResourceProp true if this is a subproperty of `knora-api:hasValue` or `knora-api:hasLinkTo`. - * @param subPropertyOf the set of direct superproperties of this property. - * @param isEditable true if this is a Knora resource property that can be edited via the Knora API. - * @param isLinkValueProp true if the property points to a link value (reification). - * @param predicates the property's predicates. - * @param subjectType the required type of the property's subject. - * @param objectType the required type of the property's object. - * @return a [[ReadPropertyInfoV2]]. - */ - private def makeProperty( - propertyIri: IRI, - propertyType: IRI, - isResourceProp: Boolean = false, - subPropertyOf: Set[IRI] = Set.empty[IRI], - isEditable: Boolean = false, - isLinkProp: Boolean = false, - isLinkValueProp: Boolean = false, - predicates: Seq[PredicateInfoV2] = Seq.empty[PredicateInfoV2], - subjectType: Option[IRI] = None, - objectType: Option[IRI] = None, - ): ReadPropertyInfoV2 = { - val propTypePred = makePredicate( - predicateIri = OntologyConstants.Rdf.Type, - objects = Seq(SmartIriLiteralV2(propertyType.toSmartIri)), - ) - - val maybeSubjectTypePred = subjectType.map { subjType => - makePredicate( - predicateIri = OntologyConstants.KnoraApiV2Complex.SubjectType, - objects = Seq(SmartIriLiteralV2(subjType.toSmartIri)), - ) - } - - val maybeObjectTypePred = objectType.map { objType => - makePredicate( - predicateIri = OntologyConstants.KnoraApiV2Complex.ObjectType, - objects = Seq(SmartIriLiteralV2(objType.toSmartIri)), - ) - } - - val predsWithTypes = predicates ++ maybeSubjectTypePred ++ maybeObjectTypePred :+ propTypePred - - ReadPropertyInfoV2( - entityInfoContent = PropertyInfoContentV2( - propertyIri = propertyIri.toSmartIri, - ontologySchema = ApiV2Complex, - predicates = predsWithTypes.map { pred => - pred.predicateIri -> pred - }.toMap, - subPropertyOf = subPropertyOf.map(iri => iri.toSmartIri), - ), - isResourceProp = isResourceProp, - isEditable = isEditable, - isLinkProp = isLinkProp, - isLinkValueProp = isLinkValueProp, - ) - } + ).map(_.build()).map(info => info.entityInfoContent.propertyIri -> info).toMap } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2SimpleTransformationRules.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2SimpleTransformationRules.scala index 2909e151ac..da6cf1e397 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2SimpleTransformationRules.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2SimpleTransformationRules.scala @@ -5,15 +5,19 @@ package org.knora.webapi.messages.v2.responder.ontologymessages +import org.eclipse.rdf4j.model.vocabulary.RDFS +import org.eclipse.rdf4j.model.vocabulary.XSD + import org.knora.webapi.* +import org.knora.webapi.LanguageCode.* import org.knora.webapi.messages.IriConversions.* import org.knora.webapi.messages.OntologyConstants +import org.knora.webapi.messages.OntologyConstants.KnoraApiV2Simple import org.knora.webapi.messages.SmartIri import org.knora.webapi.messages.StringFormatter -import org.knora.webapi.messages.store.triplestoremessages.OntologyLiteralV2 -import org.knora.webapi.messages.store.triplestoremessages.SmartIriLiteralV2 -import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2 import org.knora.webapi.messages.v2.responder.ontologymessages.OwlCardinality.* +import org.knora.webapi.messages.v2.responder.ontologymessages.ReadClassInfoV2Builder.* +import org.knora.webapi.messages.v2.responder.ontologymessages.ReadPropertyInfoV2Builder.* import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo import org.knora.webapi.slice.ontology.domain.model.Cardinality.* @@ -31,377 +35,92 @@ object KnoraBaseToApiV2SimpleTransformationRules extends OntologyTransformationR label = Some("The knora-api ontology in the simple schema"), ) - private val Label: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.Rdfs.Label, - propertyType = OntologyConstants.Owl.DatatypeProperty, - ) + private val Label = makeOwlDatatypeProperty(RDFS.LABEL) - private val Result: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.Result, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.DE -> "Ergebnis", - LanguageCodes.EN -> "result", - LanguageCodes.FR -> "résultat", - LanguageCodes.IT -> "risultato", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides a message indicating that an operation was successful", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.String), - ) + private val Result = makeOwlDatatypeProperty(KnoraApiV2Simple.Result, XSD.STRING) + .withRdfLabel(Map(DE -> "Ergebnis", EN -> "result", FR -> "résultat", IT -> "risultato")) + .withRdfCommentEn("Provides a message indicating that an operation was successful") - private val MayHaveMoreResults: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.MayHaveMoreResults, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "May have more results", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates whether more results may be available for a search query", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Boolean), - ) + private val MayHaveMoreResults = makeOwlDatatypeProperty(KnoraApiV2Simple.MayHaveMoreResults, XSD.BOOLEAN) + .withRdfLabelEn("May have more results") + .withRdfCommentEn("Indicates whether more results may be available for a search query") - private val Error: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.Error, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.DE -> "Fehler", - LanguageCodes.EN -> "error", - LanguageCodes.FR -> "erreur", - LanguageCodes.IT -> "errore", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides a message indicating that an operation was unsuccessful", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.String), - ) + private val Error = makeOwlDatatypeProperty(KnoraApiV2Simple.Error, XSD.STRING) + .withRdfLabel(Map(DE -> "Fehler", EN -> "error", FR -> "erreur", IT -> "errore")) + .withRdfCommentEn("Provides a message indicating that an operation was unsuccessful") - private val ArkUrl: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.ArkUrl, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "ARK URL", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides the ARK URL of a resource.", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Uri), - ) + private val ArkUrl = makeOwlDatatypeProperty(KnoraApiV2Simple.ArkUrl, XSD.ANYURI) + .withRdfLabelEn("ARK URL") + .withRdfCommentEn("Provides the ARK URL of a resource.") - private val VersionArkUrl: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.VersionArkUrl, - propertyType = OntologyConstants.Owl.DatatypeProperty, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "version ARK URL", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Provides the ARK URL of a particular version of a resource.", - ), - ), - ), - objectType = Some(OntologyConstants.Xsd.Uri), - ) + private val VersionArkUrl = makeOwlDatatypeProperty(KnoraApiV2Simple.VersionArkUrl, XSD.ANYURI) + .withRdfLabelEn("version ARK URL") + .withRdfCommentEn("Provides the ARK URL of a particular version of a resource.") - private val ResourceProperty: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.ResourceProperty, - propertyType = OntologyConstants.Rdf.Property, - subjectType = Some(OntologyConstants.KnoraApiV2Simple.Resource), - subPropertyOf = Set(OntologyConstants.KnoraApiV2Simple.ResourceProperty), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Resource property", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The base property of properties that point from Knora resources to Knora resources or values. These properties are required to have cardinalities in the resource classes in which they are used.", - ), - ), - ), - ) + private val ResourceProperty = makeRdfProperty(KnoraApiV2Simple.ResourceProperty) + .withSubjectType(KnoraApiV2Simple.Resource) + .withSubPropertyOf(OntologyConstants.KnoraApiV2Simple.ResourceProperty) + .withRdfLabelEn("Resource property") + .withRdfCommentEn( + "The base property of properties that point from Knora resources to Knora resources or values. These properties are required to have cardinalities in the resource classes in which they are used.", + ) - private val HasValue: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.HasValue, - propertyType = OntologyConstants.Owl.DatatypeProperty, - subjectType = Some(OntologyConstants.KnoraApiV2Simple.Resource), - subPropertyOf = Set(OntologyConstants.KnoraApiV2Simple.ResourceProperty), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "has value", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "The base property of properties that point from Knora resources to Knora values.", - ), - ), - ), - ) + private val HasValue = makeOwlDatatypeProperty(KnoraApiV2Simple.HasValue) + .withSubjectType(KnoraApiV2Simple.Resource) + .withSubPropertyOf(KnoraApiV2Simple.ResourceProperty) + .withRdfLabelEn("has value") + .withRdfCommentEn("The base property of properties that point from Knora resources to Knora values.") - private val SubjectType: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.SubjectType, - propertyType = OntologyConstants.Rdf.Property, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Subject type", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Specifies the required type of the subjects of a property", - ), - ), - ), - ) + private val SubjectType = makeRdfProperty(KnoraApiV2Simple.SubjectType) + .withRdfLabelEn("Subject type") + .withRdfCommentEn("Specifies the required type of the subjects of a property") - private val ObjectType: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.ObjectType, - propertyType = OntologyConstants.Rdf.Property, - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Object type", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Specifies the required type of the objects of a property", - ), - ), - ), - ) + private val ObjectType = makeRdfProperty(KnoraApiV2Simple.ObjectType) + .withRdfLabelEn("Object type") + .withRdfCommentEn("Specifies the required type of the objects of a property") - private val Date: ReadClassInfoV2 = makeDatatype( - datatypeIri = OntologyConstants.KnoraApiV2Simple.Date, - datatypeInfo = DatatypeInfoV2( - onDatatype = OntologyConstants.Xsd.String.toSmartIri, - pattern = Some( - "(GREGORIAN|JULIAN|ISLAMIC):\\d{1,4}(-\\d{1,2}(-\\d{1,2})?)?( BC| AD| BCE| CE)?(:\\d{1,4}(-\\d{1,2}(-\\d{1,2})?)?( BC| AD| BCE| CE)?)?", - ), - ), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Date literal", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents a date as a period with different possible precisions.", - ), - ), - ), - ) + private val Date = + makeStringDatatypeClassWithPattern( + KnoraApiV2Simple.Date, + "(GREGORIAN|JULIAN|ISLAMIC):\\d{1,4}(-\\d{1,2}(-\\d{1,2})?)?( BC| AD| BCE| CE)?(:\\d{1,4}(-\\d{1,2}(-\\d{1,2})?)?( BC| AD| BCE| CE)?)?", + ) + .withRdfsLabelEn("Date literal") + .withRdfsCommentEn("Represents a date as a period with different possible precisions.") - private val Color: ReadClassInfoV2 = makeDatatype( - datatypeIri = OntologyConstants.KnoraApiV2Simple.Color, - datatypeInfo = DatatypeInfoV2( - onDatatype = OntologyConstants.Xsd.String.toSmartIri, - pattern = Some("#([0-9a-fA-F]{3}){1,2}"), - ), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Color literal", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents a color.", - ), - ), - ), - ) + private val Color = makeStringDatatypeClassWithPattern(KnoraApiV2Simple.Color, "#([0-9a-fA-F]{3}){1,2}") + .withRdfsLabelEn("Color literal") + .withRdfsCommentEn("Represents a color.") - private val Interval: ReadClassInfoV2 = makeDatatype( - datatypeIri = OntologyConstants.KnoraApiV2Simple.Interval, - datatypeInfo = DatatypeInfoV2( - onDatatype = OntologyConstants.Xsd.String.toSmartIri, - pattern = Some("\\d+(\\.\\d+)?,\\d+(\\.\\d+)?"), - ), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Interval literal", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents an interval.", - ), - ), - ), - ) + private val Interval = makeStringDatatypeClassWithPattern(KnoraApiV2Simple.Interval, "\\d+(\\.\\d+)?,\\d+(\\.\\d+)?") + .withRdfsLabelEn("Interval literal") + .withRdfsCommentEn("Represents an interval.") - private val Geoname: ReadClassInfoV2 = makeDatatype( - datatypeIri = OntologyConstants.KnoraApiV2Simple.Geoname, - datatypeInfo = DatatypeInfoV2( - onDatatype = OntologyConstants.Xsd.String.toSmartIri, - pattern = Some("\\d{1,8}"), - ), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Geoname code", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents a Geoname code.", - ), - ), - ), - ) + private val Geoname = makeStringDatatypeClassWithPattern(KnoraApiV2Simple.Geoname, "\\d{1,8}") + .withRdfsLabelEn("Geoname code") + .withRdfsCommentEn("Represents a Geoname code.") - private val Geom: ReadClassInfoV2 = makeDatatype( - datatypeIri = OntologyConstants.KnoraApiV2Simple.Geom, - datatypeInfo = DatatypeInfoV2( - onDatatype = OntologyConstants.Xsd.String.toSmartIri, - ), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "Geometry specification", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents a geometry specification in JSON.", - ), - ), - ), - ) + private val Geom = makeStringDatatypeClass(KnoraApiV2Simple.Geom) + .withRdfsLabelEn("Geometry specification") + .withRdfsCommentEn("Represents a geometry specification in JSON.") - private val File: ReadClassInfoV2 = makeDatatype( - datatypeIri = OntologyConstants.KnoraApiV2Simple.File, - datatypeInfo = DatatypeInfoV2( - onDatatype = OntologyConstants.Xsd.Uri.toSmartIri, - ), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "File URI", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents a file URI.", - ), - ), - ), - ) + private val File = makeUriDatatypeClass(KnoraApiV2Simple.File) + .withRdfsLabelEn("File URI") + .withRdfsCommentEn("Represents a file URI.") - private val ListNode: ReadClassInfoV2 = makeDatatype( - datatypeIri = OntologyConstants.KnoraApiV2Simple.ListNode, - datatypeInfo = DatatypeInfoV2( - onDatatype = OntologyConstants.Xsd.String.toSmartIri, - ), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.EN -> "List Node", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Represents a list node.", - ), - ), - ), - ) + private val ListNode = makeStringDatatypeClass(KnoraApiV2Simple.ListNode) + .withRdfsLabelEn("List Node") + .withRdfsCommentEn("Represents a list node.") - private val HasIncomingLink: ReadPropertyInfoV2 = makeProperty( - propertyIri = OntologyConstants.KnoraApiV2Simple.HasIncomingLink, - propertyType = OntologyConstants.Owl.ObjectProperty, - subjectType = Some(OntologyConstants.KnoraApiV2Simple.Resource), - objectType = Some(OntologyConstants.KnoraApiV2Simple.Resource), - subPropertyOf = Set(OntologyConstants.KnoraApiV2Simple.HasLinkTo), - predicates = Seq( - makePredicate( - predicateIri = OntologyConstants.Rdfs.Label, - objectsWithLang = Map( - LanguageCodes.DE -> "hat eingehenden Verweis", - LanguageCodes.EN -> "has incoming link", - ), - ), - makePredicate( - predicateIri = OntologyConstants.Rdfs.Comment, - objectsWithLang = Map( - LanguageCodes.EN -> "Indicates that this resource referred to by another resource", - ), - ), - ), - ) + private val HasIncomingLink = makeOwlObjectProperty(KnoraApiV2Simple.HasIncomingLink, KnoraApiV2Simple.Resource) + .withSubjectType(KnoraApiV2Simple.Resource) + .withSubPropertyOf(KnoraApiV2Simple.HasLinkTo) + .withRdfLabel(Map(DE -> "hat eingehenden Verweis", EN -> "has incoming link")) + .withRdfCommentEn("Indicates that this resource referred to by another resource") private val ResourceCardinalites = Map( - OntologyConstants.KnoraApiV2Simple.HasIncomingLink -> Unbounded, - OntologyConstants.KnoraApiV2Simple.ArkUrl -> ExactlyOne, - OntologyConstants.KnoraApiV2Simple.VersionArkUrl -> ExactlyOne, + KnoraApiV2Simple.HasIncomingLink -> Unbounded, + KnoraApiV2Simple.ArkUrl -> ExactlyOne, + KnoraApiV2Simple.VersionArkUrl -> ExactlyOne, ) /** @@ -560,9 +279,11 @@ object KnoraBaseToApiV2SimpleTransformationRules extends OntologyTransformationR Geoname, Geom, ListNode, - ).map { classInfo => - classInfo.entityInfoContent.classIri -> classInfo - }.toMap + ) + .map(_.withApiV2SimpleSchema) + .map(_.build()) + .map(it => it.entityInfoContent.classIri -> it) + .toMap /** * Properties that need to be added to `knora-base`, after converting it to the [[ApiV2Simple]] schema, to obtain `knora-api`. @@ -580,114 +301,8 @@ object KnoraBaseToApiV2SimpleTransformationRules extends OntologyTransformationR SubjectType, ObjectType, HasIncomingLink, - ).map { propertyInfo => - propertyInfo.entityInfoContent.propertyIri -> propertyInfo - }.toMap - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Convenience functions for building ontology entities, to make the code above more concise. - - /** - * Makes a [[PredicateInfoV2]]. - * - * @param predicateIri the IRI of the predicate. - * @param objects the non-language-specific objects of the predicate. - * @param objectsWithLang the language-specific objects of the predicate. - * @return a [[PredicateInfoV2]]. - */ - private def makePredicate( - predicateIri: IRI, - objects: Seq[OntologyLiteralV2] = Seq.empty[OntologyLiteralV2], - objectsWithLang: Map[String, String] = Map.empty[String, String], - ): PredicateInfoV2 = - PredicateInfoV2( - predicateIri = predicateIri.toSmartIri, - objects = objects ++ objectsWithLang.map { case (lang, str) => - StringLiteralV2.from(str, Some(lang)) - }, - ) - - /** - * Makes a [[ReadPropertyInfoV2]]. - * - * @param propertyIri the IRI of the property. - * @param propertyType the type of the property (owl:ObjectProperty, owl:DatatypeProperty, or rdf:Property). - * @param subPropertyOf the set of direct superproperties of this property. - * @param predicates the property's predicates. - * @param subjectType the required type of the property's subject. - * @param objectType the required type of the property's object. - * @return a [[ReadPropertyInfoV2]]. - */ - private def makeProperty( - propertyIri: IRI, - propertyType: IRI, - subPropertyOf: Set[IRI] = Set.empty[IRI], - predicates: Seq[PredicateInfoV2] = Seq.empty[PredicateInfoV2], - subjectType: Option[IRI] = None, - objectType: Option[IRI] = None, - ): ReadPropertyInfoV2 = { - val propTypePred = makePredicate( - predicateIri = OntologyConstants.Rdf.Type, - objects = Seq(SmartIriLiteralV2(propertyType.toSmartIri)), - ) - - val maybeSubjectTypePred = subjectType.map { subjType => - makePredicate( - predicateIri = OntologyConstants.KnoraApiV2Simple.SubjectType, - objects = Seq(SmartIriLiteralV2(subjType.toSmartIri)), - ) - } - - val maybeObjectTypePred = objectType.map { objType => - makePredicate( - predicateIri = OntologyConstants.KnoraApiV2Simple.ObjectType, - objects = Seq(SmartIriLiteralV2(objType.toSmartIri)), - ) - } - - val predsWithTypes = predicates ++ maybeSubjectTypePred ++ maybeObjectTypePred :+ propTypePred - - ReadPropertyInfoV2( - entityInfoContent = PropertyInfoContentV2( - propertyIri = propertyIri.toSmartIri, - ontologySchema = ApiV2Simple, - predicates = predsWithTypes.map { pred => - pred.predicateIri -> pred - }.toMap, - subPropertyOf = subPropertyOf.map(_.toSmartIri), - ), - ) - } - - /** - * Makes a [[ReadClassInfoV2]] representing an rdfs:Datatype. - * - * @param datatypeIri the IRI of the datatype. - * @param datatypeInfo a [[DatatypeInfoV2]] describing the datatype. - * @param predicates the predicates of the datatype. - * @return a [[ReadClassInfoV2]]. - */ - private def makeDatatype( - datatypeIri: IRI, - datatypeInfo: DatatypeInfoV2, - predicates: Seq[PredicateInfoV2], - ): ReadClassInfoV2 = { - - val rdfType = OntologyConstants.Rdf.Type.toSmartIri -> PredicateInfoV2( - predicateIri = OntologyConstants.Rdf.Type.toSmartIri, - objects = Seq(SmartIriLiteralV2(OntologyConstants.Rdfs.Datatype.toSmartIri)), - ) - - ReadClassInfoV2( - entityInfoContent = ClassInfoContentV2( - classIri = datatypeIri.toSmartIri, - datatypeInfo = Some(datatypeInfo), - predicates = predicates.map { pred => - pred.predicateIri -> pred - }.toMap + rdfType, - ontologySchema = ApiV2Simple, - ), - allBaseClasses = Seq(datatypeIri.toSmartIri), - ) - } + ).map(_.withApiV2SimpleSchema) + .map(_.build()) + .map(it => it.entityInfoContent.propertyIri -> it) + .toMap } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala index 3e2e951092..31d68e6b86 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/ontologymessages/OntologyMessagesV2.scala @@ -10,6 +10,11 @@ import org.apache.commons.lang3.builder.HashCodeBuilder import org.apache.pekko import org.apache.pekko.actor.ActorRef import org.apache.pekko.util.Timeout +import org.eclipse.rdf4j.model.IRI as Rdf4jIRI +import org.eclipse.rdf4j.model.vocabulary.OWL +import org.eclipse.rdf4j.model.vocabulary.RDF +import org.eclipse.rdf4j.model.vocabulary.RDFS +import org.eclipse.rdf4j.model.vocabulary.XSD import zio.* import zio.prelude.Validation @@ -26,11 +31,13 @@ import dsp.errors.InconsistentRepositoryDataException import dsp.valueobjects.Iri import dsp.valueobjects.Schema import org.knora.webapi.* +import org.knora.webapi.LanguageCode.EN import org.knora.webapi.config.AppConfig import org.knora.webapi.core.RelayedMessage import org.knora.webapi.messages.IriConversions.* import org.knora.webapi.messages.OntologyConstants import org.knora.webapi.messages.OntologyConstants.KnoraApiV2Complex +import org.knora.webapi.messages.OntologyConstants.KnoraApiV2Simple import org.knora.webapi.messages.OntologyConstants.Rdfs import org.knora.webapi.messages.ResponderRequest.KnoraRequestV2 import org.knora.webapi.messages.SmartIri @@ -1893,6 +1900,49 @@ object PredicateInfoV2 { } } +final case class PredicateInfoV2Builder private ( + predicateIri: SmartIri, + objects: Seq[OntologyLiteralV2] = Seq.empty, +) { + self => + def withObject(obj: OntologyLiteralV2): PredicateInfoV2Builder = + copy(objects = self.objects :+ obj) + def withObjects(objs: Seq[OntologyLiteralV2]): PredicateInfoV2Builder = + copy(objects = self.objects ++ objs) + def withStringLiteral(lang: LanguageCode, value: String): PredicateInfoV2Builder = + withObject(StringLiteralV2.from(value, Some(lang.code))) + def withStringLiteral(value: String): PredicateInfoV2Builder = + withObject(StringLiteralV2.from(value, None)) + def withStringLiterals(literals: Map[LanguageCode, String]): PredicateInfoV2Builder = + withObjects(literals.map { case (lang, value) => StringLiteralV2.from(value, lang) }.toSeq) + def build(): PredicateInfoV2 = PredicateInfoV2(self.predicateIri, self.objects) +} +object PredicateInfoV2Builder { + def make(predicateIri: Rdf4jIRI)(implicit sf: StringFormatter): PredicateInfoV2Builder = + make(sf.toSmartIri(predicateIri.toString)) + def make(predicateIri: String)(implicit sf: StringFormatter): PredicateInfoV2Builder = + make(sf.toSmartIri(predicateIri)) + def make(predicateIri: SmartIri): PredicateInfoV2Builder = + PredicateInfoV2Builder(predicateIri) + + def makeRdfType(typeIri: SmartIri)(implicit sf: StringFormatter): PredicateInfoV2Builder = + makeRdfType().withObject(SmartIriLiteralV2(typeIri)) + private def makeRdfType()(implicit sf: StringFormatter): PredicateInfoV2Builder = make(RDF.TYPE) + + def makeRdfsLabel(literals: Map[LanguageCode, String])(implicit sf: StringFormatter): PredicateInfoV2Builder = + makeRdfsLabel().withStringLiterals(literals) + def makeRdfsLabelEn(value: String)(implicit sf: StringFormatter): PredicateInfoV2Builder = makeRdfsLabel(EN, value) + private def makeRdfsLabel(lang: LanguageCode, value: String)(implicit sf: StringFormatter): PredicateInfoV2Builder = + makeRdfsLabel().withStringLiteral(lang, value) + private def makeRdfsLabel()(implicit sf: StringFormatter): PredicateInfoV2Builder = make(RDFS.LABEL) + + def makeRdfsCommentEn(value: String)(implicit sf: StringFormatter): PredicateInfoV2Builder = + makeRdfsComment(EN, value) + private def makeRdfsComment(lang: LanguageCode, value: String)(implicit sf: StringFormatter): PredicateInfoV2Builder = + makeRdfsComment().withStringLiteral(lang, value) + private def makeRdfsComment()(implicit sf: StringFormatter): PredicateInfoV2Builder = make(RDFS.COMMENT) +} + /** * Represents the OWL cardinalities that Knora supports. */ @@ -2606,6 +2656,64 @@ case class ReadClassInfoV2( } } +final case class ReadClassInfoV2Builder( + classIri: SmartIri, + datatypeInfo: Option[DatatypeInfoV2] = None, + predicates: List[PredicateInfoV2] = List.empty, + ontologySchema: ApiV2Schema = ApiV2Complex, + allBaseClasses: List[SmartIri] = List.empty, +) { self => + def withApiV2SimpleSchema: ReadClassInfoV2Builder = + copy(ontologySchema = ApiV2Simple) + + def withRdfType(classIri: Rdf4jIRI)(implicit sf: StringFormatter): ReadClassInfoV2Builder = { + val rdfType = + PredicateInfoV2Builder.make(RDF.TYPE).withObject(SmartIriLiteralV2(sf.toSmartIri(classIri.toString))).build() + copy(predicates = rdfType :: self.predicates) + } + + def withBaseClass(classIri: SmartIri)(implicit sf: StringFormatter): ReadClassInfoV2Builder = + copy(allBaseClasses = classIri :: self.allBaseClasses) + + def withRdfsLabelEn(label: String)(implicit sf: StringFormatter): ReadClassInfoV2Builder = + self.withPredicate(PredicateInfoV2Builder.makeRdfsLabelEn(label)) + + def withRdfsCommentEn(comment: String)(implicit sf: StringFormatter): ReadClassInfoV2Builder = + self.withPredicate(PredicateInfoV2Builder.makeRdfsCommentEn(comment)) + + def withPredicate(builder: PredicateInfoV2Builder): ReadClassInfoV2Builder = + copy(predicates = builder.build() :: self.predicates) + + def build(): ReadClassInfoV2 = { + val predicatesMap = predicates.map(p => p.predicateIri -> p).toMap + val classInfo = ClassInfoContentV2( + classIri = classIri, + datatypeInfo = datatypeInfo, + predicates = predicatesMap, + ontologySchema = ontologySchema, + ) + + ReadClassInfoV2(classInfo, self.allBaseClasses) + } +} +object ReadClassInfoV2Builder { + def makeStringDatatypeClassWithPattern(classIri: String, pattern: String)(implicit + sf: StringFormatter, + ): ReadClassInfoV2Builder = + makeDatatypeClass(sf.toSmartIri(classIri), DatatypeInfoV2(sf.toSmartIri(XSD.STRING.toString), Some(pattern))) + + def makeStringDatatypeClass(classIri: String)(implicit sf: StringFormatter): ReadClassInfoV2Builder = + makeDatatypeClass(sf.toSmartIri(classIri), DatatypeInfoV2(sf.toSmartIri(XSD.STRING.toString), None)) + + def makeUriDatatypeClass(classIri: String)(implicit sf: StringFormatter): ReadClassInfoV2Builder = + makeDatatypeClass(sf.toSmartIri(classIri), DatatypeInfoV2(sf.toSmartIri(XSD.ANYURI.toString), None)) + + def makeDatatypeClass(classIri: SmartIri, datatypeInfo: DatatypeInfoV2)(implicit + sf: StringFormatter, + ): ReadClassInfoV2Builder = + ReadClassInfoV2Builder(classIri, Some(datatypeInfo)).withRdfType(RDFS.DATATYPE).withBaseClass(classIri) +} + /** * Represents an OWL property definition as returned in an API response. * @@ -2745,6 +2853,147 @@ case class ReadPropertyInfoV2( } } +final case class ReadPropertyInfoV2Builder private ( + // PropertyInfoContentV2 fields + propertyIri: SmartIri, + predicates: Map[SmartIri, PredicateInfoV2] = Map.empty, + subPropertyOf: Set[SmartIri] = Set.empty, + ontologySchema: OntologySchema = ApiV2Complex, + objectType: Option[SmartIri] = None, + subjectType: Option[SmartIri] = None, + // ReadPropertyInfoV2 other fields + isResourceProp: Boolean = false, + isEditable: Boolean = false, + isLinkProp: Boolean = false, + isLinkValueProp: Boolean = false, + isFileValueProp: Boolean = false, + isStandoffInternalReferenceProperty: Boolean = false, +) { self => + private def withPredicate(v: PredicateInfoV2): ReadPropertyInfoV2Builder = + copy(predicates = self.predicates + (v.predicateIri -> v)) + + private def withRdfType(propertyType: SmartIri)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + withPredicate(PredicateInfoV2Builder.makeRdfType(propertyType).build()) + + def withSubjectType(subjectType: Rdf4jIRI)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + withSubjectType(sf.toSmartIri(subjectType.toString)) + def withSubjectType(subjectType: String)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + withSubjectType(sf.toSmartIri(subjectType)) + def withSubjectType(subjectType: SmartIri)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + self.copy(subjectType = Some(subjectType)) + + private def withObjectType(valueType: SmartIri): ReadPropertyInfoV2Builder = self.copy(objectType = Some(valueType)) + + def withSubPropertyOf(propertyIri: String)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + self.copy(subPropertyOf = self.subPropertyOf + sf.toSmartIri(propertyIri)) + + def withIsResourceProp(): ReadPropertyInfoV2Builder = self.copy(isResourceProp = true) + def withIsLinkValueProp(): ReadPropertyInfoV2Builder = self.copy(isLinkValueProp = true) + + def withRdfLabelEn(label: String)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + withPredicate(PredicateInfoV2Builder.makeRdfsLabelEn(label).build()) + def withRdfLabel(label: Map[LanguageCode, String])(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + withPredicate(PredicateInfoV2Builder.makeRdfsLabel(label).build()) + + def withRdfCommentEn(comment: String)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + withPredicate(PredicateInfoV2Builder.makeRdfsCommentEn(comment).build()) + + def withApiV2SimpleSchema: ReadPropertyInfoV2Builder = self.copy(ontologySchema = ApiV2Simple) + + def build()(implicit sf: StringFormatter): ReadPropertyInfoV2 = { + def mk(predIri: SmartIri, iriLit: SmartIri) = + PredicateInfoV2Builder.make(predIri).withObject(SmartIriLiteralV2(iriLit)).build() + val (objectTypePropIri, subjectTypePropIri) = ontologySchema match { + case ApiV2Simple => (sf.toSmartIri(KnoraApiV2Simple.ObjectType), sf.toSmartIri(KnoraApiV2Simple.SubjectType)) + case ApiV2Complex => (sf.toSmartIri(KnoraApiV2Complex.ObjectType), sf.toSmartIri(KnoraApiV2Complex.SubjectType)) + case _ => throw IllegalArgumentException(s"Only V2 is supported, this is unsupported $ontologySchema") + } + val predicates = self.predicates ++ + self.objectType.map(objectTypePropIri -> mk(objectTypePropIri, _)) ++ + self.subjectType.map(subjectTypePropIri -> mk(subjectTypePropIri, _)) + + ReadPropertyInfoV2( + PropertyInfoContentV2(propertyIri, predicates, subPropertyOf, ontologySchema), + isResourceProp, + isEditable, + isLinkProp, + isLinkValueProp, + isFileValueProp, + isStandoffInternalReferenceProperty, + ) + } + +} +object ReadPropertyInfoV2Builder { + def makeOwlAnnotationProperty(iri: String, objectType: Rdf4jIRI)(implicit + sf: StringFormatter, + ): ReadPropertyInfoV2Builder = makeOwlAnnotationProperty(iri, objectType.toString) + + def makeOwlAnnotationProperty(iri: String, objectType: String)(implicit + sf: StringFormatter, + ): ReadPropertyInfoV2Builder = makeOwlAnnotationProperty(sf.toSmartIri(iri), sf.toSmartIri(objectType)) + + def makeOwlAnnotationProperty(iri: SmartIri, objectType: SmartIri)(implicit + sf: StringFormatter, + ): ReadPropertyInfoV2Builder = make(iri, OWL.ANNOTATIONPROPERTY).withObjectType(objectType) + + def makeOwlDatatypeProperty(iri: String, objectType: Rdf4jIRI)(implicit + sf: StringFormatter, + ): ReadPropertyInfoV2Builder = makeOwlDatatypeProperty(iri, objectType.toString) + + def makeOwlDatatypeProperty(iri: Rdf4jIRI, objectType: Rdf4jIRI)(implicit + sf: StringFormatter, + ): ReadPropertyInfoV2Builder = makeOwlDatatypeProperty(iri.toString, objectType.toString) + + def makeOwlDatatypeProperty(iri: String, objectType: String)(implicit + sf: StringFormatter, + ): ReadPropertyInfoV2Builder = makeOwlDatatypeProperty(sf.toSmartIri(iri), sf.toSmartIri(objectType)) + + def makeOwlDatatypeProperty(iri: SmartIri, objectType: SmartIri)(implicit + sf: StringFormatter, + ): ReadPropertyInfoV2Builder = makeOwlDatatypeProperty(iri).withObjectType(objectType) + + def makeOwlDatatypeProperty(iri: Rdf4jIRI)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + makeOwlDatatypeProperty(sf.toSmartIri(iri.toString)) + + def makeOwlDatatypeProperty(iri: String)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + makeOwlDatatypeProperty(sf.toSmartIri(iri)) + + def makeOwlDatatypeProperty(iri: SmartIri)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + make(iri, OWL.DATATYPEPROPERTY) + + def makeOwlObjectProperty(iri: String, objectType: Rdf4jIRI)(implicit + sf: StringFormatter, + ): ReadPropertyInfoV2Builder = makeOwlObjectProperty(iri, objectType.toString) + + def makeOwlObjectProperty(iri: String, objectType: String)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + makeOwlObjectProperty(sf.toSmartIri(iri)).withObjectType(sf.toSmartIri(objectType)) + + def makeOwlObjectProperty(iri: Rdf4jIRI)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + makeOwlObjectProperty(sf.toSmartIri(iri.toString)) + + def makeOwlObjectProperty(iri: String)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + makeOwlObjectProperty(sf.toSmartIri(iri)) + + def makeOwlObjectProperty(iri: SmartIri)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + make(iri, OWL.OBJECTPROPERTY) + + def makeRdfProperty(iri: String)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + make(iri, RDF.PROPERTY) + + def make(iri: SmartIri, rdfType: SmartIri)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + ReadPropertyInfoV2Builder(iri).withRdfType(rdfType) + + def make(iri: SmartIri, rdfType: Rdf4jIRI)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + make(iri, sf.toSmartIri(rdfType.toString)) + + def make(iri: String, rdfType: Rdf4jIRI)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + make(sf.toSmartIri(iri), sf.toSmartIri(rdfType.toString)) + + def make(iri: Rdf4jIRI, rdfType: Rdf4jIRI)(implicit sf: StringFormatter): ReadPropertyInfoV2Builder = + make(sf.toSmartIri(iri.toString), sf.toSmartIri(rdfType.toString)) +} + /** * Represents an OWL named individual definition as returned in an API response. *