The key is to recognize that in Yen, Model is one of the central abstractions. The output model is just a Model , in which some of the triples are present, because they are associated with the output rules, and are not read from the source document. Thus, you only need to change the first line of your example, where you first create the model.
While you can create output models directly, it is often easiest to create an OntModel with the required degree of output support:
Model model = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM_RDFS_INF );
If you need another argument or OWL support, you can choose another OntModelSpec constant. Keep in mind that large and / or complex models can perform slow queries.
Refresh (after editing the original question)
To reason on two models, you need an alliance. You can do this with OntModel submodeling. I would modify your example as follows (note: I have not tested this code, but it should work):
String rdfFile = "... your RDF file location ..."; Model source = FileManager.get().loadModel( rdfFile ); String ontFile = "... your ontology file location ..."; Model ont = FileManager.get().loadModel( ontFile ); Model m = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM_RDFS_INF, ont ); m.addSubModel( source ); String queryString = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX wn:<http://www.webkb.org/theKB_terms.rdf/wn#> " + "SELECT ?person " + "WHERE {" + " ?person rdf:type wn:Person . " + " }"; Query query = QueryFactory.create(queryString); QueryExecution qe = QueryExecutionFactory.create(query, m); ResultSet results = qe.execSelect(); ResultSetFormatter.out(System.out, results, query); qe.close();
source share