Dear Jess users,
I am having trouble instantiating a Java class from within a rule's RHS, and 
cannot figure out how to solve this problem.

The code in my RHS creates an instance of a class from the JGraphT library. As 
seen in  
https://github.com/jgrapht/jgrapht/blob/master/jgrapht-demo/src/main/java/org/jgrapht/demo/HelloJGraphT.java
 (lines 91-92), the creation of a DefaultDirectedGraph instance require another 
class as argument; here, DefaultEdge.

I couldn't find an example in the Jess documentation about how to do that. For 
example, I tried the following:

        (bind ?edge-class org.jgrapht.graph.DefaultEdge)
        (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph ?edge-class))

I also tried variations such as

        (bind ?edge-class org.jgrapht.graph.DefaultEdge)
        (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph (?edge-class 
getClass))

or

        (bind ?edge-class (new org.jgrapht.graph.DefaultEdge))
        (bind ?graph (new org.jgrapht.graph.DefaultDirectedGraph ?edge-class))

Any idea about what the syntax should be to properly instantiate the 
DefaultDirectedGraph class? For information (but not certain how relevant it is 
here), I succeeded in the past in using java.util.regex.Pattern and its static 
method 'compile' by typing

        (bind ?pattern-class java.util.regex.Pattern)
        (bind ?matches ((?pattern-class compile "...") matcher ?string))

Best,
Aurélien

Reply via email to