In order to mitigate against the brute force attacks against Gitlab accounts, we are moving to all edu-ID Logins. We would like to remind you to link your account with your edu-id. Login will be possible only by edu-ID after November 30, 2021. Here you can find the instructions for linking your account.

If you don't have a SWITCH edu-ID, you can create one with this guide here

kind regards

Commit d0a6854e authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Update code styles.

parent c526b186
......@@ -15,11 +15,9 @@
*/
package ch.memobase.configs
import ch.memobase.exceptions.InvalidMappingException
import ch.memobase.helpers.KEYS
import ch.memobase.helpers.ValidationError
import ch.memobase.model.LocalTransform
import ch.memobase.rdf.InvalidInputException
import ch.memobase.reporting.Report
import ch.memobase.reporting.ReportStatus
import ch.memobase.transform.ITransformer
......@@ -39,7 +37,12 @@ class LocalTransformsLoader(private val data: ByteArray) {
fun parse(key: String): Report {
return try {
if (data.isEmpty())
Report(key, ReportStatus.ignored, "[Local Transform] Ignored empty local transformation file.", KEYS.step)
Report(
key,
ReportStatus.ignored,
"[Local Transform] Ignored empty local transformation file.",
KEYS.step
)
else {
val results = objectMapper.readValue(ByteArrayInputStream(data), LocalTransform::class.java)
results.splitEntity?.forEach {
......
......@@ -19,14 +19,14 @@ import ch.memobase.rdf.MemobaseModel
import ch.memobase.rdf.RDF
import ch.memobase.rdf.RICO
import ch.memobase.rdf.RicoResource
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import org.apache.jena.datatypes.xsd.impl.XSDDateTimeType
import org.apache.jena.rdf.model.Literal
import org.apache.jena.rdf.model.Model
import org.apache.jena.rdf.model.Resource
import org.apache.jena.rdf.model.ResourceFactory
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
object Activity {
......
......@@ -32,7 +32,13 @@ data class ExtractCreationRelationName(
throw ValidationError("Property 'extractRelationName.pattern' requires a named group '(?<$extractCreationRelationNamePatternGroupName>[captured-text])' to be defined, instead was '$pattern'.")
}
if (!validLanguageTags.contains(language)) {
throw ValidationError("Property 'extractRelationName.language' must be one of ${validLanguageTags.joinToString(", ")}, instead was '$language'.")
throw ValidationError(
"Property 'extractRelationName.language' must be one of ${
validLanguageTags.joinToString(
", "
)
}, instead was '$language'."
)
}
return ExtractCreationRelationNameTransform(Regex(pattern), if (language == "NONE") "" else language)
}
......
......@@ -23,10 +23,10 @@ import org.apache.jena.rdf.model.Resource
import org.apache.jena.rdf.model.Statement
class EnrichedConceptBuilder(
private val rdfType: Resource,
private val model: MemobaseModel,
private val target: RicoResource,
private val targetProperty: Property
private val rdfType: Resource,
private val model: MemobaseModel,
private val target: RicoResource,
private val targetProperty: Property
) {
private var resource: RicoResource? = null
......@@ -38,9 +38,9 @@ class EnrichedConceptBuilder(
fun addLabels(property: Property, labels: Labels): EnrichedConceptBuilder {
resource
?.addLiteral(property, labels.de.ifEmpty { KEYS.missingLabelDe }, "de")
?.addLiteral(property, labels.fr.ifEmpty { KEYS.missingLabelFr }, "fr")
?.addLiteral(property, labels.it.ifEmpty { KEYS.missingLabelIt }, "it")
?.addLiteral(property, labels.de.ifEmpty { KEYS.missingLabelDe }, "de")
?.addLiteral(property, labels.fr.ifEmpty { KEYS.missingLabelFr }, "fr")
?.addLiteral(property, labels.it.ifEmpty { KEYS.missingLabelIt }, "it")
return this
}
......
......@@ -28,7 +28,7 @@ import org.apache.logging.log4j.LogManager
class RicoResource(val resource: Resource) {
constructor(resource: Resource, rdfType: Resource) : this(resource.addProperty(RDF.type, rdfType))
constructor(resource: Resource, rdfType: Resource, ricoType: String) : this(
resource.addProperty(RDF.type, rdfType).addProperty(RICO.type, ricoType)
resource.addProperty(RDF.type, rdfType).addProperty(RICO.type, ricoType)
)
private val log = LogManager.getLogger("RicoResource")
......@@ -138,7 +138,7 @@ class RicoResource(val resource: Resource) {
fun removeAllProperties(property: Property, value: String): RicoResource {
resource.model.remove(resource.listProperties(property).filterKeep { it.`object`.isLiteral }
.filterKeep { it.string == value }.toList())
.filterKeep { it.string == value }.toList())
return this
}
......
......@@ -28,10 +28,9 @@ import ch.memobase.rdf.SKOS
import org.apache.logging.log4j.LogManager
class GenreNormalizer(
private val facetsMap: Map<String, Facets>,
private val labelsMap: Map<String, Labels>
) :
ITransformer {
private val facetsMap: Map<String, Facets>,
private val labelsMap: Map<String, Labels>
) : ITransformer {
private val log = LogManager.getLogger(this::class.java)
override fun transform(item: RicoResource, model: MemobaseModel): List<String> {
......@@ -41,7 +40,7 @@ class GenreNormalizer(
if (item.hasProperty(SKOS.prefLabel)) {
val allStatements = item.listProperties()
val copyStatements =
allStatements.filter { it.predicate != SKOS.prefLabel }.filter { it.predicate != RDF.type }
allStatements.filter { it.predicate != SKOS.prefLabel }.filter { it.predicate != RDF.type }
item.listProperties(SKOS.prefLabel).mapNotNull { statement ->
val nameValue = statement.string.trim()
val builder = EnrichedConceptBuilder(SKOS.Concept, model, record, EBUCORE.hasGenre)
......@@ -49,20 +48,20 @@ class GenreNormalizer(
if (facetValues != null) {
facetValues.wikidata.forEach { facetValue ->
builder
.init()
.addLabels(SKOS.prefLabel, labelsMap.getOrDefault(facetValue, Labels.default))
.addSameAsLink(facetValue)
.addOtherStatements(copyStatements)
.appendActivity(KEYS.genreNormalizerMechanismName, item)
.build()
.init()
.addLabels(SKOS.prefLabel, labelsMap.getOrDefault(facetValue, Labels.default))
.addSameAsLink(facetValue)
.addOtherStatements(copyStatements)
.appendActivity(KEYS.genreNormalizerMechanismName, item)
.build()
}
facetValues.freeFacetValue.forEach { facetValue ->
builder
.init()
.addLabels(SKOS.prefLabel, labelsMap.getOrDefault(facetValue, Labels.default))
.addOtherStatements(copyStatements)
.appendActivity(KEYS.genreNormalizerMechanismName, item)
.build()
.init()
.addLabels(SKOS.prefLabel, labelsMap.getOrDefault(facetValue, Labels.default))
.addOtherStatements(copyStatements)
.appendActivity(KEYS.genreNormalizerMechanismName, item)
.build()
}
null
} else {
......
......@@ -19,6 +19,5 @@ import ch.memobase.rdf.MemobaseModel
import ch.memobase.rdf.RicoResource
interface ITransformer {
fun transform(item: RicoResource, model: MemobaseModel): List<String>
}
......@@ -26,10 +26,9 @@ import ch.memobase.rdf.RicoResource
import org.apache.logging.log4j.LogManager
class LanguagesNormalizer(
private val facetsMap: Map<String, Facets>,
private val labelsMap: Map<String, Labels>
) :
ITransformer {
private val facetsMap: Map<String, Facets>,
private val labelsMap: Map<String, Labels>
) : ITransformer {
private val log = LogManager.getLogger(this::class.java)
override fun transform(item: RicoResource, model: MemobaseModel): List<String> {
......@@ -37,7 +36,7 @@ class LanguagesNormalizer(
if (item.hasProperty(RICO.name)) {
val allStatements = item.listProperties()
val copyStatements =
allStatements.filter { it.predicate != RICO.name }.filter { it.predicate != RDF.type }
allStatements.filter { it.predicate != RICO.name }.filter { it.predicate != RDF.type }
item.listProperties(RICO.name).mapNotNull { statement ->
val nameValue = statement.string.trim()
val record = findRecord(model)
......@@ -46,20 +45,20 @@ class LanguagesNormalizer(
if (facetValues != null) {
facetValues.wikidata.forEach { facetValue ->
builder
.init()
.addLabels(RICO.name, labelsMap.getOrDefault(facetValue, Labels.default))
.addSameAsLink(facetValue)
.addOtherStatements(copyStatements)
.appendActivity(KEYS.languageNormalizerMechanismName, item)
.build()
.init()
.addLabels(RICO.name, labelsMap.getOrDefault(facetValue, Labels.default))
.addSameAsLink(facetValue)
.addOtherStatements(copyStatements)
.appendActivity(KEYS.languageNormalizerMechanismName, item)
.build()
}
facetValues.freeFacetValue.forEach { facetValue ->
builder
.init()
.addLabels(RICO.name, labelsMap.getOrDefault(facetValue, Labels.default))
.addOtherStatements(copyStatements)
.appendActivity(KEYS.languageNormalizerMechanismName, item)
.build()
.init()
.addLabels(RICO.name, labelsMap.getOrDefault(facetValue, Labels.default))
.addOtherStatements(copyStatements)
.appendActivity(KEYS.languageNormalizerMechanismName, item)
.build()
}
null
} else {
......
......@@ -51,8 +51,7 @@ class PersonNormalizer(
}
if (splitNames.isEmpty()) {
log.error("The split names list is empty: $text.")
}
else if (splitNames.size == 1) {
} else if (splitNames.size == 1) {
if (singleNameIsLastName) {
item.addLiteral(FOAF.lastName, splitNames[0], value.language)
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment