Try to add a reasoner. Not properly working now.
This commit is contained in:
		
							parent
							
								
									08a8c05b2d
								
							
						
					
					
						commit
						6d245000fd
					
				| @ -1,16 +1,19 @@ | ||||
| package hsh.ins_jena; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.InputStream; | ||||
| import java.util.Iterator; | ||||
| 
 | ||||
| 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.rdf.model.InfModel; | ||||
| import org.apache.jena.rdf.model.Model; | ||||
| import org.apache.jena.rdf.model.ModelFactory; | ||||
| import org.apache.jena.reasoner.Reasoner; | ||||
| import org.apache.jena.reasoner.ReasonerRegistry; | ||||
| import org.apache.jena.reasoner.ValidityReport; | ||||
| import org.apache.jena.util.FileManager; | ||||
| 
 | ||||
| import hsh.ins_jena.model.Generator; | ||||
| 
 | ||||
| @ -24,27 +27,46 @@ public class App { | ||||
| 	} | ||||
| 
 | ||||
| 	private static void readAndHandleFiles(String inputPath) { | ||||
| 		Model model = ModelFactory.createDefaultModel(); | ||||
| 		Model tboxModel = FileManager.get().loadModel("file:" + inputPath + "/" + Generator.T_BOX_FILENAME_XML); | ||||
| 		Model aboxModel = FileManager.get().loadModel("file:" + inputPath + "/" + Generator.T_BOX_FILENAME_XML); | ||||
| 
 | ||||
| 		InputStream inT, inA; | ||||
| 		try { | ||||
| 			inT = new FileInputStream(new File(inputPath + "/" + Generator.T_BOX_FILENAME_XML)); | ||||
| 			inA = new FileInputStream(new File(inputPath + "/" + Generator.A_BOX_FILENAME_XML)); | ||||
| 			model.read(inT, ""); | ||||
| 			model.read(inA, ""); | ||||
| 		} catch (FileNotFoundException e) { | ||||
| 			e.printStackTrace(); | ||||
| 		// Combine both models to an RDFS model | ||||
| 		InfModel rdfsModel = ModelFactory.createRDFSModel(tboxModel, aboxModel); | ||||
| 		 | ||||
| 		// Do some validity checking | ||||
| 		ValidityReport validity = rdfsModel.validate(); | ||||
| 		if (validity.isValid()) { | ||||
| 		    System.out.println("\nValidity Report: OK"); | ||||
| 		} else { | ||||
| 		    System.out.println("\nValidity Report: Conflicts!"); | ||||
| 		    for (Iterator<ValidityReport.Report> i = validity.getReports(); i.hasNext(); ) { | ||||
| 		        ValidityReport.Report report = (ValidityReport.Report)i.next(); | ||||
| 		        System.out.println(" - " + report); | ||||
| 		    } | ||||
| 		} | ||||
| 		 | ||||
| 		// Let's create an rdfs reasoner | ||||
| 		Reasoner rdfsReasoner = ReasonerRegistry.getRDFSReasoner(); | ||||
| 		rdfsReasoner = rdfsReasoner.bindSchema(tboxModel); | ||||
| 		InfModel infModel = ModelFactory.createInfModel(rdfsReasoner, rdfsModel); | ||||
| 
 | ||||
| 		System.err.println("Loaded model:"); | ||||
| 		System.out.println(model); | ||||
| 
 | ||||
| 		System.err.println("infModel"); | ||||
| 		System.out.println(infModel); | ||||
| 		 | ||||
| 		Query queryReleaseYear = QueryFactory.create( | ||||
| 				"PREFIX : <" + Generator.OWN_URI + ">"  | ||||
| 				+ "SELECT ?console\n" | ||||
| 				+ "WHERE {\n" + "  ?console :madeBy :Nintendo .\n" + "  ?console :releaseYear ?releaseYear .  \n" | ||||
| 				+ "  FILTER(?releaseYear > 2015)\n" + "}"); | ||||
| 		 | ||||
| 		Query queryConsoles = QueryFactory.create( | ||||
| 				"PREFIX : <" + Generator.OWN_URI + ">"  | ||||
| 				+ "SELECT ?console\n" | ||||
| 				+ "WHERE {\n"  | ||||
| 				+ "  ?console :madeBy :Nintendo .\n" | ||||
| 				+ "}"); | ||||
| 
 | ||||
| 		 | ||||
| 		Query queryCEOForConsole = QueryFactory.create( | ||||
| 			"PREFIX : <" + Generator.OWN_URI + ">" + | ||||
| 			"PREFIX rdf: <" + Generator.RDF_URI + ">" + | ||||
| @ -61,19 +83,23 @@ public class App { | ||||
| 			"}\n" +  | ||||
| 			""); | ||||
| 
 | ||||
| //		Query query = QueryFactory | ||||
| //				.create("PREFIX : <" + Generator.OWN_URI + ">" + " " + " SELECT ?s ?p ?p WHERE {" + "?s ?p ?o .}"); | ||||
| 		//Query queryAll = QueryFactory.create("PREFIX : <" + Generator.OWN_URI + ">" + " " + " SELECT ?s ?p ?p WHERE {" + "?s ?p ?o .}"); | ||||
| 
 | ||||
| 		QueryExecution queryExecLocalReleaseDate = QueryExecutionFactory.create(queryReleaseYear, model); | ||||
| 		QueryExecution queryExecRemoteReleaseDate = QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT,queryReleaseYear); | ||||
| 		QueryExecution queryExecLocalConsoles = QueryExecutionFactory.create(queryConsoles, infModel); | ||||
| 		System.err.println("Show consoles from local model"); | ||||
| 		printQueryResult(queryExecLocalConsoles); | ||||
| 		 | ||||
| 		QueryExecution queryExecLocalCEOtoConsole = QueryExecutionFactory.create(queryCEOForConsole, model); | ||||
| 		QueryExecution queryExecRemoteCEOtoConsole = QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT,queryCEOForConsole); | ||||
| 		 | ||||
| 		QueryExecution queryExecLocalReleaseDate = QueryExecutionFactory.create(queryReleaseYear, infModel); | ||||
| 		QueryExecution queryExecRemoteReleaseDate = QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT, queryReleaseYear); | ||||
| 		 | ||||
| 		QueryExecution queryExecLocalCEOtoConsole = QueryExecutionFactory.create(queryCEOForConsole, infModel); | ||||
| 		QueryExecution queryExecRemoteCEOtoConsole = QueryExecutionFactory.sparqlService(SPARQL_ENDPOINT, queryCEOForConsole); | ||||
| 		 | ||||
| 		System.err.println("Doing local release date query"); | ||||
| 		printQueryResult(queryExecLocalReleaseDate);  | ||||
| 		printQueryResult(queryExecLocalReleaseDate); | ||||
| 		System.err.println("Doing remote release date query"); | ||||
| 		printQueryResult(queryExecRemoteReleaseDate);  | ||||
| 		printQueryResult(queryExecRemoteReleaseDate); | ||||
| 		 | ||||
| 		System.err.println("Doing local CEO query"); | ||||
| 		printQueryConstructs(queryExecLocalCEOtoConsole); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user