use of com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner in project stanbol by apache.
the class JenaAdapter method main.
public static void main(String[] args) {
RuleAdapter ruleAdapter = new JenaAdapter();
try {
KB kb = RuleParserImpl.parse("http://sssw.org/2012/rules/", new FileInputStream("/Users/mac/Documents/CNR/SSSW2012/rules/exercise1"));
System.out.println("Rules: " + kb.getRuleList().size());
Recipe recipe = new RecipeImpl(new IRI("http://sssw.org/2012/rules/"), "Recipe", kb.getRuleList());
List<com.hp.hpl.jena.reasoner.rulesys.Rule> jenaRules = (List<com.hp.hpl.jena.reasoner.rulesys.Rule>) ruleAdapter.adaptTo(recipe, com.hp.hpl.jena.reasoner.rulesys.Rule.class);
String rules = "[ Exercise1: (http://dbpedia.org/resource/Madrid http://dbpedia.org/ontology/locationOf ?location) (?location rdf:type http://dbpedia.org/ontology/Museum) (?location http://dbpedia.org/ontology/numberOfVisitors ?visitors) greaterThan(?visitors '2000000'^^http://www.w3.org/2001/XMLSchema#integer) -> (?location rdf:type http://www.mytravels.com/Itinerary/MadridItinerary) ]";
//List<com.hp.hpl.jena.reasoner.rulesys.Rule> jenaRules = com.hp.hpl.jena.reasoner.rulesys.Rule.parseRules(rules);
for (com.hp.hpl.jena.reasoner.rulesys.Rule jenaRule : jenaRules) {
System.out.println(jenaRule.toString());
}
Model m = ModelFactory.createDefaultModel();
Resource configuration = m.createResource();
configuration.addProperty(ReasonerVocabulary.PROPruleMode, "hybrid");
//Model model = FileManager.get().loadModel("/Users/mac/Documents/workspaceMyStanbol/sssw2012/events.rdf");
Model model = FileManager.get().loadModel("/Users/mac/Documents/CNR/SSSW2012/datasets_new/Exercise1.rdf");
//GenericRuleReasoner reasoner = new GenericRuleReasoner(jenaRules);
//GenericRuleReasoner reasoner = new GenericRuleReasoner(com.hp.hpl.jena.reasoner.rulesys.Rule.parseRules(rules));
GenericRuleReasoner reasoner = new GenericRuleReasoner(jenaRules);
// not needed in RDFS case
reasoner.setOWLTranslation(true);
reasoner.setTransitiveClosureCaching(true);
InfModel infModel = ModelFactory.createInfModel(reasoner, model);
infModel.prepare();
infModel.getDeductionsModel().write(System.out);
//String sparql = "select * where {?s a <http://www.mytravels.com/Itinerary/MovieCityMuseums> }";
//String sparql = "select * where {?s a <http://www.mytravels.com/Itinerary/CityEventItinerary> }";
String sparql = "select * where {?s a <http://www.mytravels.com/Itinerary/MadridItinerary> }";
//String sparql = "select * where {?s a <http://linkedevents.org/ontology/cazzo> }";
//String sparql = "select * where {?s a <http://www.mytravels.com/Itinerary/MovieCityItinerary> }";
Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
QueryExecution queryExecution = QueryExecutionFactory.create(query, infModel);
com.hp.hpl.jena.query.ResultSet resultSet = queryExecution.execSelect();
ResultSetFormatter.out(System.out, resultSet);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RuleAtomCallExeption e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnavailableRuleObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedTypeForExportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations