I'm trying to keep a big model with reference data and in memory and attach other models with inference rules, and I need matching rules to fire when new triples are coming, lookup the reference data and all the new triples to end up in the second model.
Like this:
#Reference data:
:alice
foaf:name "Alice" ;
schema:identifier "1" ;
.
#New incoming triples:
:claire
foaf:name "Claire" ;
schema:identifier "3" ;
:friend_id "1" ;
.
When Claire arrives a rule should fire, find Alice in reference data by id and generate additional triple like
:alice foaf:knows :claire
which should end up together with Claire's records in the model being filled, not the same one where Alice resides.
My latest attempt at this:
private void createUnionModel() {
Model referred = RDFDataMgr.loadModel("referred.ttl");
Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL("align.sse"));
Model aligned = ModelFactory.createDefaultModel();
Model union = ModelFactory.createUnion(aligned, referred);
InfModel infModel = ModelFactory.createInfModel(reasoner, union);
RDFDataMgr.read(infModel, "new_triples.ttl");
printModel(referred, "referred");
printModel(aligned, "aligned");
printModel(union, "union");
printModel(infModel, "inference");
}
shows that triples generated by inference rules don't go into the aligned
model:
'alignment rules loaded'
'alignment rules loaded'
----------------- referred
:alice a foaf:Person ;
schema:identifier "1" ;
foaf:name "Alice" .
:bob a foaf:Person ;
schema:identifier "2" ;
foaf:name "Bob" .
----------------- aligned
<http://example.org/claire>
a <http://xmlns.com/foaf/0.1/Person> ;
<http://example.org/friend_id> "1" ;
<http://schema.org/identifier> "3" ;
<http://xmlns.com/foaf/0.1/name>
"Claire" .
----------------- union
:claire a foaf:Person ;
:friend_id "1" ;
schema:identifier "3" ;
foaf:name "Claire" .
:alice a foaf:Person ;
schema:identifier "1" ;
foaf:name "Alice" .
:bob a foaf:Person ;
schema:identifier "2" ;
foaf:name "Bob" .
----------------- inference
'alignment rules loaded'
'rule matched: ' <http://example.org/claire> ' knows ' <http://example.org/alice>
:claire a foaf:Person ;
schema:identifier "3" ;
foaf:knows :alice ;
foaf:name "Claire" .
:alice a foaf:Person ;
schema:identifier "1" ;
foaf:name "Alice" .
:bob a foaf:Person ;
schema:identifier "2" ;
foaf:name "Bob" .
I tried to compose the model differently, i.e. first constructing the inference model and then combining it with reference, didn't help.
How can I save triples generated by inference rules in a model separately from lookup data?
Is there a way to define this in ttl
files instead of Java code?