Christopher Johnson (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/250224
Change subject: adds property label sparql lookup for getclaims property graph
title
......................................................................
adds property label sparql lookup for getclaims property graph title
Change-Id: Ida651d108d7a55f3e0a80ea7fbfd3a01757f7617
---
M src/utils.R
1 file changed, 27 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/wikidata/analytics/dashboard
refs/changes/24/250224/1
diff --git a/src/utils.R b/src/utils.R
index 9bca13b..e1a13de 100644
--- a/src/utils.R
+++ b/src/utils.R
@@ -202,12 +202,38 @@
setkey(dt_getclaims_file, property)
dt_getclaims_property <- dt_getclaims_file[params_property]
dt_getclaims_property <- dt_getclaims_property[,.SD,.SDcols=c(1,3)]
+ title_query <- get_property_label_query(params_property)
+ pfx <- get_property_label_prefixes()
+ title <- get_sparql_result(wdqs_uri, pfx, title_query)
return(dygraph(dt_getclaims_property,
- main = params_property,
+ main = paste0(params_property, " : ", title$text),
ylab = "") %>%
dyOptions(useDataTimezone = TRUE,
labelsKMB = TRUE,
fillGraph = TRUE,
strokeWidth = 2, colors = brewer.pal(5, "Set2")[5:1]) %>%
dyCSS(css = custom_css))
+}
+
+get_property_label_query <- function(params_property){
+ query = curl_escape(paste0("SELECT distinct ?o WHERE {wd:",params_property,
" ?p ?o
+ SERVICE wikibase:label {
+ bd:serviceParam wikibase:language \"en\" .
+ wd:",params_property," rdfs:label ?o
+ }
+ }"))
+ return(query)
+}
+
+get_property_label_prefixes <- function(){
+ prefixes <-
"PREFIX%20wd%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3EPREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3EPREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E"
+ return(prefixes)
+}
+
+get_sparql_result <- function(uri = wdqs_uri, prefix, query) {
+ # escape_query <- curl_escape(query)
+ xml_result <- readLines(curl(paste0(uri, prefix, query)))
+ doc = xmlParse(xml_result)
+ result = xmlToDataFrame(nodes = getNodeSet(doc, "//sq:literal", c(sq =
"http://www.w3.org/2005/sparql-results#")))
+ return(result)
}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/250224
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida651d108d7a55f3e0a80ea7fbfd3a01757f7617
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/analytics/dashboard
Gerrit-Branch: master
Gerrit-Owner: Christopher Johnson (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits