Created
July 19, 2016 04:29
-
-
Save ankunix/f9209ea0ec027e1a2eb7ce9095a8c7b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jena; | |
import org.apache.jena.query.Query; | |
import org.apache.jena.query.QueryExecution; | |
import org.apache.jena.query.QueryExecutionFactory; | |
import org.apache.jena.query.QueryFactory; | |
import org.apache.jena.query.ResultSet; | |
import org.apache.jena.query.ResultSetFormatter; | |
import org.apache.jena.rdf.model.Model; | |
public class Run { | |
public static void main(String[] args) { | |
//Add the statement one by one in your code to manually create the RDF model. | |
// Model model = RDF_Validator.createUnivRDF(); | |
//Remote RDF file location | |
String URI = "https://gist.githubusercontent.com/anonymous/1ad4a9f52579e16f44cc42f85d503395/raw/25324dad6ab11a5e30afba2722e77c80c3724045/asd.rdf"; | |
//Local RDF file location | |
// String URI = "file:///Users/ankushchauhan/assignment2.rdf"; | |
//Read the model from a file | |
Model model = RDF_Validator.RDF_URI_Reader(URI); | |
//View the in-memory RDF Model | |
//model.write(System.out,"RDF/XML-ABBREV"); | |
String queryString1 = "prefix schema: <http://schema.org/>" | |
+ "SELECT * WHERE" | |
+ "{" | |
+ "?provider schema:additionalType \"CP\"." | |
+ "?provider schema:alternateName \"001\"." | |
+ "?provider schema:seeks ?target." | |
+ "?target ?target_property ?target_value." | |
+ "}"; | |
String queryString2 = "prefix schema: <http://schema.org/>" | |
+ "SELECT ?provider (COUNT(?provider) as ?targetCount) WHERE" | |
+ "{" | |
+ "?provider schema:additionalType \"CP\"." | |
+ "?provider schema:alternateName \"001\"." | |
+ "?provider schema:seeks ?target." | |
+ "}" | |
+ "GROUP BY ?provider"; | |
String queryString3 = "prefix schema: <http://schema.org/>" | |
+ "SELECT ?provider (COUNT(?provider) as ?targetCount) WHERE" | |
+ "{" | |
+ "?provider schema:additionalType \"CP\"." | |
+ "?provider schema:alternateName \"001\"." | |
+ "?provider schema:seeks ?target." | |
+ "?target schema:sameAs ?patient." | |
+ "?patient schema:additionalType \"PT\"." | |
+ "}" | |
+ "GROUP BY ?provider"; | |
String queryString4 = "prefix schema: <http://schema.org/>" | |
+ "SELECT ?provider (COUNT(?provider) as ?targetCount) WHERE" | |
+ "{" | |
+ "?provider schema:additionalType \"CP\"." | |
+ "?provider schema:alternateName \"001\"." | |
+ "?provider schema:seeks ?target." | |
+ "?target schema:sameAs ?patient." | |
+ "?patient schema:additionalType \"PT\"." | |
+ "?patient schema:homeLocation ?homeLocation." | |
+ "?homeLocation schema:address ?address." | |
+ "?address schema:postalCode \"30092\"." | |
+ "}" | |
+ "GROUP BY ?provider"; | |
//+ "?patient schema:additionalType \"PT\". ?patient schema:email \"sam.rose@gmail.com\". }"; | |
Query query = QueryFactory.create(queryString); | |
QueryExecution qe = QueryExecutionFactory.create(query, model); | |
ResultSet results = qe.execSelect(); | |
ResultSetFormatter.out(System.out, results, query); | |
qe.close(); | |
//Determining additional triples (for part 2 of the assignment) | |
RDF_Inference.getAllInferences(model); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment