Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Elasticsearch Services
Search Doc Service
Commits
1a5a77de
Commit
1a5a77de
authored
Sep 09, 2020
by
Jonas Waeber
Browse files
Refactor agent & corporateBody transformation
parent
288d6581
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/KEYS.kt
View file @
1a5a77de
...
...
@@ -45,6 +45,8 @@ object KEYS {
const
val
creator
=
"creator"
const
val
Person
=
"Person"
const
val
CorporateBody
=
"CorporateBody"
const
val
Agent
=
"Agent"
const
val
Place
=
"Place"
const
val
Title
=
"Title"
...
...
src/main/kotlin/SearchDocTransform.kt
View file @
1a5a77de
...
...
@@ -22,8 +22,6 @@ import com.beust.klaxon.JsonObject
import
org.apache.logging.log4j.LogManager
import
org.memobase.builders.*
import
org.memobase.helpers.*
import
org.memobase.model.FacettedContainer
import
org.memobase.model.LanguageContainer
import
org.memobase.model.SearchDoc
import
org.memobase.rdf.NS
...
...
@@ -47,11 +45,23 @@ class SearchDocTransform {
val
temporalIds
=
Extract
.
identifiers
(
record
[
KEYS
.
temporal
])
val
personFacetBuilder
=
PersonFacetBuilder
()
val
subjectPersonBuilder
=
PersonContainerBuilder
(
hasSubjectIds
,
null
,
input
)
val
publisherPersonBuilder
=
PersonContainerBuilder
(
publishedByIds
,
null
,
input
)
val
producersPersonBuilder
=
PersonContainerBuilder
(
producerIds
,
null
,
input
)
val
contributorPersonBuilder
=
PersonContainerBuilder
(
emptyList
(),
KEYS
.
contributor
,
input
)
val
creatorPersonBuilder
=
PersonContainerBuilder
(
emptyList
(),
KEYS
.
creator
,
input
)
val
subjectPersonBuilder
=
AgentContainerBuilder
(
hasSubjectIds
,
KEYS
.
Person
,
null
,
input
)
val
publisherPersonBuilder
=
AgentContainerBuilder
(
publishedByIds
,
KEYS
.
Person
,
null
,
input
)
val
producersPersonBuilder
=
AgentContainerBuilder
(
producerIds
,
KEYS
.
Person
,
null
,
input
)
val
contributorPersonBuilder
=
AgentContainerBuilder
(
emptyList
(),
KEYS
.
Person
,
KEYS
.
contributor
,
input
)
val
creatorPersonBuilder
=
AgentContainerBuilder
(
emptyList
(),
KEYS
.
Person
,
KEYS
.
creator
,
input
)
val
subjectCorporateBodyBuilder
=
AgentContainerBuilder
(
hasSubjectIds
,
KEYS
.
CorporateBody
,
null
,
input
)
val
publisherCorporateBodyBuilder
=
AgentContainerBuilder
(
publishedByIds
,
KEYS
.
CorporateBody
,
null
,
input
)
val
producersCorporateBodyBuilder
=
AgentContainerBuilder
(
producerIds
,
KEYS
.
CorporateBody
,
null
,
input
)
val
contributorCorporateBodyBuilder
=
AgentContainerBuilder
(
emptyList
(),
KEYS
.
CorporateBody
,
KEYS
.
contributor
,
input
)
val
creatorCorporateBodyBuilder
=
AgentContainerBuilder
(
emptyList
(),
KEYS
.
CorporateBody
,
KEYS
.
creator
,
input
)
val
subjectAgentBuilder
=
AgentContainerBuilder
(
hasSubjectIds
,
KEYS
.
Agent
,
null
,
input
)
val
publisherAgentBuilder
=
AgentContainerBuilder
(
publishedByIds
,
KEYS
.
Agent
,
null
,
input
)
val
producersAgentBuilder
=
AgentContainerBuilder
(
producerIds
,
KEYS
.
Agent
,
null
,
input
)
val
contributorAgentBuilder
=
AgentContainerBuilder
(
emptyList
(),
KEYS
.
Agent
,
KEYS
.
contributor
,
input
)
val
creatorAgentBuilder
=
AgentContainerBuilder
(
emptyList
(),
KEYS
.
Agent
,
KEYS
.
creator
,
input
)
val
placesRelatedBuilder
=
FacettedContainerBuilder
(
spatialIds
,
KEYS
.
Place
,
KEYS
.
name
,
FacetBuildHelpers
::
place
)
val
placeCapturedBuilder
=
...
...
@@ -73,6 +83,17 @@ class SearchDocTransform {
producersPersonBuilder
,
contributorPersonBuilder
,
creatorPersonBuilder
,
subjectCorporateBodyBuilder
,
publisherCorporateBodyBuilder
,
producersCorporateBodyBuilder
,
contributorCorporateBodyBuilder
,
creatorCorporateBodyBuilder
,
subjectAgentBuilder
,
publisherAgentBuilder
,
producersAgentBuilder
,
contributorAgentBuilder
,
creatorAgentBuilder
,
placeFacetBuilder
,
placeCapturedBuilder
,
placesRelatedBuilder
,
...
...
@@ -97,11 +118,6 @@ class SearchDocTransform {
val
genre
=
Filter
.
entitiesByProperty
(
"hasGenre"
,
record
,
input
)
val
subjects
=
Filter
.
entitiesByProperty
(
"hasSubject"
,
record
,
input
)
val
publishers
=
Filter
.
entitiesByProperty
(
"publishedBy"
,
record
,
input
)
val
producers
=
Filter
.
entitiesByProperty
(
"P60441"
,
record
,
input
)
val
creationRelationAgents
=
Filter
.
entitiesByProperty
(
"recordResourceOrInstantiationIsSourceOfCreationRelation"
,
record
,
input
)
val
digitalRules
=
Filter
.
entitiesByProperty
(
"regulatedBy"
,
digitalObject
,
input
)
val
physicalRules
=
Filter
.
entitiesByProperty
(
"regulatedBy"
,
physicalObject
,
input
)
...
...
@@ -157,37 +173,17 @@ class SearchDocTransform {
personCreator
=
creatorPersonBuilder
.
build
(),
personsFacet
=
personFacetBuilder
.
build
(),
corporateBodySubject
=
Extract
.
typedEntityByType
(
subjects
,
"@type"
,
"CorporateBody"
,
"name"
),
corporateBodyProducer
=
Extract
.
typedEntityByType
(
producers
,
"@type"
,
"CorporateBody"
,
"name"
),
corporateBodyPublisher
=
Extract
.
typedEntityByType
(
publishers
,
"@type"
,
"CorporateBody"
,
"name"
),
corporateBodyContributor
=
Extract
.
extractTypedCreationRelationAgent
(
creationRelationAgents
,
input
,
creationRelationTypeParam
=
"contributor"
,
agentTypeParam
=
NS
.
rico
+
"CorporateBody"
),
corporateBodyCreator
=
Extract
.
extractTypedCreationRelationAgent
(
creationRelationAgents
,
input
,
creationRelationTypeParam
=
"creator"
,
agentTypeParam
=
NS
.
rico
+
"CorporateBody"
),
agentSubject
=
Extract
.
typedEntityByType
(
subjects
,
"@type"
,
"Agent"
,
"name"
),
agentProducer
=
Extract
.
typedEntityByType
(
producers
,
"@type"
,
"Agent"
,
"name"
),
agentPublisher
=
Extract
.
typedEntityByType
(
publishers
,
"@type"
,
"Agent"
,
"name"
),
agentContributor
=
Extract
.
extractTypedCreationRelationAgent
(
creationRelationAgents
,
input
,
creationRelationTypeParam
=
"contributor"
,
agentTypeParam
=
NS
.
rico
+
"Agent"
),
agentCreator
=
Extract
.
extractTypedCreationRelationAgent
(
creationRelationAgents
,
input
,
creationRelationTypeParam
=
"creator"
,
agentTypeParam
=
NS
.
rico
+
"Agent"
),
corporateBodySubject
=
subjectCorporateBodyBuilder
.
build
(),
corporateBodyProducer
=
producersCorporateBodyBuilder
.
build
(),
corporateBodyPublisher
=
publisherCorporateBodyBuilder
.
build
(),
corporateBodyContributor
=
contributorCorporateBodyBuilder
.
build
(),
corporateBodyCreator
=
creatorCorporateBodyBuilder
.
build
(),
agentSubject
=
subjectAgentBuilder
.
build
(),
agentProducer
=
producersAgentBuilder
.
build
(),
agentPublisher
=
publisherAgentBuilder
.
build
(),
agentContributor
=
contributorAgentBuilder
.
build
(),
agentCreator
=
creatorAgentBuilder
.
build
(),
// DIGITAL & PHYSICAL
access
=
accessPhysical
+
accessDigital
,
...
...
src/main/kotlin/builders/
Person
ContainerBuilder.kt
→
src/main/kotlin/builders/
Agent
ContainerBuilder.kt
View file @
1a5a77de
...
...
@@ -22,19 +22,20 @@ import com.beust.klaxon.JsonObject
import
org.memobase.KEYS
import
org.memobase.helpers.Extract
import
org.memobase.helpers.FacetBuildHelpers
import
org.memobase.model.
Pers
onContainer
import
org.memobase.model.
AgentWithRelati
onContainer
import
org.memobase.rdf.NS
class
Person
ContainerBuilder
(
class
Agent
ContainerBuilder
(
private
val
identifiers
:
List
<
String
>,
private
val
agentType
:
String
,
private
val
creationRelationType
:
String
?,
private
val
inputMap
:
Map
<
String
,
JsonObject
>
)
:
IFieldBuilder
{
private
val
containers
=
mutableListOf
<
Pers
onContainer
>()
private
val
containers
=
mutableListOf
<
AgentWithRelati
onContainer
>()
override
fun
filter
(
jsonObject
:
JsonObject
):
Boolean
{
if
(
jsonObject
[
KEYS
.
atType
]
!=
NS
.
rico
+
KEYS
.
Person
)
return
false
if
(
jsonObject
[
KEYS
.
atType
]
!=
NS
.
rico
+
agentType
)
return
false
return
if
(
creationRelationType
!=
null
)
{
jsonObject
[
KEYS
.
agentIsTargetOfCreationRelation
].
let
{
if
(
it
!=
null
)
...
...
@@ -50,7 +51,7 @@ class PersonContainerBuilder(
}
override
fun
append
(
jsonObject
:
JsonObject
):
String
{
val
name
=
Extract
.
languageContainer
(
"
person
-name"
,
jsonObject
[
KEYS
.
name
])
val
name
=
Extract
.
languageContainer
(
"
agent
-name"
,
jsonObject
[
KEYS
.
name
])
.
reduce
{
acc
,
languageContainer
->
acc
.
merge
(
languageContainer
)
}
val
relation
=
if
(
jsonObject
.
containsKey
(
KEYS
.
agentIsTargetOfCreationRelation
))
{
val
creationRelation
=
inputMap
[
jsonObject
[
KEYS
.
agentIsTargetOfCreationRelation
]]
...
...
@@ -64,9 +65,13 @@ class PersonContainerBuilder(
}
else
{
null
}
val
facet
=
FacetBuildHelpers
.
person
(
jsonObject
)
val
facet
=
if
(
agentType
==
KEYS
.
Person
)
{
FacetBuildHelpers
.
person
(
jsonObject
)
}
else
{
null
}
containers
.
add
(
Pers
onContainer
(
AgentWithRelati
onContainer
(
name
,
relation
,
facet
...
...
@@ -75,7 +80,7 @@ class PersonContainerBuilder(
return
"Created person container for person ${jsonObject[KEYS.entityId]}"
}
override
fun
build
():
List
<
Pers
onContainer
>
{
override
fun
build
():
List
<
AgentWithRelati
onContainer
>
{
return
containers
}
}
src/main/kotlin/helpers/Extract.kt
View file @
1a5a77de
...
...
@@ -21,11 +21,8 @@ package org.memobase.helpers
import
com.beust.klaxon.JsonArray
import
com.beust.klaxon.JsonObject
import
org.apache.logging.log4j.LogManager
import
org.memobase.model.DateContainer
import
org.memobase.model.FacettedContainer
import
org.memobase.model.LanguageContainer
import
org.memobase.model.RelationNameContainer
import
org.memobase.rdf.NS
object
Extract
{
private
val
log
=
LogManager
.
getLogger
(
"ExtractSearchDoc"
)
...
...
@@ -110,35 +107,6 @@ object Extract {
}[
"identifier"
]
as
String
?
?:
error
(
"Identifier contains no property rico:identifier: $entities."
)
}
fun
extractTypedCreationRelationAgent
(
creationRelations
:
List
<
JsonObject
>,
input
:
Map
<
String
,
JsonObject
>,
creationRelationTypeParam
:
String
,
agentTypeParam
:
String
):
List
<
RelationNameContainer
>
{
return
creationRelations
.
mapNotNull
{
creationRelation
->
val
creationRelationType
=
creationRelation
[
"type"
]
as
String
if
(
creationRelationTypeParam
!=
creationRelationType
)
return
@mapNotNull
null
val
name
=
languageContainer
(
"creation-relation-name"
,
creationRelation
[
"name"
])
if
(
name
.
isEmpty
())
{
log
.
warn
(
"No name for creation relation found: $creationRelation."
)
}
val
agent
=
Filter
.
entitiesByProperty
(
"creationRelationHasTarget"
,
creationRelation
,
input
).
first
()
val
agentType
=
agent
[
"@type"
]
as
String
if
(
agentType
!=
agentTypeParam
)
return
@mapNotNull
null
val
agentName
=
languageContainer
(
agent
[
"@id"
]
as
String
,
agent
[
"name"
])
if
(
agentName
.
isEmpty
())
{
log
.
error
(
"Agent/Person/CorporateBody without rico:name found: ${agent["
@
id
"]}."
)
null
}
else
{
return
@mapNotNull
RelationNameContainer
(
agentName
.
reduce
{
acc
,
languageContainer
->
acc
.
merge
(
languageContainer
)
},
if
(
name
.
isNotEmpty
())
name
.
reduce
{
acc
,
languageContainer
->
acc
.
merge
(
languageContainer
)
}
else
LanguageContainer
(
emptyList
(),
emptyList
(),
emptyList
(),
listOf
(
"Unknown"
)))
}
}
}
fun
listOfStrings
(
value
:
Any
?):
List
<
String
>
{
return
when
(
value
)
{
is
String
->
listOf
(
value
)
...
...
src/main/kotlin/model/
Pers
onContainer.kt
→
src/main/kotlin/model/
AgentWithRelati
onContainer.kt
View file @
1a5a77de
...
...
@@ -18,8 +18,8 @@
package
org.memobase.model
data class
Pers
onContainer
(
data class
AgentWithRelati
onContainer
(
val
name
:
LanguageContainer
,
val
relation
:
LanguageContainer
?,
val
facet
:
List
<
String
>
val
facet
:
List
<
String
>
?
)
src/main/kotlin/model/RelationNameContainer.kt
deleted
100644 → 0
View file @
288d6581
/*
* search-doc-service
* Copyright (C) 2020 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
org.memobase.model
import
com.fasterxml.jackson.annotation.JsonInclude
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
data class
RelationNameContainer
(
val
name
:
LanguageContainer
,
val
relation
:
LanguageContainer
)
src/main/kotlin/model/SearchDoc.kt
View file @
1a5a77de
...
...
@@ -47,24 +47,24 @@ data class SearchDoc(
val
language
:
List
<
FacettedContainer
>,
// Agents
val
personSubject
:
List
<
Pers
onContainer
>,
val
personCreator
:
List
<
Pers
onContainer
>,
val
personContributor
:
List
<
Pers
onContainer
>,
val
personPublisher
:
List
<
Pers
onContainer
>,
val
personProducer
:
List
<
Pers
onContainer
>,
val
personSubject
:
List
<
AgentWithRelati
onContainer
>,
val
personCreator
:
List
<
AgentWithRelati
onContainer
>,
val
personContributor
:
List
<
AgentWithRelati
onContainer
>,
val
personPublisher
:
List
<
AgentWithRelati
onContainer
>,
val
personProducer
:
List
<
AgentWithRelati
onContainer
>,
val
personsFacet
:
List
<
String
>,
val
corporateBodySubject
:
List
<
Language
Container
>,
val
corporateBodyCreator
:
List
<
Relation
Name
Container
>,
val
corporateBodyContributor
:
List
<
Relation
Name
Container
>,
val
corporateBodyPublisher
:
List
<
Language
Container
>,
val
corporateBodyProducer
:
List
<
Language
Container
>,
val
agentSubject
:
List
<
Language
Container
>,
val
agentCreator
:
List
<
Relation
Name
Container
>,
val
agentContributor
:
List
<
Relation
Name
Container
>,
val
agentPublisher
:
List
<
Language
Container
>,
val
agentProducer
:
List
<
Language
Container
>,
val
corporateBodySubject
:
List
<
AgentWithRelation
Container
>,
val
corporateBodyCreator
:
List
<
AgentWith
RelationContainer
>,
val
corporateBodyContributor
:
List
<
AgentWith
RelationContainer
>,
val
corporateBodyPublisher
:
List
<
AgentWithRelation
Container
>,
val
corporateBodyProducer
:
List
<
AgentWithRelation
Container
>,
val
agentSubject
:
List
<
AgentWithRelation
Container
>,
val
agentCreator
:
List
<
AgentWith
RelationContainer
>,
val
agentContributor
:
List
<
AgentWith
RelationContainer
>,
val
agentPublisher
:
List
<
AgentWithRelation
Container
>,
val
agentProducer
:
List
<
AgentWithRelation
Container
>,
// Places
val
placeRelated
:
List
<
FacettedContainer
>,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment