diff --git a/src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt b/src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt index a0b5a99..6a335fb 100644 --- a/src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt +++ b/src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt @@ -28,7 +28,8 @@ fun Model.extractBegreper(catalogId: String): List { merknad = it.extractMerknad(), eksempel = it.extractEksempel(), fagområde = it.extractFagområde(), - fagområdeKoder = it.extractFagområdeKoder() + fagområdeKoder = it.extractFagområdeKoder(), + omfang = it.extractOmfang(), ) } @@ -118,6 +119,24 @@ fun Resource.extractFagområdeKoder(): List? { .takeIf { it.isNotEmpty() } } +fun Resource.extractOmfang(): URITekst? { + val text = this.listProperties(SKOSNO.valueRange) + .toList() + .firstOrNull { it.`object`.isLiteral } + ?.let { it.`object`.asLiteralOrNull()?.string } + + val uri = this.listProperties(SKOSNO.valueRange) + .toList() + .firstOrNull { it.`object`.isURIResource } + ?.let { it.`object`.asResourceUriOrNull()?.uri } + + return if (text != null || uri != null) { + URITekst(uri, text) + } else { + null + } +} + private fun Resource.extractDefinition(): Definisjon? { val relationshipWithSource: ForholdTilKildeEnum? = this.getProperty(SKOSNO.relationshipWithSource) ?.let { statement -> @@ -134,10 +153,10 @@ private fun Resource.extractDefinition(): Definisjon? { val source: List? = this.listProperties(DCTerms.source) .toList() .mapNotNull { statement -> - statement.`object`.let { obj -> + statement.`object`.let { when { - obj.isLiteral -> URITekst(tekst = obj.asLiteralOrNull()?.string) - obj.isURIResource -> URITekst(uri = obj.asResourceUriOrNull()?.uri) + it.isLiteral -> URITekst(tekst = it.asLiteralOrNull()?.string) + it.isURIResource -> URITekst(uri = it.asResourceUriOrNull()?.uri) else -> null } } diff --git a/src/test/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImportTests.kt b/src/test/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImportTests.kt index 871cf5d..741fa05 100644 --- a/src/test/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImportTests.kt +++ b/src/test/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImportTests.kt @@ -42,6 +42,7 @@ class SkosApNoImportTests { assertFalse(concept.eksempel!!.isEmpty()) assertFalse(concept.fagområde!!.isEmpty()) assertFalse(concept.fagområdeKoder!!.isEmpty()) + assertNotNull(concept.omfang) } } @@ -260,7 +261,20 @@ class SkosApNoImportTests { assertEquals(1, subjects.size) - assertTrue(subjects.first()!!.contains("https://example.com/fagområdekode")) + assertTrue(subjects.first()!!.contains("https://example.com/fagområde")) + } + + @Test + fun `should extract omfang`() { + val model = readModel("import_concept.ttl") + + val scope = model.listResourcesWithProperty(SKOSNO.valueRange) + .toList() + .map { it.extractOmfang() } + + assertEquals(1, scope.size) + + assertEquals(URITekst("https://example.com/omfang", "omfang"), scope.first()) } private fun readModel(file: String): Model { diff --git a/src/test/resources/import_concept.ttl b/src/test/resources/import_concept.ttl index f0b06f9..bd64d13 100644 --- a/src/test/resources/import_concept.ttl +++ b/src/test/resources/import_concept.ttl @@ -30,10 +30,11 @@ owl:versionInfo "1.0.0" ; skos:prefLabel "anbefaltTerm"@nb, "recommendedTerm"@en ; skos:altLabel "tillattTerm"@nn, "tillattTerm2"@nn ; - skos:hiddenLabel "fraraadetTerm"@nb,"fraraadetTerm2"@nb, "Lorem ipsum"@nb ; + skos:hiddenLabel "fraraadetTerm"@nb, "fraraadetTerm2"@nb, "Lorem ipsum"@nb ; skos:scopeNote "merknad"@nn, "merknad"@nb ; skos:example "eksempel"@nn, "eksempel"@nb ; - dct:subject "fagområde"@nb, ; + dct:subject "fagområde"@nb, ; + skosno:valueRange "omfang"@nb, ; dct:modified "2020-01-02"^^xsd:date ; skosno:hasGenericConceptRelation [ rdf:type skosno:GenericConceptRelation ; dct:description "Inndelingskriterium"@nb ;