WDscholia / scholia

Wikidata-based scholarly profiles
https://scholia.toolforge.org
Other
215 stars 78 forks source link

"Co-occurring topics" on topic aspect should have a DISTINCT count for works #2388

Open fnielsen opened 7 months ago

fnielsen commented 7 months ago

Describe the bug "Co-occurring topics" on topic aspect should have a DISTINCT count for works

To Reproduce Steps to reproduce the behavior:

  1. Go to https://scholia.toolforge.org/topic/Q115564437#topics
  2. Read 138 for count

Expected behavior The count should be lower (83) if it entails works

Suggestion

PREFIX target: <http://www.wikidata.org/entity/Q115564437>

SELECT
  ?works
  (CONCAT("/topics/Q115564437,", SUBSTR(STR(?topic), 32)) AS ?worksUrl)

  ?topic ?topicLabel
  (CONCAT("/topic/", SUBSTR(STR(?topic), 32)) AS ?topicUrl)

  ?example_work ?example_workLabel
  (CONCAT("/work/", SUBSTR(STR(?example_work), 32)) AS ?example_workUrl)
WITH {
  SELECT
    (COUNT(DISTINCT ?work) AS ?works)
    ?topic
    (SAMPLE(?work) AS ?example_work)
  WHERE {
    # Find works for the specific queried topic
    ?work wdt:P921/( wdt:P31*/wdt:P279* | wdt:P361+ | wdt:P1269+) target: .

    # Find co-occuring topics
    ?work wdt:P921 ?topic .

    # Avoid listing the queried topic
    FILTER (target: != ?topic)
  }
  GROUP BY ?topic
} AS %result
WHERE {
  # Label the results
  INCLUDE %result
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,da,de,es,fr,jp,nl,no,ru,sv,zh" . } 
}
ORDER BY DESC(?count)