Fixed!
I now create my dataset as follows in an assembler:
if ( !exactlyOneProperty(root, pLocation) )
throw new AssemblerException(root, "No location given");
String dir = getStringValue(root, pLocation);
Location loc = Location.create(dir);
DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(loc);
if ( root.hasProperty(pUnionDefaultGraph) ) {
Node b = root.getProperty(pUnionDefaultGraph).getObject().asNode();
NodeValue nv = NodeValue.makeNode(b);
if ( nv.isBoolean() )
dsg.getContext().set(TDB2.symUnionDefaultGraph, nv.getBoolean());
else
Log.warn(DatasetAssemblerTDB.class, "Failed to recognize value
for union graph setting (ignored): " + b);
}
RulesReloadingDataset rulesReloadingDataset
= new RulesReloadingDataset(ModelFactory.createInfModel(new
GenericRuleReasoner(new ArrayList<Rule>()),
ModelFactory.createModelForGraph(dsg.getDefaultGraph())));
return rulesReloadingDataset;
Thank your for your hints!
Johan,
Op za 31 okt. 2020 om 11:03 schreef Johan Kumps <[email protected]>:
> Hi,
>
> I managed to create a custom dataset and get it registered. It seems to
> work fine but apparently it is an in memory dataset. Rules get reloaded
> when I change the rule set.
> How should I make sure it is a tdb2 persistent one?
>
> Johan
>
> Op vr 30 okt. 2020 om 23:08 schreef Johan Kumps <[email protected]>:
>
>> Barry,
>>
>> Would you mind to share your CustomDatasetAssembler and Fuseki turtle
>> config file?
>> I'm struggling to find out how to make Jena aware of my custom dataset
>> implementation.
>>
>> Thank you very much!
>>
>> Johan,
>>
>> Op vr 30 okt. 2020 om 20:10 schreef Johan Kumps <[email protected]>:
>>
>>> Barry,
>>>
>>> Thanks for the pointer. I'll try that out!
>>>
>>> You're right we already attended the same Interconnect call's :). I
>>> emailed you about SparQL+ :)
>>>
>>> Johan,
>>>
>>> Op vr 30 okt. 2020 om 18:35 schreef Nouwt, B. (Barry)
>>> <[email protected]>:
>>>
>>>> Hi Johan, I can give some implementation pointers.
>>>>
>>>> We implemented our own dataset:
>>>>
>>>> public class CustomDataset extends DatasetImpl { ... }
>>>>
>>>> And in this dataset we periodically update the rules like this:
>>>>
>>>> public void updateRules(List<Rule> rules)
>>>> {
>>>> Model m = this.getDefaultModel();
>>>> InfGraph ig = (InfGraph) m.getGraph();
>>>> Graph rawGraph = ig.getRawGraph();
>>>> Reasoner r = ig.getReasoner();
>>>> if (r instanceof GenericRuleReasoner) {
>>>> GenericRuleReasoner gr = (GenericRuleReasoner) r;
>>>> List<Rule> oldRules = gr.getRules();
>>>> LOG.trace("Old rules: {}", oldRules);
>>>> if (!oldRules.equals(rules)) {
>>>> LOG.trace("New rules: {}", rules);
>>>> gr.setRules(rules);
>>>> InfModel inf = ModelFactory.createInfModel(gr,
>>>> ModelFactory.createModelForGraph(rawGraph));
>>>> this.setDefaultModel(inf);
>>>> }
>>>> }
>>>>
>>>> Then we use a CustomDatasetAssembler (i.e.
>>>> https://jena.apache.org/documentation/assembler/inside-assemblers.html)
>>>> to configure our dataset using a Fuseki Turtle configuration file:
>>>>
>>>> ...
>>>>
>>>> ex:CustomDataset ja:assembler "org.test.CustomDatasetAssembler" .
>>>>
>>>> ex:dataset rdf:type ex:CustomDataset ;
>>>> ja:defaultGraph ke:infGraph .
>>>>
>>>> ...
>>>>
>>>> This is probably not the ideal way, but it works good enough for our
>>>> non-production environment.
>>>>
>>>> By the way, I think I recognize your name from the InterConnect project.
>>>>
>>>> Kind regards, Barry
>>>>
>>>> -----Original Message-----
>>>> From: Johan Kumps <[email protected]>
>>>> Sent: zondag 25 oktober 2020 11:47
>>>> To: [email protected]
>>>> Subject: Re: Add rules at runtime
>>>>
>>>> Hi Barry,
>>>>
>>>> Could you share your code please?
>>>>
>>>> Thanks!
>>>>
>>>> Op di 13 okt. 2020 om 08:30 schreef Nouwt, B. (Barry)
>>>> <[email protected]>:
>>>>
>>>> > Hi Johan, you can definitely reload the rules in Apache Jena Fuseki,
>>>> > but it requires programming. I did it by creating a custom Dataset
>>>> > implementation (which I configured using an Assembler configuration
>>>> > file) that periodically reloads the rules, but that might not be the
>>>> easiest way.
>>>> > Regards, Barry
>>>> >
>>>> > -----Original Message-----
>>>> > From: Johan Kumps <[email protected]>
>>>> > Sent: maandag 12 oktober 2020 22:16
>>>> > To: [email protected]
>>>> > Subject: Re: Add rules at runtime
>>>> >
>>>> > Hi,
>>>> >
>>>> > I understand that within Jena rules and data are stored separately
>>>> but
>>>> > the question is whether there is a possibility to reload rules in the
>>>> > given file. If so it would be possible to reload the rule set without
>>>> > having to restart the server.
>>>> > Any ideas?
>>>> >
>>>> > Johan,
>>>> >
>>>> > Op ma 5 okt. 2020 om 14:12 schreef Nouwt, B. (Barry)
>>>> > <[email protected]>:
>>>> >
>>>> > > Hi Johan,
>>>> > >
>>>> > > I do not think Apache Jena Fuseki supports uploading a rule file as
>>>> > > you would do with data. Apache Jena rules (
>>>> > > https://jena.apache.org/documentation/inference/) can only be set
>>>> as
>>>> > > part of the configuration of a dataset, I think.
>>>> > >
>>>> > > However, if you use another type of constraints/rules (i.e. SWRL or
>>>> > > OWL Restrictions), you can maybe upload those as part of your data
>>>> > > (as they are part of you ontology, I think). If you then use a
>>>> > > reasoner that supports those constraints/rules (Pellet maybe?), it
>>>> > > will probably take them into account.
>>>> > >
>>>> > > Hope this helps!
>>>> > >
>>>> > > Regards, Barry
>>>> > >
>>>> > > -----Original Message-----
>>>> > > From: Johan Kumps <[email protected]>
>>>> > > Sent: maandag 5 oktober 2020 13:37
>>>> > > To: [email protected]
>>>> > > Subject: Add rules at runtime
>>>> > >
>>>> > > Hi all,
>>>> > >
>>>> > > Is it possible to add rules to Jena at runtime or is it only
>>>> > > possible to add rules via a file and restart the server?
>>>> > >
>>>> > > It would be very nice if you could upload a rule the same way as
>>>> you
>>>> > > can do to add data to a dataset.
>>>> > >
>>>> > > Kind regards,
>>>> > > Johan,
>>>> > > This message may contain information that is not intended for you.
>>>> > > If you are not the addressee or if this message was sent to you by
>>>> > > mistake, you are requested to inform the sender and delete the
>>>> > > message. TNO accepts no liability for the content of this e-mail,
>>>> > > for the manner in which you use it and for damage of any kind
>>>> > > resulting from the risks inherent to the electronic transmission of
>>>> messages.
>>>> > >
>>>> >
>>>>
>>>