Difference between revisions of "Template:SPARQLPredicateGraph"

From Wikibase Personal data
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
#defaultView:Graph
 
#defaultView:Graph
SELECT ?item1 ?item1Label ?rgb ?item2 ?item2Label ?link
+
SELECT ?item1 ?item1Label ?rgb ?item2 ?item2Label
 
WITH {
 
WITH {
 
   SELECT ?predicateFilterValue ?predicateFilterValueRGB WHERE {
 
   SELECT ?predicateFilterValue ?predicateFilterValueRGB WHERE {
Line 18: Line 18:
 
AS %predicates
 
AS %predicates
 
WITH {SELECT ?node ?nodeRGB WHERE {
 
WITH {SELECT ?node ?nodeRGB WHERE {
     ?node {{{node_condition}}}.
+
     {{#if: {{{node_condition|}}}|?node {{{node_condition}}}.||}}
 
     ?node {{{predicate}}} ?predicateFilterValue.
 
     ?node {{{predicate}}} ?predicateFilterValue.
 
     INCLUDE %predicateFilterValues.
 
     INCLUDE %predicateFilterValues.
Line 31: Line 31:
 
     ?subject ?predicate ?object.
 
     ?subject ?predicate ?object.
 
     # This is filtering for each edge twice, potentially a huge waste: |E|*|V| instead of |V|
 
     # This is filtering for each edge twice, potentially a huge waste: |E|*|V| instead of |V|
     ?subject {{{node_condition}}}.      
+
     {{#if: {{{node_condition|}}}|?subject {{{node_condition}}}.||}}
     ?object {{{node_condition}}}.
+
     {{#if: {{{node_condition|}}}|?object {{{node_condition}}}.||}}
 
     BIND(?predicateRGB as ?edgeRGB)
 
     BIND(?predicateRGB as ?edgeRGB)
 
   }
 
   }
 
} AS %edges
 
} AS %edges
 
WHERE {
 
WHERE {
 +
{{#ifeq:{{{legend|}}}|true|
 
   { # The caption's nodes:  
 
   { # The caption's nodes:  
 
     INCLUDE %predicateFilterValues.
 
     INCLUDE %predicateFilterValues.
 
     BIND(?predicateFilterValue AS ?item1).
 
     BIND(?predicateFilterValue AS ?item1).
 
     BIND(?predicateValueRGB AS ?rgb).
 
     BIND(?predicateValueRGB AS ?rgb).
    BIND(?nodeSize AS 5).
 
 
   }  
 
   }  
 
   UNION
 
   UNION
Line 49: Line 49:
 
     BIND(?objectValue AS ?item2).
 
     BIND(?objectValue AS ?item2).
 
     BIND(?predicateRGB AS ?rgb).
 
     BIND(?predicateRGB AS ?rgb).
    BIND(?nodeSize AS 5).
 
 
   }
 
   }
 
   UNION
 
   UNION
 +
||}}
 
   {   
 
   {   
 
     INCLUDE %nodes.
 
     INCLUDE %nodes.
 
     BIND(?node AS ?item1).
 
     BIND(?node AS ?item1).
 
     BIND(?nodeRGB AS ?rgb).
 
     BIND(?nodeRGB AS ?rgb).
    BIND(?nodeSize AS 1).
 
 
   }
 
   }
 
   UNION
 
   UNION
Line 64: Line 63:
 
     BIND(?object AS ?item2).
 
     BIND(?object AS ?item2).
 
     BIND(?edgeRGB AS ?rgb).
 
     BIND(?edgeRGB AS ?rgb).
    BIND(?nodeSize AS 1).
 
 
   }
 
   }
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {

Latest revision as of 10:58, 21 May 2019

  1. defaultView:Graph

SELECT ?item1 ?item1Label ?rgb ?item2 ?item2Label WITH {

 SELECT ?predicateFilterValue ?predicateFilterValueRGB WHERE {
   VALUES (?predicateFilterValue ?predicateFilterValueRGB) {
      {{{filter_values_colors}}}
   }  
 }

} AS %predicateFilterValues WITH {

 SELECT ?predicate ?subjectValue ?objectValue ?predicateRGB  WHERE {
   VALUES (?predicate ?subjectValue ?objectValue ?predicateRGB) {
    {{{predicates_subjects_objects_colors}}}
   }
 }

} AS %predicates WITH {SELECT ?node ?nodeRGB WHERE {

   ?node {{{predicate}}} ?predicateFilterValue.
   INCLUDE %predicateFilterValues.
   BIND(?predicateFilterValueRGB AS ?nodeRGB)
 }

} AS %nodes WITH {SELECT ?subject ?object ?edgeRGB WHERE {

   INCLUDE %predicates.
   ?subject {{{predicate}}} ?subjectValue.
   ?object {{{predicate}}} ?objectValue.
   ?subject ?predicate ?object.
   # This is filtering for each edge twice, potentially a huge waste: |E|*|V| instead of |V|
   
   
   BIND(?predicateRGB as ?edgeRGB)
 }

} AS %edges WHERE {

 {  
    INCLUDE %nodes.
    BIND(?node AS ?item1).
    BIND(?nodeRGB AS ?rgb).
 }
 UNION
 {  
    INCLUDE %edges.
    BIND(?subject AS ?item1).
    BIND(?object AS ?item2).
    BIND(?edgeRGB AS ?rgb).
 }
 SERVICE wikibase:label {
   bd:serviceParam wikibase:language "en" . 
 }

} LIMIT 10000