001 package es.ucm.fdi.gaia.ontobridge.test; 002 003 import java.util.ArrayList; 004 005 import com.hp.hpl.jena.rdf.model.Model; 006 007 import es.ucm.fdi.gaia.ontobridge.OntoBridge; 008 import es.ucm.fdi.gaia.ontobridge.OntologyDocument; 009 import es.ucm.fdi.gaia.ontobridge.SPARQL; 010 011 /** 012 * File used for testing the SPARQL class using the restaurants ontology. 013 * 014 * @author Antonio A. Sánchez Ruiz-Granados 015 */ 016 public class Test7 { 017 018 public static void main(String args[]) { 019 OntoBridge ob = new OntoBridge(); 020 ob.initWithPelletReasoner(); 021 022 OntologyDocument mainOnto = new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/restaurant.owl","file:test/restaurant.owl"); 023 024 ArrayList<OntologyDocument> subOntologies = new ArrayList<OntologyDocument>(); 025 subOntologies.add(new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/calendar.owl","file:test/calendar.owl")); 026 subOntologies.add(new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/price.owl","file:test/price.owl")); 027 subOntologies.add(new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/address.owl","file:test/address.owl")); 028 subOntologies.add(new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/contact-details.owl","file:test/contact-details.owl")); 029 030 ob.loadOntology(mainOnto, subOntologies, false); 031 032 SPARQL sparql = new SPARQL(ob); 033 034 System.out.println(); 035 System.out.println("SPARQL SELECT query: subclasses of Cuisine"); 036 String query1 = 037 "PREFIX ro: <http://gaia.fdi.ucm.es/ontologies/restaurant.owl#> " + 038 "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + 039 "SELECT DISTINCT ?a " + 040 "WHERE { ?a rdfs:subClassOf ro:Cuisine } " + 041 "ORDER BY ?a"; 042 sparql.execSelectQueryAndPrint(query1, System.out); 043 044 System.out.println(); 045 System.out.println("SPARQL ASQ query: are there any instances with name 'restaurant1'?"); 046 String query2 = 047 "PREFIX ro: <http://gaia.fdi.ucm.es/ontologies/restaurant.owl#> " + 048 "ASK { ?a ro:name \"restaurant1\" }"; 049 System.out.println(sparql.execAskQuery(query2)); 050 051 System.out.println(); 052 System.out.println("SPARQL CONSTRUCT query: new model with the instances of Restaurant"); 053 String query3 = 054 "PREFIX ro: <http://gaia.fdi.ucm.es/ontologies/restaurant.owl#> " + 055 "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + 056 "CONSTRUCT { ?a rdf:type ro:Cuisine } " + 057 "WHERE { ?a rdf:type ro:Restaurant }"; 058 Model m3 = sparql.execConstructQuery(query3); 059 m3.write(System.out, /*"N-TRIPLE"*/ "RDF/XML-ABBREV"); 060 061 System.out.println(); 062 System.out.println("SPARQL DESCRIBE query: new model with a description of the instances of Restaurant"); 063 String query4 = 064 "PREFIX ro: <http://gaia.fdi.ucm.es/ontologies/restaurant.owl#> " + 065 "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + 066 "DESCRIBE ?a " + 067 "WHERE { ?a rdf:type ro:Restaurant }"; 068 Model m4 = sparql.execDescribeQuery(query4);; 069 m4.write(System.out, /*"N-TRIPLE"*/ "RDF/XML-ABBREV"); 070 } 071 }