Graph Statistics: Difference between revisions

m (→‎Degree of Item: update query to show degree=indegree+outdegree)
(→‎Degree of Item: added Sinks & Sources query)
Line 61: Line 61:
}}
}}
''Change harcoded item to parameter''
''Change harcoded item to parameter''
=== Sinks ===
Returns sinks, items with '''0 indegrees'''.
These items can be regarded as destinations to a path.
{{SPARQL2|query=
#defaultView:Table
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
Select ?item ?itemLabel
(count(DISTINCT ?inItem) as ?indegree)
(count(DISTINCT ?outItem) as ?outdegree)
WHERE {
  ?item wikibase:identifiers ?i. # get only items
 
  # filter out...
  MINUS {?inItem wdt:P1 ?item.} # all items with 1+ indegree
  MINUS {?item wdt:P3 wd:Q167.} # all students
  MINUS {?item wdt:P3 wd:Q169.} # all categories
  MINUS {?item wdt:P3 wd:Q427.} # all sessions
  MINUS {?inItem wdt:P21 ?item.} # all resources
 
  # show 0+ outdegrees of the items
  OPTIONAL {?item wdt:P1 ?outItem.}
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
group by ?item ?itemLabel
ORDER BY DESC(?item)
LIMIT 50 # change as needed
}}
=== Sources ===
Returns sources, items with '''0 outdegrees'''.
These items can be regarded as origins to a path.
{{SPARQL2|query=
#defaultView:Table
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
Select ?item ?itemLabel
(count(DISTINCT ?outItem) as ?outdegree)
(count(DISTINCT ?inItem) as ?indegree)
WHERE {
  ?item wikibase:identifiers ?i. # get only items
 
  # filter out...
  MINUS {?item wdt:P1 ?outItem.} # all items with 1+ outdegree
  MINUS {?item wdt:P3 wd:Q167.} # all students
  MINUS {?item wdt:P3 wd:Q169.} # all categories
  MINUS {?item wdt:P3 wd:Q427.} # all sessions
  MINUS {?inItem wdt:P21 ?item.} # all resources
 
  # show 0+ outdegrees of the items
  OPTIONAL {
    ?inItem wdt:P1 ?item.
  }
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
group by ?item ?itemLabel
ORDER BY DESC(?item)
LIMIT 50 # change as needed
}}

Revision as of 10:03, 28 November 2023

A page to help show the structure of the graph using metrics and statistics. For similar pages reference:

Simple Metrics

ItemCount

Gives a count of all items in the Wikibase-instance. Items used: Student (Q167)

Properties used: instance of (P3)

#defaultView:Table
PREFIX wd:  <https://graphit.ur.de/entity>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
SELECT (COUNT(*) as ?items) 
WHERE {
  # items that have 0+ statements
  ?item wikibase:statements ?s.
  MINUS{ ?item a wikibase:Property } # Filter out properties
  MINUS{ ?item wdt:P3 wd:Q167 } # Filter out students
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} LIMIT 25

Try it!


Make inline

PropertyCount

Gives a count of all properties in the Wikibase-instance



#defaultView:Table
PREFIX wd:  <https://graphit.ur.de/entity>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
SELECT (COUNT(*) as ?property) 
WHERE {
  ?property a wikibase:Property.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} LIMIT 28

Try it!


Make inline

Degree of Item

Gives back the indegree and outdegree of a specific item.

  • InDegree = all dependencies (P1) going in to the item
  • OutDegree = all dependencies (P1) comming out of an item

To get all edges coming out of an item, change wdt:P1 to ?p. This will include things such as resources and dates.

Items used: Matrix Multiplication (Q93)

Properties used: depends on (P1)

#defaultView:Table
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
Select ?item ?itemLabel
(count(DISTINCT ?inItem) as ?indegree)
(count(DISTINCT ?outItem) as ?outdegree)
((?indegree + ?outdegree ) AS ?degree)
WHERE { 
  BIND (wd:Q93 as ?item).
  OPTIONAL {
    ?inItem wdt:P1 ?item. # inDegree
    ?item wdt:P1 ?outItem. # outDegree
  } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?item ?itemLabel

Try it!


Change harcoded item to parameter

Sinks

Returns sinks, items with 0 indegrees. These items can be regarded as destinations to a path.

Items used: Student (Q167), Category (Q169), Session (Q427)

Properties used: depends on (P1), instance of (P3), resource (P21)

#defaultView:Table
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
Select ?item ?itemLabel
(count(DISTINCT ?inItem) as ?indegree)
(count(DISTINCT ?outItem) as ?outdegree)
WHERE { 
  ?item wikibase:identifiers ?i. # get only items
  
  # filter out...
  MINUS {?inItem wdt:P1 ?item.} # all items with 1+ indegree
  MINUS {?item wdt:P3 wd:Q167.} # all students 
  MINUS {?item wdt:P3 wd:Q169.} # all categories 
  MINUS {?item wdt:P3 wd:Q427.} # all sessions
  MINUS {?inItem wdt:P21 ?item.} # all resources
  
  # show 0+ outdegrees of the items
  OPTIONAL {?item wdt:P1 ?outItem.}
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} 
group by ?item ?itemLabel
ORDER BY DESC(?item)
LIMIT 50 # change as needed

Try it!


Sources

Returns sources, items with 0 outdegrees. These items can be regarded as origins to a path.

Items used: Student (Q167), Category (Q169), Session (Q427)

Properties used: depends on (P1), instance of (P3), resource (P21)

#defaultView:Table
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
Select ?item ?itemLabel
(count(DISTINCT ?outItem) as ?outdegree)
(count(DISTINCT ?inItem) as ?indegree)
WHERE { 
  ?item wikibase:identifiers ?i. # get only items
  
  # filter out...
  MINUS {?item wdt:P1 ?outItem.} # all items with 1+ outdegree
  MINUS {?item wdt:P3 wd:Q167.} # all students 
  MINUS {?item wdt:P3 wd:Q169.} # all categories 
  MINUS {?item wdt:P3 wd:Q427.} # all sessions
  MINUS {?inItem wdt:P21 ?item.} # all resources
  
  # show 0+ outdegrees of the items
  OPTIONAL {
    ?inItem wdt:P1 ?item.
  }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} 
group by ?item ?itemLabel
ORDER BY DESC(?item)
LIMIT 50 # change as needed

Try it!