Advertisement
Guest User

Untitled

a guest
May 27th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.21 KB | None | 0 0
  1. package testing;
  2.  
  3. import com.hp.hpl.jena.query.Query;
  4. import com.hp.hpl.jena.query.QueryExecution;
  5. import com.hp.hpl.jena.query.QueryExecutionFactory;
  6. import com.hp.hpl.jena.query.QueryFactory;
  7. import com.hp.hpl.jena.query.ResultSet;
  8. import com.hp.hpl.jena.query.ResultSetFormatter;
  9. import com.hp.hpl.jena.rdf.model.Model;
  10. import com.hp.hpl.jena.util.FileManager;
  11.  
  12. import exceptions.ReadModelException;
  13.  
  14. public class JenaReader {
  15.     public static void main(String[] args) throws ReadModelException {
  16.  
  17.     Model data = FileManager.get().loadModel("./ProviderSets/amazonOnDemand_fullset0.ttl", "TTL");
  18.  
  19.         test(data);
  20.     }
  21.    
  22.     private static void test(Model model) {
  23.         String q = "PREFIX core: <http://www.linked-usdl.org/ns/usdl-core#>  PREFIX price: <http://www.linked-usdl.org/ns/usdl-price#>  PREFIX pf: <http://jena.hpl.hp.com/ARQ/property#>  PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>  PREFIX gr: <http://purl.org/goodrelations/v1#>  PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>  PREFIX cloudtaxonomy: <http://rdfs.genssiz.org/CloudTaxonomy#> PREFIX spin: <http://spinrdf.org/spin#> SELECT REDUCED ?offering   WHERE {  {  SELECT REDUCED ?offering  WHERE {  ?offering rdf:type core:ServiceOffering.  ?offering core:includes ?serv .  {  ?serv gr:qualitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:Location .  ?f rdfs:label ?value  FILTER regex(?value, 'tokyo', 'i')  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:qualitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:Location .  ?f rdfs:label ?value  FILTER regex(?value, 'tokyo', 'i')  }  }  } . {  SELECT REDUCED ?offering  WHERE {  ?offering rdf:type core:ServiceOffering . ?offering core:includes ?serv .  {  ?serv gr:quantitativeProductOrServiceProperty cloudtaxonomy:MemorySize .  ?f gr:hasValue ?value  FILTER(?value >= 3.7)  }UNION{  ?serv gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:MemorySize .  ?f gr:hasValue ?value  FILTER(?value >= 3.7)  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty cloudtaxonomy:MemorySize .  ?f gr:hasValue ?value  FILTER(?value >= 3.7)  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:MemorySize .  ?f gr:hasValue ?value  FILTER(?value >= 3.7)  } UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:MemorySize .  ?f gr:hasMinValue ?value  FILTER(?value >= 3.7)  }  }  } . {  SELECT REDUCED ?offering  WHERE {  ?offering rdf:type core:ServiceOffering . ?offering core:includes ?serv .  {  ?serv gr:quantitativeProductOrServiceProperty cloudtaxonomy:DiskSize .  ?f gr:hasValue ?value  FILTER(?value >= 150.0)  }UNION{  ?serv gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:DiskSize .  ?f gr:hasValue ?value  FILTER(?value >= 150.0)  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty cloudtaxonomy:DiskSize .  ?f gr:hasValue ?value  FILTER(?value >= 150.0)  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:DiskSize .  ?f gr:hasValue ?value  FILTER(?value >= 150.0)  } UNION{  ?serv core:hasServiceModel ?model .  ?model gr:quantitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:DiskSize .  ?f gr:hasMinValue ?value  FILTER(?value >= 150.0)  }  }  } . {  SELECT REDUCED ?offering  WHERE {  ?offering rdf:type core:ServiceOffering.  ?offering core:includes ?serv .  {  ?serv gr:qualitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:Feature .  ?f rdfs:label ?value  FILTER regex(?value, 'Virtual Machine', 'i')  }UNION{  ?serv core:hasServiceModel ?model .  ?model gr:qualitativeProductOrServiceProperty ?f .  ?f rdf:type cloudtaxonomy:Feature .  ?f rdfs:label ?value  FILTER regex(?value, 'Virtual Machine', 'i')  }  }  }  }";
  24.  
  25.         Query query = QueryFactory.create(q);
  26.         System.out.println(query.toString());
  27.  
  28.         QueryExecution exec = QueryExecutionFactory.create(query,model);
  29.  
  30.         ResultSet results = exec.execSelect(); 
  31.         ResultSetFormatter.out(System.out, results, query);
  32.  
  33.         exec.close();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement