sgvizler.Query Class
Important class. Runs SPARQL query against SPARQL endpoints.
Dependencies:
- sgvizler.util
- sgvizler.namespace
- sgvizler.registry
- sgvizler.parser
- sgvizler.loader
- sgvizler.logger
- sgvizler.defaults
- jQuery
- google.visualization
Example of how to use the Query class:
var sparqlQueryString = "SELECT * {?s ?p ?o} LIMIT 10",
containerID = "myElementID",
Q = new sgvizler.Query();
// Note that default values may be set in the sgvizler object.
Q.query(sparqlQueryString)
.endpointURL("http://dbpedia.org/sparql")
.endpointOutputFormat("json") // Possible values 'xml', 'json', 'jsonp'.
.chartFunction("google.visualization.BarChart") // The name of the function to draw the chart.
.draw(containerID); // Draw the chart in the designated HTML element.
Constructor
Item Index
Methods
- addFrom
- addListener
- chartFunction
- chartFunction
- chartHeight
- chartHeight
- chartWidth
- chartWidth
- clearFroms
- datatableFunction
- datatableFunction
- draw
- endpointOutputFormat
- endpointOutputFormat
- endpointURL
- endpointURL
- fireListener
- getDataTable
- getEncodedQuery
- getGoogleJSON
- getResultRowCount
- insertFrom
- query
- query
- saveDataTable
- saveQueryResults.
- sendQuery
- validatorURL
- validatorURL
Properties
Methods
addFrom
-
url
Add a url as an RDF source to be included in the SPARQL
query in the FROM
block.
Parameters:
-
url
String
addListener
-
name
-
func
Add a function which is to be fired when the
listener named name
is fired.
See fireListener
Example:
addListener("ready", function () { console.log("Ready!") });
chartFunction
-
functionName
Set the name of chart function. The function should be availble in the global object, or registered with dependencies in Sgvizler's registry; see TODO
Parameters:
-
functionName
String
chartHeight
-
height
Set the height of the chart container.
Parameters:
-
height
Number
chartWidth
-
width
Set the width of the chart container.
Parameters:
-
width
Number
clearFroms
()
public
Remove all registered FROMs.
See also addFrom
.
datatableFunction
-
functionName
Set the name of datatable preprocessing function. The function should be availble in the global object, or registered with dependencies in Sgvizler's registry; see TODO
Parameters:
-
functionName
String
draw
-
containerId
Draws the result of the query in a given container.
Parameters:
-
containerId
StringThe elementId of the container to draw the result of the query.
endpointOutputFormat
-
format
Set endpoint output format. Legal values are 'xml'
,
'json'
, 'jsonp'
.
Parameters:
-
format
String
endpointURL
-
url
Set endpoint URL.
Parameters:
-
url
String
Example:
sgvizler.endpointURL('http://sparql.dbpedia.org');
sets this Query object's endpoint to DBpedia.
fireListener
-
name
Fires (runs, executes) all functions registered
on the listener name
.
See addListener
.
Parameters:
-
name
StringThe name of the listener.
getEncodedQuery
()
String
public
Get the query string with prefixes added and encoded for URL insertion.
Returns:
getGoogleJSON
-
data
Converts "raw" query results into Google JSON, using sgvizler.parser.
Parameters:
-
data
ObjectQuery result set
Returns:
JSON edable by google.visualization.DataTable
getResultRowCount
-
dataTable
Sets and returns noOfResults
, i.e., the number of
rows in the query result.
Parameters:
-
dataTable
google.visualization.DataTable
Returns:
insertFrom
()
private
Extends the query string by including the urls in
from
as FROM
statements in the (SPARQL) query
.
saveDataTable
()
jQuery.Promise
private
async
Converts the the query result set into a
google.visualization.DataTable, and if specified,
applies datatable preprocessing function, and saves
the datatable in the private property
dataTable
.
Returns:
A Promise which resolves when the datatable is saved.
saveQueryResults.
()
jQuery.Promise
private
async
Saves the query result set in the private property
results
. Works like a wrapper for sendQuery().
See also saveDataTable().
Returns:
A Promise which resolves when the results are saved.
sendQuery
()
jQuery.Promise
private
async
Sends query to endpoint using AJAX. "Low level" method,
consider using saveQueryResults()
.
Returns:
A Promise containing the query results.
validatorURL
-
url
Set URL to online SPARQL query validator. Appending a SPARQL query to the end of this URL should give a page which validates the given query.
Parameters:
-
url
String
Example:
TODO
Properties
chartOptions
Object
private
Contains properties relevant for chart drawing business. Get and set values using get/setter functions.
Default values are found in sgvizler.defaults (these may be get/set with the get/setter function on the sgvizler class) and are loaded on construction---and get overwritten by properties in the constructed parameter.
dataTable
google.visualization.DataTable
private
DataTable query results.
queryOptions
Object
private
Contains properties relevant for query business. Get and set values using get/setter functions.
Default values are found in sgvizler.defaults (these may be get/set with the get/setter function on the sgvizler class) and are loaded on construction---and get overwritten by properties in the constructed parameter.
queryResult
Object either XML or JSON
private
The raw results as retuned by the endpoint.