Search in sources :

Example 6 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class GreaterEqualThanAtom 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.GreaterEqualThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.GreaterEqualThanAtom) 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());
    }
    List<Node> nodes = new ArrayList<Node>();
    nodes.add(arg1Node);
    nodes.add(arg2Node);
    Functor functor = new Functor("ge", 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 7 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class IndividualPropertyAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom argument2 = tmp.getArgument2();
    IObjectAtom objectProperty = tmp.getObjectProperty();
    System.out.println(argument1);
    ClauseEntry argument2ClauseEntry = adapter.adaptTo(argument2, Rule.class);
    ClauseEntry argument1ClauseEntry = adapter.adaptTo(argument1, Rule.class);
    ClauseEntry objectPropertyClauseEntry = adapter.adaptTo(objectProperty, Rule.class);
    Node subjectNode;
    Node predicateNode;
    Node objectNode;
    System.out.println(argument1ClauseEntry.getClass());
    if (argument1ClauseEntry instanceof NodeClauseEntry) {
        subjectNode = ((NodeClauseEntry) argument1ClauseEntry).getNode();
    } else if (argument1ClauseEntry instanceof VariableClauseEntry) {
        subjectNode = ((VariableClauseEntry) argument1ClauseEntry).getNode();
        System.out.println("Here");
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (objectPropertyClauseEntry instanceof NodeClauseEntry) {
        predicateNode = ((NodeClauseEntry) objectPropertyClauseEntry).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (argument2ClauseEntry instanceof NodeClauseEntry) {
        objectNode = ((NodeClauseEntry) argument2ClauseEntry).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) new TriplePattern(subjectNode, predicateNode, objectNode);
}
Also used : Node(com.hp.hpl.jena.graph.Node) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) VariableClauseEntry(org.apache.stanbol.rules.adapters.jena.VariableClauseEntry) ClauseEntry(com.hp.hpl.jena.reasoner.rulesys.ClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) TriplePattern(com.hp.hpl.jena.reasoner.TriplePattern) VariableClauseEntry(org.apache.stanbol.rules.adapters.jena.VariableClauseEntry)

Example 8 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class LessEqualThanAtom 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.LessEqualThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom) 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("le", 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 9 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class StrAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.StrAtom tmp = (org.apache.stanbol.rules.manager.atoms.StrAtom) ruleAtom;
    IObjectAtom iObjectAtom = tmp.getUriResource();
    ClauseEntry iObjectClauseEntry = adapter.adaptTo(iObjectAtom, Rule.class);
    if (iObjectClauseEntry instanceof NodeClauseEntry) {
        Node node = ((NodeClauseEntry) iObjectClauseEntry).getNode();
        Node emptyString = Node_RuleVariable.createLiteral("");
        Node bindind = Node_RuleVariable.createVariable("str_reuslt" + System.currentTimeMillis());
        List<Node> args = new ArrayList<Node>();
        args.add(node);
        args.add(emptyString);
        args.add(bindind);
        Functor functor = new Functor("strConcat", args);
        List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
        clauseEntries.add(functor);
        return (T) new HigherOrderClauseEntry(node, clauseEntries);
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
}
Also used : Node(com.hp.hpl.jena.graph.Node) ArrayList(java.util.ArrayList) Functor(com.hp.hpl.jena.reasoner.rulesys.Functor) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) 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) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Example 10 with Node

use of com.hp.hpl.jena.graph.Node in project stanbol by apache.

the class StringAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.StringAtom tmp = (org.apache.stanbol.rules.manager.atoms.StringAtom) ruleAtom;
    String string = tmp.getString();
    Node node = null;
    if (string.startsWith(Symbols.variablesPrefix)) {
        string = string.replace(Symbols.variablesPrefix, "");
        if (string.startsWith("?")) {
            string = string.substring(1);
        }
        node = Node_RuleVariable.createVariable(string);
    } else {
        node = NodeFactory.getTypedLiteral(string);
    }
    return (T) new NodeClauseEntry(node);
}
Also used : Node(com.hp.hpl.jena.graph.Node) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Aggregations

Node (com.hp.hpl.jena.graph.Node)31 NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)23 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)20 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)20 ArrayList (java.util.ArrayList)18 Functor (com.hp.hpl.jena.reasoner.rulesys.Functor)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 Triple (com.hp.hpl.jena.graph.Triple)3 RDFNode (com.hp.hpl.jena.rdf.model.RDFNode)3 BuiltinRegistry (com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry)3 LiteralLabel (com.hp.hpl.jena.graph.impl.LiteralLabel)2 AnonId (com.hp.hpl.jena.rdf.model.AnonId)2 URIResource (org.apache.stanbol.rules.base.api.URIResource)2 DatatypeFormatException (com.hp.hpl.jena.datatypes.DatatypeFormatException)1 Builtin (com.hp.hpl.jena.reasoner.rulesys.Builtin)1 Binding (com.hp.hpl.jena.sparql.engine.binding.Binding)1