Semantic Technology: SPARQL Demonstration

This application allows you to enter SPARQL queries against an example triple store. The triple store contains actual mileage information from two hybrid cars.

This uses the Joseki ( SPARQL server. My intent is to create a SPARQL endpoint and simple form for human access to the data. Longer term I will be expanding the ontology to relate this data to upper ontologies as well as ontologies that allow me to utilize semantically-aware graphical reporting tools.

Feel free to experiment. The current version of the ontology and data is located at The ontology itself is shown at the bottom of this page so that you can reference the existing structure for the data.

Sample SPARQL queries are located beneath the form, you can copy and paste these into the text area to see the results.

XML Stylesheet (applies to XML choice only, blank for none):
Force the accept header to text/plain:

Sample Query: List all the fuel purchases for car 3 with date, gas station name, average MPH and actual MPG. Order the output by the purchase date.

prefix veh:  <>
prefix pveh: <>

select ?purchaseDate ?stationName ?gallons ?dollarsPerGallon ?totalDollarsPaid ?averageMph ?actualMpg where { 
		?thePurchase a veh:FuelPurchase .
		?thePurchase veh:vehicle pveh:car3 .
		?thePurchase veh:date ?purchaseDate .
		?thePurchase veh:purchaseStation ?theStation .
		?theStation veh:stationName ?stationName .
		?thePurchase veh:averageMph ?averageMph .
		?thePurchase veh:actualMpg ?actualMpg .
		?thePurchase veh:gallons ?gallons .
		?thePurchase veh:usDollarsPerGallon ?dollarsPerGallon .
		?thePurchase veh:totalUsDollarsCharged ?totalDollarsPaid .
order by ?purchaseDate

Sample Query: List all the fuel purchases for car 1 with date and gas station name

prefix veh:  <>
prefix pveh: <>

select ?thePurchase ?purchaseDate ?stationName where { 
		?thePurchase a veh:FuelPurchase .
		?thePurchase veh:vehicle pveh:car1 .
		?thePurchase veh:date ?purchaseDate .
		?thePurchase veh:purchaseStation ?theStation .
		?theStation veh:stationName ?stationName

Sample Query: List the number of times that fuel was purchased at each gas station for car 2

prefix veh:  <>
prefix pveh: <>

select (count(distinct ?purchase) as ?count) ?station ?stationName ?placeName where {
		?purchase a veh:FuelPurchase .
		?purchase veh:vehicle pveh:car2 .
		?purchase veh:purchaseStation ?station .
		?station veh:stationName ?stationName .
		?station veh:location ?location .
		?location veh:placeName ?placeName
group by ?station ?stationName ?placeName

Sample Query: For any fuel purchases with comments, list the purchase and comment

prefix veh:  <>

select ?purchase ?vehicle ?comment where {
		?purchase veh:comment ?comment .
		?purchase veh:vehicle ?vehicle

Sample Query: List date and mpg for all fuel purchases for car 2

prefix veh:  <>
prefix pveh: <>

select ?date ?mpg { 
		?fuelpurch a veh:FuelPurchase .
		?fuelpurch veh:vehicle pveh:car2 .
		?fuelpurch veh:actualMpg ?mpg .
		?fuelpurch veh:date ?date 

Sample Query: List purchases where the amount charged versus owed are different (likely due to rounding)

prefix veh:  <>

select ?thePurchase ?theVendor ?theLocation ?theCharge ?theAmountOwed { 
		?thePurchase a veh:FuelPurchase .
		?thePurchase veh:totalUsDollarsCharged ?theCharge .
		?thePurchase veh:totalUsDollarsOwed  ?theAmountOwed .
		?thePurchase veh:purchaseStation ?theGasStation .
		?theGasStation veh:stationName ?theVendor .
		?theGasStation veh:location ?thePlace .
		?thePlace veh:placeName ?theLocation .
		FILTER (?theCharge != ?theAmountOwed)

Mileage Ontology

Here is the current ontology (as Turtle) that is used for the sample data

@prefix rdf:  <> .
@prefix rdfs: <> .
@prefix owl:  <> .
@prefix xsd:  <> .
@prefix veh:  <> .
@prefix pveh: <> .

veh:Vehicle a owl:Class.

veh:Automobile a owl:Class.
veh:Automobile rdfs:subClassOf veh:Vehicle.

pveh:Car a owl:Class.
pveh:Car rdfs:subClassOf veh:Automobile.

veh:Manufacturer a owl:Class.
veh:Model a owl:Class.

veh:FuelPurchase a owl:Class.
veh:GasStation a owl:Class.
veh:Place a owl:Class.

veh:year a owl:DatatypeProperty.

veh:name a owl:DatatypeProperty.

veh:manufacturer a owl:ObjectProperty;
	rdfs:domain veh:Vehicle;
	rdfs:range veh:Manufacturer.

veh:model a owl:ObjectProperty;
	rdfs:domain veh:Vehicle;
	rdfs:range veh:Model.

veh:stationName a owl:DatatypeProperty;
	rdfs:domain veh:GasStation.

veh:location a owl:ObjectProperty;
	rdfs:domain veh:GasStation;
	rdfs:range veh:Place.

veh:placeName a owl:DatatypeProperty;
	rdfs:domain veh:Place.

veh:vehicle a owl:ObjectProperty;
	rdfs:domain veh:FuelPurchase;
	rdfs:range veh:Vehicle.

veh:octaneRating a owl:DatatypeProperty;
	rdfs:domain veh:FuelPurchase.

veh:date a owl:DatatypeProperty.
#	rdfs:range xsd:date.(using YYYY-MM-DD values produces an error with Pellet 2.2.1)
veh:gallons a owl:DatatypeProperty.
veh:usDollarsPerGallon a owl:DatatypeProperty.
veh:totalUsDollarsCharged a owl:DatatypeProperty.
veh:totalUsDollarsOwed a owl:DatatypeProperty.
veh:reportedMpg a owl:DatatypeProperty.
veh:averageMph a owl:DatatypeProperty.
veh:milesTraveled a owl:DatatypeProperty.
veh:odometerReading a owl:DatatypeProperty.
veh:actualMpg a owl:DatatypeProperty.

veh:purchaseStation a owl:ObjectProperty;
	rdfs:domain veh:FuelPurchase;
	rdfs:range veh:GasStation.

veh:comment a owl:DatatypeProperty.