Skip to content

Commit c54fd19

Browse files
committed
Fix #2513 Attempt to fix author sorting in author list
GROUP_CONCAT does not sort, so author lists might be permuted. There seems very little to do about it other than attempt to sort the authors before concatenation and then "hope" that BlazeGraph does the correct sorting. This sometimes work, but at other times there seems to be no effect - at least in recent publication panel for organization the problem persist. The problem has been noted, e.g., at w3c/sparql-dev#9
1 parent 41251f4 commit c54fd19

File tree

3 files changed

+71
-21
lines changed

3 files changed

+71
-21
lines changed

scholia/app/templates/author_list-of-publications.sparql

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,25 @@ SELECT
99
?venue ?venueLabel
1010
(GROUP_CONCAT(DISTINCT ?author_label; separator=", ") AS ?authors)
1111
(CONCAT("../authors/", GROUP_CONCAT(DISTINCT SUBSTR(STR(?author), 32); separator=",")) AS ?authorsUrl)
12+
WITH {
13+
# By standard GROUP_CONCAT does not sort, but BlazeGraph seems to sort.
14+
SELECT
15+
?work ?author ?author_label
16+
WHERE {
17+
?work wdt:P50 target: .
18+
?work p:P50 [ ps:P50 ?author ; pq:P1545 ?order ] .
19+
BIND(xsd:integer(?order) AS ?n)
20+
OPTIONAL {
21+
?author rdfs:label ?author_label_ . FILTER (LANG(?author_label_) = 'en')
22+
}
23+
BIND(COALESCE(?author_label_, SUBSTR(STR(?author), 32)) AS ?author_label)
24+
}
25+
ORDER BY ?n
26+
} AS %authors
1227
WHERE {
1328
?work wdt:P50 target: .
14-
?work wdt:P50 ?author .
15-
OPTIONAL {
16-
?author rdfs:label ?author_label_ . FILTER (LANG(?author_label_) = 'en')
17-
}
18-
BIND(COALESCE(?author_label_, SUBSTR(STR(?author), 32)) AS ?author_label)
29+
INCLUDE %authors
30+
1931
OPTIONAL { ?work wdt:P31 ?type_ . ?type_ rdfs:label ?type_label . FILTER (LANG(?type_label) = 'en') }
2032
?work wdt:P577 ?datetimes .
2133
BIND(xsd:date(?datetimes) AS ?dates)

scholia/app/templates/organization_recent-literature.sparql

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,49 @@ SELECT
77
?work ?workLabel
88
?researchers ?researchersUrl
99
WITH {
10-
SELECT
11-
(MIN(?publication_datetimes) AS ?publication_datetime) ?work
12-
(GROUP_CONCAT(DISTINCT ?researcher_label; separator=', ') AS ?researchers)
13-
(CONCAT("../authors/", GROUP_CONCAT(DISTINCT SUBSTR(STR(?researcher), 32); separator=",")) AS ?researchersUrl)
14-
WHERE {
10+
SELECT DISTINCT
11+
?researcher
12+
WHERE {
1513
?researcher ( wdt:P108 | wdt:P463 | wdt:P1416 ) / wdt:P361* target: .
16-
?work wdt:P50 ?researcher .
17-
?researcher rdfs:label ?researcher_label . FILTER (LANG(?researcher_label) = 'en')
18-
OPTIONAL {
19-
?work wdt:P577 ?publication_datetimes .
20-
}
14+
}
15+
} AS %researchers
16+
WITH {
17+
SELECT
18+
?work
19+
(MIN(?publication_datetime_) AS ?publication_datetime)
20+
WHERE {
21+
INCLUDE %researchers
22+
?work wdt:P50 ?researcher ;
23+
wdt:P577 ?publication_datetime_ .
2124
}
2225
GROUP BY ?work
2326
ORDER BY DESC(?publication_datetime)
24-
LIMIT 200
27+
LIMIT 200
28+
} AS %works
29+
WITH {
30+
SELECT
31+
?work
32+
(GROUP_CONCAT(?researcher_label; separator=', ') AS ?researchers)
33+
(CONCAT("../authors/", GROUP_CONCAT(DISTINCT SUBSTR(STR(?researcher), 32); separator=",")) AS ?researchersUrl)
34+
WHERE {
35+
INCLUDE %researchers
36+
INCLUDE %works
37+
{
38+
# GROUP_CONCAT cannot honor sorting, but this was an attempt
39+
SELECT
40+
?work ?researcher ?researcher_label
41+
WHERE {
42+
?work p:P50 [ ps:P50 ?researcher ; pq:P1545 ?order ] .
43+
BIND(xsd:integer(?order) AS ?n)
44+
?researcher rdfs:label ?researcher_label . FILTER (LANG(?researcher_label) = 'en')
45+
}
46+
ORDER BY ?n
47+
}
48+
}
49+
GROUP BY ?work
2550
} AS %results
2651
WHERE {
52+
INCLUDE %works
2753
INCLUDE %results
2854
BIND(xsd:date(?publication_datetime) AS ?publication_date)
2955
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" . }

scholia/app/templates/work_data.sparql

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,23 @@ WHERE {
2727
(CONCAT("../authors/", GROUP_CONCAT(?q; separator=",")) AS ?valueUrl)
2828
{
2929
BIND(1 AS ?dummy)
30-
target: wdt:P50 ?iri .
31-
BIND(SUBSTR(STR(?iri), 32) AS ?q)
32-
?iri rdfs:label ?value_string .
33-
FILTER (LANG(?value_string) = 'en')
34-
BIND(COALESCE(?value_string, ?q) AS ?value_)
30+
{
31+
# GROUP_CONCAT does not order by standard but BlazeGraph seems to order
32+
# so we are hoping the sorting is correct here.
33+
SELECT
34+
?value_ ?q
35+
WHERE {
36+
target: p:P50 ?author_statement .
37+
?author_statement ps:P50 ?author .
38+
BIND(SUBSTR(STR(?author), 32) AS ?q)
39+
?author_statement pq:P1545 ?order .
40+
BIND(xsd:integer(?order) AS ?n)
41+
?author rdfs:label ?value_string .
42+
FILTER (LANG(?value_string) = 'en')
43+
BIND(COALESCE(?value_string, ?q) AS ?value_)
44+
}
45+
ORDER BY ?n
46+
}
3547
}
3648
GROUP BY ?dummy
3749
}

0 commit comments

Comments
 (0)