Skip to main content

Visualization library for SPARQL query results

Project description

VizKG

Open In Colab Python Versions PyPI Version PyPI License

VizKG, a visualization library for SPARQL query results over KGs. VizKG links SPARQL query results and external visualization libraries by mapping query variables to the visualization components needed, currently allowing for 24 types of visualizations. Not only that, VizKG also provides visualization recommendations for arbitrary SPARQL query result.

Update feature v.1.0.9

VizKG now features SPARQL endpoint access with basic authentication where users can use the feature at their own risk. The purpose of VizKG is for educational only.

Installation

Use the package manager pip to install VizKG.

pip install VizKG

Usage

# Import the library
import VizKG.visualize as vkg

Visualization Recommendation

VizKG returns the automated visualization when there is no chart type preference given.

#Wikidata: Covid-19 Recoveries, Cases, and Death Growth
sparql_query = """
SELECT ?time ?Recoveries ?Cases ?Deaths WHERE {
  {
    SELECT ?time ?Recoveries WHERE {
      wd:Q84263196 p:P8010 ?countRes .
      FILTER NOT EXISTS { ?countRes pq:P276 ?loc }
      ?countRes ps:P8010 ?Recoveries ;
                   pq:P585 ?time .
    }
  } 
  {
    SELECT ?time ?Cases WHERE {
      wd:Q84263196 p:P1603 ?countRes .
      FILTER NOT EXISTS { ?countRes pq:P276 ?loc }
       ?countRes ps:P1603 ?Cases ;
                   pq:P585 ?time .
    }
  } 
  {
    SELECT ?time ?Deaths WHERE {
      wd:Q84263196 p:P1120 ?countRes .
      FILTER NOT EXISTS { ?countRes pq:P276 ?loc }
       ?countRes ps:P1120 ?Deaths ;
                   pq:P585 ?time .
    }
  }
}
"""
sparql_service_url = "https://query.wikidata.org/sparql"
chart = vkg(sparql_query=sparql_query, sparql_service_url=sparql_service_url)
chart.plot()

WD:COVID-19 Growth

Use Case Examples

Wikidata: COVID-19 Vaccine Origins

sparql_query = """
SELECT DISTINCT ?vaccineLabel ?originCountry  {
  ?vaccine wdt:P1924 wd:Q84263196 .
  ?vaccine wdt:P178 ?developer.
  ?vaccine rdfs:label ?vaccineLabel .
  ?developer wdt:P17 ?origin . 
  ?origin rdfs:label ?originCountry .
  FILTER (LANG(?vaccineLabel) = 'en').
  FILTER (LANG(?originCountry) = 'en').
}LIMIT 25
"""
#to query another endpoint, change the URL for the service and the query
sparql_service_url = "https://query.wikidata.org/sparql"
chart = vkg(sparql_query=sparql_query, sparql_service_url=sparql_service_url, chart='sunburst')
chart.plot()

WD:COVID-19 Vaccine origins

DBpedia: Map of Temples in Indonesia

sparql_query = """
SELECT * WHERE {
  ?item dbo:wikiPageWikiLink dbr:Candi_of_Indonesia;
        geo:geometry ?geo .
  ?item rdfs:label ?itemLabel.
  FILTER((LANG(?itemLabel)) = "en")
}
"""
#to query another endpoint, change the URL for the service and the query
sparql_service_url = "https://dbpedia.org/sparql/"
chart = vkg(sparql_query=sparql_query, sparql_service_url=sparql_service_url, chart='map')
chart.plot()

DBpedia:Map of Temples in Indonesia

OU_UK: Number of Employees by Job Title

sparql_query = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX schema: <http://schema.org/jobTitle>

SELECT DISTINCT ?jobTitle (COUNT(?jobTitle) as ?count) WHERE {?s a foaf:Person .
  ?s <http://schema.org/jobTitle> ?jobTitle .
  FILTER (lang(?jobTitle) != 'en')
}
GROUP BY ?jobTitle
HAVING (?count > 10)
"""
#to query another endpoint, change the URL for the service and the query
sparql_service_url = "https://data.open.ac.uk/sparql"
chart = vkg(sparql_query=sparql_query, sparql_service_url=sparql_service_url, chart='TreeMap')
chart.plot()

OU_UK:Number of Employees by Job Title

Budaya KB: Number of Temples by Indonesian Regencies

sparql_query = """
prefix bkb: <https://budayakb.cs.ui.ac.id/ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>


SELECT ?provLabel (COUNT(?temple) AS ?numTemple) WHERE {
  ?temple a bkb:Candi .
  ?temple bkb:locationInProvince ?prov .
  ?prov rdfs:label ?provLabel.
  FILTER (lang(?provLabel) = 'id')

} GROUP BY ?provLabel
ORDER BY DESC(?numTemple)
"""
#to query another endpoint, change the URL for the service and the query
sparql_service_url = "https://budayakb.cs.ui.ac.id/budaya/sparql"
chart = vkg(sparql_query=sparql_query, sparql_service_url=sparql_service_url, chart='bubble')
chart.plot()

BudayaKB:Number of Temples by Indonesian Regencies

Supported Visualizations

  • Table
  • ImageGrid
  • Map
  • Graph
  • Tree
  • Dimensions
  • Timeline
  • WordCloud
  • Histogram
  • Density Plot
  • Box Plot
  • Violin Plot
  • Line Chart
  • Bar Chart
  • Area Chart
  • Stacked Area Chart
  • Bubble Chart
  • Scatter Chart
  • HeatMap
  • Radar Chart
  • Tree Map
  • SunBurst Chart
  • Pie Chart
  • Donut Chart

Related Work

Tool Framework Data Source Input Type Number of Chart Types
Wikidata Query Service Web-based Wikidata only SPARQL SELECT 14
Dataviz Web-based Wikidata only SPARQL SELECT 23
YASGUI Web-based Generic SPARQL SELECT and SPARQL CONSTRUCT 11
LDVizWiz Web-based Generic SPARQL SELECT/ASK and RDF Data 27
Sparklis Web-based Generic Text 4
Quedi Web-based Generic Text 16
Voyager Web-based Generic Tabular Data 5
S-Paths Web-based Generic RDF Data 10
Gastrodon Python Library Generic RDF Data -
kglab Python Library Generic RDF Data 1
Autoviz Python Library Generic Tabular Data 5
Visualizer Python Library Generic Tabular Data 20

Code Contributors

This project exists thanks to all the people who contribute.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

VizKG-1.0.9.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

VizKG-1.0.9-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file VizKG-1.0.9.tar.gz.

File metadata

  • Download URL: VizKG-1.0.9.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.0 pkginfo/1.7.0 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.8

File hashes

Hashes for VizKG-1.0.9.tar.gz
Algorithm Hash digest
SHA256 6f2a0772135ded3aaa14221aeee087323af50c438c89acc1f0931bba8b0f34ac
MD5 7eb446f8441f230fe44434ffe73bc15d
BLAKE2b-256 2d57227df318a3d536ded408025b6a3e80e1960e2da52f06a4b537e6fd24dc20

See more details on using hashes here.

File details

Details for the file VizKG-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: VizKG-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.0 pkginfo/1.7.0 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.8

File hashes

Hashes for VizKG-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ff952390ecbee8dd678b3d348577b32625e691ef62f5567e1aceebdcee75cefe
MD5 eafe154b6b105bb2c29926e23b6d6c2c
BLAKE2b-256 fda0e0131356793374e44e44ab50f52b8b66c035a2b5728c2dd6286bf350e4e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page