-
Notifications
You must be signed in to change notification settings - Fork 7
/
search_person_by_gnd_names.rq
81 lines (79 loc) · 2.47 KB
/
search_person_by_gnd_names.rq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Search a person by all preferred and variant names from gnd
# (rank by calculated total score)
#
# Requires a full-text index, as provided by Jena
# (WDQS currently does not support full text search, see
# https://phabricator.wikimedia.org/T141813)
#
PREFIX gndo: <https://d-nb.info/standards/elementset/gnd#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <http://schema.org/>
PREFIX text: <http://jena.apache.org/text#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
#
select distinct ?wd ?wdLabel
?life
(group_concat(distinct ?info ;
separator = "; ") as ?description)
(group_concat(distinct ?affiliation ;
separator = "; ") as ?affiliations)
# (sum(?score) as ?totalScore)
(uri(concat('https://tools.wmflabs.org/quickstatements/#v1=', max(?wdId), '|P227|"', max(?gndId), '"')) as ?addGnd)
('add gndId' as ?addGndLabel)
where {
# get all name variants for search
service <https://zbw.eu/beta/sparql/gnd/query> {
values ( ?gndId ?language ) {
# defaults to economist Dunning, John H.
( "119094665" "en" )
}
?gndPers gndo:gndIdentifier ?gndId .
{
?gndPers gndo:preferredNameForThePerson ?name .
} union {
?gndPers gndo:variantNameForThePerson ?name .
}
}
# full text search, limit number of results to 20
# (query strings and index without language tags)
(?wd ?score) text:query (?name 20) .
#
# restrict to class human
?wd wdt:P31 wd:Q5 ;
rdfs:label ?wdLabelLang .
filter(lang(?wdLabelLang) = ?language)
bind(str(?wdLabelLang) as ?wdLabel)
#
# get additional information
optional {
?wd wdt:P106/rdfs:label ?occupationLang .
filter(lang(?occupationLang) = ?language)
bind(str(?occupationLang) as ?occupation)
}
optional {
?wd wdt:P108/rdfs:label ?affiliationLang .
filter(lang(?affiliationLang) = ?language)
bind(str(?affiliationLang) as ?affiliation)
}
optional {
?wd schema:description ?infoLang .
filter(lang(?infoLang) = ?language)
bind(str(?infoLang) as ?info)
}
optional {
?wd wdt:P569 ?birthDate .
}
optional {
?wd wdt:P570 ?deathDate .
}
bind(if(bound(?birthDate), str(year(?birthDate)), '') as ?birth)
bind(if(bound(?deathDate), str(year(?deathDate)), '') as ?death)
bind(concat(?birth, ' - ', ?death) as ?life)
#
bind(strafter(str(?wd), str(wd:)) as ?wdId)
}
group by ?wd ?wdLabel ?gndId ?life
order by desc(sum(?score))
limit 20