Skip to content

Commit

Permalink
Mapping of value range/scope
Browse files Browse the repository at this point in the history
  • Loading branch information
torleifg committed Jan 14, 2025
1 parent 34041ef commit 21de2c5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
27 changes: 23 additions & 4 deletions src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ fun Model.extractBegreper(catalogId: String): List<Begrep> {
merknad = it.extractMerknad(),
eksempel = it.extractEksempel(),
fagområde = it.extractFagområde(),
fagområdeKoder = it.extractFagområdeKoder()
fagområdeKoder = it.extractFagområdeKoder(),
omfang = it.extractOmfang(),
)
}

Expand Down Expand Up @@ -118,6 +119,24 @@ fun Resource.extractFagområdeKoder(): List<String>? {
.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

Check warning on line 136 in src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt#L136

Added line #L136 was not covered by tests
}
}

private fun Resource.extractDefinition(): Definisjon? {
val relationshipWithSource: ForholdTilKildeEnum? = this.getProperty(SKOSNO.relationshipWithSource)
?.let { statement ->
Expand All @@ -134,10 +153,10 @@ private fun Resource.extractDefinition(): Definisjon? {
val source: List<URITekst>? = 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

Check warning on line 160 in src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/no/fdk/concept_catalog/rdf/SkosApNoImport.kt#L160

Added line #L160 was not covered by tests
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SkosApNoImportTests {
assertFalse(concept.eksempel!!.isEmpty())
assertFalse(concept.fagområde!!.isEmpty())
assertFalse(concept.fagområdeKoder!!.isEmpty())
assertNotNull(concept.omfang)
}
}

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/test/resources/import_concept.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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, <https://example.com/fagområdekode> ;
dct:subject "fagområde"@nb, <https://example.com/fagområde> ;
skosno:valueRange "omfang"@nb, <https://example.com/omfang> ;
dct:modified "2020-01-02"^^xsd:date ;
skosno:hasGenericConceptRelation [ rdf:type skosno:GenericConceptRelation ;
dct:description "Inndelingskriterium"@nb ;
Expand Down

0 comments on commit 21de2c5

Please sign in to comment.