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.
> >
>