Search in sources :

Example 11 with NodeClauseEntry

use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.

the class LessThanAtom 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.LessThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessThanAtom) 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);
    Functor functor = new Functor("lessThan", 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)

Example 12 with NodeClauseEntry

use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.

the class NumberAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.NumberAtom tmp = (org.apache.stanbol.rules.manager.atoms.NumberAtom) ruleAtom;
    String number = tmp.getNumber();
    Node node = null;
    System.out.println("Number atom " + number);
    if (number.startsWith("?")) {
        number = number.substring(1);
        node = Node_RuleVariable.createVariable(number);
    } else {
        Number n = null;
        if (number.contains("\\.")) {
            int indexOfPoint = number.indexOf('.');
            if (indexOfPoint == number.length() - 2) {
                n = Float.parseFloat(number);
            } else {
                n = Double.parseDouble(number);
            }
        } else {
            n = Integer.parseInt(number);
        }
        node = NodeFactory.getTypedLiteral(n);
    }
    return (T) new NodeClauseEntry(node);
}
Also used : Node(com.hp.hpl.jena.graph.Node) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Example 13 with NodeClauseEntry

use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.

the class ResourceAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.ResourceAtom tmp = (org.apache.stanbol.rules.manager.atoms.ResourceAtom) ruleAtom;
    String unquotedURI = tmp.toUnquotedString();
    Node node = Node_RuleVariable.createURI(unquotedURI);
    return (T) new NodeClauseEntry(node);
}
Also used : Node(com.hp.hpl.jena.graph.Node) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Example 14 with NodeClauseEntry

use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.

the class NumericVariableAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.NumericVariableAtom tmp = (org.apache.stanbol.rules.manager.atoms.NumericVariableAtom) ruleAtom;
    URI uri = tmp.getURI();
    String variable = uri.toString();
    variable = variable.replace(Symbols.variablesPrefix, "");
    if (variable.startsWith("?")) {
        variable = variable.substring(1);
    }
    Integer index = ((JenaAdapter) adapter).variableMap.get(variable);
    if (index == null) {
        index = ((JenaAdapter) adapter).variableMap.size();
        ((JenaAdapter) adapter).variableMap.put(variable, index);
    }
    Node_RuleVariable ruleVariable = new Node_RuleVariable("?" + variable, index.intValue());
    return (T) new NodeClauseEntry(ruleVariable);
}
Also used : Node_RuleVariable(com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable) URI(java.net.URI) JenaAdapter(org.apache.stanbol.rules.adapters.jena.JenaAdapter) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Example 15 with NodeClauseEntry

use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.

the class VariableAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.VariableAtom tmp = (org.apache.stanbol.rules.manager.atoms.VariableAtom) ruleAtom;
    URI uri = tmp.getURI();
    String variable = uri.toString();
    variable = variable.replace(Symbols.variablesPrefix, "");
    if (variable.startsWith("?")) {
        variable = variable.substring(1);
    }
    Integer index = ((JenaAdapter) adapter).variableMap.get(variable);
    if (index == null) {
        index = ((JenaAdapter) adapter).variableMap.size();
        ((JenaAdapter) adapter).variableMap.put(variable, index);
    }
    Node_RuleVariable ruleVariable = new Node_RuleVariable("?" + variable, index.intValue());
    return (T) new NodeClauseEntry(ruleVariable);
}
Also used : Node_RuleVariable(com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable) URI(java.net.URI) JenaAdapter(org.apache.stanbol.rules.adapters.jena.JenaAdapter) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Aggregations

NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)26 Node (com.hp.hpl.jena.graph.Node)23 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)20 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)20 Functor (com.hp.hpl.jena.reasoner.rulesys.Functor)16 ArrayList (java.util.ArrayList)16 HigherOrderClauseEntry (org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry)15 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)9 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)7 TriplePattern (com.hp.hpl.jena.reasoner.TriplePattern)4 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)4 BuiltinRegistry (com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry)3 Node_RuleVariable (com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable)3 URI (java.net.URI)3 JenaAdapter (org.apache.stanbol.rules.adapters.jena.JenaAdapter)3 LiteralLabel (com.hp.hpl.jena.graph.impl.LiteralLabel)2 Builtin (com.hp.hpl.jena.reasoner.rulesys.Builtin)1 VariableClauseEntry (org.apache.stanbol.rules.adapters.jena.VariableClauseEntry)1 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)1 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)1