Search in sources :

Example 1 with Builtin

use of com.hp.hpl.jena.reasoner.rulesys.Builtin in project stanbol by apache.

the class GreaterThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    Node arg1Node = null;
    Node arg2Node = null;
    org.apache.stanbol.rules.manager.atoms.GreaterThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.GreaterThanAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getArgument1();
    ExpressionAtom argument2 = tmp.getArgument2();
    ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
    ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
    List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
    if (clauseEntry1 instanceof HigherOrderClauseEntry) {
        arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
        clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
    } else if (clauseEntry1 instanceof NodeClauseEntry) {
        arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (clauseEntry2 instanceof HigherOrderClauseEntry) {
        arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
        clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
    } else if (clauseEntry2 instanceof NodeClauseEntry) {
        arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    java.util.List<Node> nodes = new ArrayList<Node>();
    nodes.add(arg1Node);
    nodes.add(arg2Node);
    Builtin f = BuiltinRegistry.theRegistry.getImplementation("greaterThan");
    System.out.println("Class: " + f.getClass().getCanonicalName());
    System.out.println("Arg1: " + arg1Node.getClass().getCanonicalName());
    System.out.println("Arg2: " + arg2Node.getClass().getCanonicalName());
    Functor functor = new Functor("greaterThan", nodes, BuiltinRegistry.theRegistry);
    clauseEntries.add(functor);
    return (T) new HigherOrderClauseEntry(arg1Node, clauseEntries);
}
Also used : Node(com.hp.hpl.jena.graph.Node) ArrayList(java.util.ArrayList) Functor(com.hp.hpl.jena.reasoner.rulesys.Functor) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) HigherOrderClauseEntry(org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry) ClauseEntry(com.hp.hpl.jena.reasoner.rulesys.ClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) HigherOrderClauseEntry(org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) Builtin(com.hp.hpl.jena.reasoner.rulesys.Builtin)

Aggregations

Node (com.hp.hpl.jena.graph.Node)1 Builtin (com.hp.hpl.jena.reasoner.rulesys.Builtin)1 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)1 Functor (com.hp.hpl.jena.reasoner.rulesys.Functor)1 ArrayList (java.util.ArrayList)1 HigherOrderClauseEntry (org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry)1 NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)1 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)1 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)1