Skip to content
Snippets Groups Projects
Commit 152ce0ad authored by Frank Lange's avatar Frank Lange
Browse files

fill the orcid field of person authors with data from the triplestore

parent aa7e8b68
No related branches found
No related tags found
No related merge requests found
Pipeline #1484759 failed
......@@ -6,14 +6,15 @@ from rdflib import RDF, URIRef, Variable
from project.dalia.api_models.api_models import OrganizationAuthor, PersonAuthor
from project.dalia.query.utils import query_dalia_dataset
from project.dalia.query_builder.query_builder import GROUP, OPTIONAL, QueryBuilder, UNION, VALUES
from project.dalia.rdf.namespace import Jena_ARQ_list, SCHEMA, educor
from project.dalia.rdf.namespace import Jena_ARQ_list, SCHEMA, educor, metadata4ing
_VARIABLES = {
"lr": Variable("lr"),
"type": Variable("type"),
"name": Variable("name"),
"family": Variable("family"),
"given": Variable("given")
"given": Variable("given"),
"orcid": Variable("orcid"),
}
......@@ -44,6 +45,9 @@ def prepare_query_for_authors_metadata_for_resources(resource_uri_refs: List[URI
(var_member, SCHEMA.familyName, _VARIABLES["family"]),
OPTIONAL(
(var_member, SCHEMA.givenName, _VARIABLES["given"])
),
OPTIONAL(
(var_member, metadata4ing.orcidId, _VARIABLES["orcid"])
)
)
).build()
......@@ -62,7 +66,8 @@ def authors_from_results(
elif type == SCHEMA.Person:
given = str(result.given) if result.given else None
family = str(result.family) if result.family else None
author = PersonAuthor(firstname=given, lastname=family)
orcid = str(result.orcid) if result.orcid else None
author = PersonAuthor(firstname=given, lastname=family, orcid=orcid)
else:
continue
......
"""
Terms from Metadata4Ing (https://w3id.org/nfdi4ing/metadata4ing)
"""
from rdflib import URIRef
NS = "http://w3id.org/nfdi4ing/metadata4ing#"
# Properties
hasRorId = URIRef(NS + "hasRorId")
orcidId = URIRef(NS + "orcidId")
......@@ -12,7 +12,7 @@ def test_prepare_query_for_authors_metadata_for_resources():
query = prepare_query_for_authors_metadata_for_resources([URIRef("abc"), URIRef("def")])
assert normalize(query) == dedent_and_normalize("""
SELECT ?lr ?type ?name ?family ?given
SELECT ?lr ?type ?name ?family ?given ?orcid
WHERE {
VALUES ( ?lr ) {
( <abc> )
......@@ -31,6 +31,9 @@ def test_prepare_query_for_authors_metadata_for_resources():
?member <https://schema.org/familyName> ?family .
OPTIONAL {
?member <https://schema.org/givenName> ?given .
} .
OPTIONAL {
?member <http://w3id.org/nfdi4ing/metadata4ing#orcidId> ?orcid .
} .
}
}
......@@ -42,6 +45,7 @@ def test_get_authors_metadata_for_resources(triplestore):
lr_authors = get_authors_metadata_for_resources([
URIRef("https://id.dalia.education/learning-resource/1ec1db44-5330-47c5-aae3-6852b11f43a4"),
URIRef("https://id.dalia.education/learning-resource/1f794f99-c131-4fb6-b238-5750afa197c8"),
URIRef("https://id.dalia.education/learning-resource/4ed25f20-c3e7-4956-958e-59e4dc0b4bc8"),
URIRef("https://id.dalia.education/learning-resource/87f26aee-175f-4cd2-bb9d-58e4f543bbcf"), # has no authors
URIRef("http://does-not-exist/123"),
])
......@@ -58,6 +62,14 @@ def test_get_authors_metadata_for_resources(triplestore):
PersonAuthor(firstname='Senthold', lastname='Asseng', orcid=None),
PersonAuthor(firstname='David', lastname='Gackstetter', orcid=None),
PersonAuthor(firstname='Benjamin', lastname='Leroy', orcid=None),
PersonAuthor(firstname='Daniel', lastname='Martini', orcid=None)
PersonAuthor(firstname='Daniel', lastname='Martini', orcid=None),
],
URIRef("https://id.dalia.education/learning-resource/4ed25f20-c3e7-4956-958e-59e4dc0b4bc8"): [
PersonAuthor(firstname='Marlen', lastname='Fischer', orcid=None),
PersonAuthor(firstname='Juliane', lastname='Röder', orcid="https://orcid.org/0000-0002-4692-2700"),
PersonAuthor(firstname='Johannes', lastname='Signer', orcid="https://orcid.org/0000-0002-1771-7775"),
PersonAuthor(firstname='Daniel', lastname='Tschink', orcid="https://orcid.org/0000-0001-8683-2534"),
PersonAuthor(firstname='Tanja', lastname='Weibulat', orcid="https://orcid.org/0000-0003-2976-2300"),
PersonAuthor(firstname='Ortrun', lastname='Brand', orcid="https://orcid.org/0000-0002-6850-5123"),
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment