I have created a function that perform some calculations between nodes. I would like to call this function from Jena rule? Is this possible? I found that built-in function can be called from jena rule, but I would like to call my own function. How can I write a builtin function?
Asked
Active
Viewed 376 times
0
-
There have been some recent questions about implementing built ins for rules. They probably answer your question. – Joshua Taylor Aug 19 '14 at 20:45
-
possible duplicate of [writing Jena built-ins](http://stackoverflow.com/questions/12139978/writing-jena-built-ins) – Joshua Taylor Aug 19 '14 at 20:46
-
1Oh, the duplicate I linked to is not a very good duplicate. [How can I create customized builtins in Jena?](http://stackoverflow.com/q/23255124/1281433) is much better. [Once I've written a builtin, what do I need to do to make the reasoners aware of it?](http://stackoverflow.com/q/23268298/1281433) is also very helpful. – Joshua Taylor Aug 19 '14 at 20:52
-
1I'm not sure what you're asking; once you implement a rule and register it, it's can be called in a rule. I think that the linked questions cover that. If you've already implemented a built in, and are having trouble calling it, please show your code and describe the specific problem. – Joshua Taylor Aug 19 '14 at 21:52
-
1If you thought it was impossible, it's not immediately clear why you'd ask "Is this possible?" At any rate: it's described in the documentation (see the links in the linked questions); a good IDE will make it easy to implement a builtin; and Jena is open source, so it's easy to see the implementations of the standard builtins. – Joshua Taylor Aug 20 '14 at 03:52
-
1Builtins don't return values like that. Look at the [builtin primitives](http://jena.apache.org/documentation/inference/#RULEbuiltins) that come with Jena. The rule would be more like `(?x ?hasBase ?b) (?x hasExponent ?e) pow(?b,?e,?z) -> (?x hasValue ?z)`. A mathematical builtin like `product(?a,?b,?c)` needs to compute the value of `?a * ?b` and to bind it to `?c`. – Joshua Taylor Aug 26 '14 at 12:56
-
1That tutorial is more than just Jena. I don't know what SADL is. Unless you need SADL, I'd suggest you look through the other links here. – Joshua Taylor Aug 26 '14 at 22:49
-
1I can't help you with the SADL stuff, but that page did mention that the builtin would end up having three arguments, not just two. Before trying any frameworks, you'll probably benefit from implementing one without it. The other questions explain how to do that. Particularly pay attention to the part about registering the builtin so that the rule engine can find it. – Joshua Taylor Aug 27 '14 at 00:44
-
Implementing, registering, and then using a new Jena `Builtin` is a fairly straight forward process. The links that @JoshuaTaylor has provided are a critical first step to understanding what you are doing. Once that is complete, steps 3-5 on the [link you provided](http://sadl.sourceforge.net/CustomJenaBuiltins.html) are extremely SADL-community-specific. These steps appear to be the ones that are important for registering your builtin with SADL. Using that bulitin should be no different than using all the other builtins (however SADL exposes those to you). Needs a (non-existant) `SADL` tag. – Rob Hall Aug 27 '14 at 12:59
-
Read my answer to [Once I've written a builtin, what do I need to do to make the reasoners aware of it?](http://stackoverflow.com/a/23270901/2528639). That answer contains a complete example for "implementing, registering, and then using a new Jena Builtin". – Rob Hall Aug 29 '14 at 14:33