Sunday, 15 January 2012

java - How to write the result of a rule, into a model (in Jena)? -



java - How to write the result of a rule, into a model (in Jena)? -

i working on project need create rules using jena freamwork.

i have created rules , work should. can see output on screen storing result model of ontology have.

i have code :

@prefix ex: <http://www.semanticweb.org/prova_rules_m#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix xsd: <http://www.w3.org/2001/xmlschema#> . @include <owl> [pippo: (?p http://www.semanticweb.org/prova_rules_m#anni_persona ?x) <- (?p rdf:type ex:persona) (?p http://www.semanticweb.org/prova_rules_m/persona#data_nascita ?c) mydiffdateyear(?c,"2014-06-18t00:00:00.0"^^xsd:datetime,?x) ]

in illustration using custom built-in have created previously. returns number of years of difference between 2 dates. can see output in screen next code :

string percorsofile ="./prova_rules_m_rdf.owl"; string rulefile= "./prova_rules_m_rdf_7_diffdate.txt"; model rawmodel = modelfactory.createdefaultmodel(); //create resource (empty model) resource configuration = rawmodel.createresource(); // set engine mode configuration.addproperty(reasonervocabulary.proprulemode, "hybrid"); // set rules file configuration.addproperty(reasonervocabulary.propruleset, rulefile); list<rule> rules = rule.rulesfromurl(rulefile); genericrulereasoner reasonerrule = (genericrulereasoner) genericrulereasonerfactory.theinstance().create(configuration); reasonerrule.setrules(rules); model modelrule= filemanager.get().loadmodel(percorsofile); //create inference model infmodel infmodelrule = modelfactory.createinfmodel(reasonerrule, modelrule); //force starting rule execution infmodelrule.prepare(); //write downwards result in rdfxml form infmodelrule.write(system.out);

how can write result of info property "anni_persona" within model (and not output) ?

thank you.

the way backwards chaining inference rule works when associated model (in case, infmodelrule), inferred tripled available when attempts read model.

for example, if asked if infmodelrule.contains(...) triple know inferred , see in output, you'll true result. model doesn't need separate step 'write' result.

if write model disk instead of standard out (psudocode):

try( final fileoutputstream out = new fileoutputstream(new file("blah.rdf")) ){ infmodelrule.write(out); }

... you'll see triples inferred there well. if later read file model without reasoner attached, triples remain.

java jena rules ontology protege

No comments:

Post a Comment