Skip to content

Commit

Permalink
Update contributors in construct query (#4147)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski authored Aug 8, 2023
1 parent 4c78aa7 commit 625b63e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 131 deletions.
68 changes: 21 additions & 47 deletions tests/docker/config/construct-query.sparql
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,12 @@ CONSTRUCT {
:label ?layerLabel ;
:idLabel ?layerIdLabel .

## Contributors / Organizations
?alias :contributors ?personId .
?personId :identifier ?personId ;
:label ?personName ;
:idLabel ?personIdName ;
:affiliation ?affiliation .
?affiliation :label ?affiliationName .
?alias :organizations ?orgId .
?orgId :identifier ?orgId ;
:label ?organizationName ;
:idLabel ?organizationIdName .
## Contributors
?alias :contributors ?contributorId .
?contributorId rdf:type ?contributorType ;
:label ?contributorName ;
:idLabel ?contributorIdName ;
:affiliation ?affiliation .

## Derivation
?alias :derivation ?derivation .
Expand Down Expand Up @@ -308,50 +303,29 @@ CONSTRUCT {
}

# Contributors
# A contributor can be a schema:Person or a schema:Organization (zero or more of each).
# We separate below both cases
OPTIONAL {
?id nsg:contribution / prov:agent ?contributorId
?id nsg:contribution / prov:agent ?contributorId .
?contributorId a ?contributorType .

# A graph of schema:Person contributors
OPTIONAL { ?contributorId schema:name ?contributorName . } .
OPTIONAL {
?contributorId a schema:Person .
BIND(?contributorId as ?personId) .
OPTIONAL { ?personId schema:givenName ?givenName . } .
OPTIONAL { ?personId schema:familyName ?familyName . } .
OPTIONAL {
?personId schema:affiliation ?affiliation .
OPTIONAL { ?affiliation schema:name ?affiliationName . } .
} .
?contributorId schema:givenName ?givenName ;
schema:familyName ?familyName .
BIND(
IF(
BOUND(?givenName) && BOUND(?familyName),
CONCAT(STR(?givenName)," ", STR(?familyName)),
IF(
BOUND(?givenName),
?givenName,
?familyName)
) AS ?personName ) .
BIND(
IF(
BOUND(?personName),
CONCAT(STR(?personId),"|", STR(?personName)),
?undefined
) AS ?personIdName) .
} .

# A graph of schema:Organization contributors
OPTIONAL {
?contributorId a schema:Organization .
BIND(?contributorId as ?orgId) .
OPTIONAL { ?orgId schema:name ?organizationName . } .
BIND(
CONCAT(STR(?givenName), " ", STR(?familyName)),
?contributorName)
AS ?contributorName
) .
}
OPTIONAL { ?contributorId schema:affiliation / schema:name ?affiliation . } .
BIND(
IF(
BOUND(?organizationName),
CONCAT(STR(?orgId),"|", STR(?organizationName)),
BOUND(?contributorId),
CONCAT(STR(?contributorId),"|", STR(?contributorName)),
?undefined
) AS ?organizationIdName) .
} .
) AS ?contributorIdName) .
} .

# Derivation
Expand Down
25 changes: 0 additions & 25 deletions tests/docker/config/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,6 @@
"optional": true,
"sortable": true
},
{
"array": true,
"fields": [
{
"name": "identifier",
"format": [
"uri"
],
"optional": false
},
{
"name": "label",
"format": [
"keyword",
"text"
],
"optional": true
}
],
"label": "Organizations",
"name": "organizations",
"filterable": true,
"optional": true,
"sortable": true
},
{
"array": false,
"fields": [
Expand Down
3 changes: 0 additions & 3 deletions tests/docker/config/search-context.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
"annotation": {
"@container": "@set"
},
"organizations": {
"@container": "@set"
},
"derivation": {
"@container": "@set"
},
Expand Down
25 changes: 0 additions & 25 deletions tests/src/test/resources/kg/search/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,6 @@
"optional": true,
"sortable": true
},
{
"array": true,
"fields": [
{
"name": "identifier",
"format": [
"uri"
],
"optional": false
},
{
"name": "label",
"format": [
"keyword",
"text"
],
"optional": true
}
],
"label": "Organizations",
"name": "organizations",
"filterable": true,
"optional": true,
"sortable": true
},
{
"array": false,
"fields": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,46 +216,29 @@ class SearchConfigSpec extends BaseSpec {
}
}
"have the correct contributor property" in {
// The affiliation property of a contributor is not indexed as expected
// because of the @embed property being set to @last. If another field
// already embeds the object with the same @id, it will not embed it
// for the affiliation.
pending
val query = queryField(neuronMorphologyId, "contributors")
val expected =
json"""
{
"contributors" : [
{
"@id" : "https://www.grid.ac/institutes/grid.5333.6",
"@type" : [
"http://schema.org/Organization",
"http://www.w3.org/ns/prov#Agent"
],
"idLabel": "https://www.grid.ac/institutes/grid.5333.6|École Polytechnique Fédérale de Lausanne",
"label": "École Polytechnique Fédérale de Lausanne"
},
{
"@id" : "https://bbp.epfl.ch/neurosciencegraph/data/d3a0dafe-f8ed-4b4d-bd90-93d64baf63a1",
"@type" : [
"http://www.w3.org/ns/prov#Agent",
"http://schema.org/Person"
],
"idLabel" : "https://bbp.epfl.ch/neurosciencegraph/data/d3a0dafe-f8ed-4b4d-bd90-93d64baf63a1|John Doe",
"identifier" : "https://bbp.epfl.ch/neurosciencegraph/data/d3a0dafe-f8ed-4b4d-bd90-93d64baf63a1",
"label" : "John Doe",
"affiliation": {
"@id": "https://www.grid.ac/institutes/grid.5333.6",
"label": "École Polytechnique Fédérale de Lausanne"
}
}
]
}
"""

assertOneSource(query) { json =>
json should equalIgnoreArrayOrder(expected)
}
}

"have the correct organization property" in {
val query = queryField(neuronMorphologyId, "organizations")
val expected =
json"""
{
"organizations" : [
{
"@id" : "https://www.grid.ac/institutes/grid.5333.6",
"idLabel" : "https://www.grid.ac/institutes/grid.5333.6|École Polytechnique Fédérale de Lausanne",
"identifier" : "https://www.grid.ac/institutes/grid.5333.6",
"label" : "École Polytechnique Fédérale de Lausanne"
"affiliation": "École Polytechnique Fédérale de Lausanne"
}
]
}
Expand Down

0 comments on commit 625b63e

Please sign in to comment.