Search in sources :

Example 1 with Node

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

the class BlankNodeAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.BlankNodeAtom tmp = (org.apache.stanbol.rules.manager.atoms.BlankNodeAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom argument2 = tmp.getArgument2();
    ClauseEntry argument1CE = adapter.adaptTo(argument1, Rule.class);
    ClauseEntry argument2CE = adapter.adaptTo(argument2, Rule.class);
    Node arg1Node;
    Node arg2Node;
    if (argument1CE instanceof NodeClauseEntry) {
        arg1Node = ((NodeClauseEntry) argument1CE).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (argument2CE instanceof NodeClauseEntry) {
        arg2Node = ((NodeClauseEntry) argument2CE).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    Node blank = Node_RuleVariable.createAnon();
    return (T) new TriplePattern(arg2Node, arg1Node, blank);
}
Also used : Node(com.hp.hpl.jena.graph.Node) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) 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)

Example 2 with Node

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

the class NodeFactory method getTypedLiteral.

/**
     * The argument is converted to a Jena {@link Node}
     * 
     * @param argument
     *            any Object
     * @return the {@link Node}
     */
public static Node getTypedLiteral(Object argument) {
    Node literal;
    if (argument instanceof TypedLiteralAtom) {
        TypedLiteralAtom typedLiteralAtom = (TypedLiteralAtom) argument;
        URIResource xsdType = typedLiteralAtom.getXsdType();
        if (xsdType.getURI().equals(XSD.xboolean)) {
            literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDboolean);
        } else if (xsdType.getURI().equals(XSD.xdouble)) {
            literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDdouble);
        } else if (xsdType.getURI().equals(XSD.xfloat)) {
            literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDfloat);
        } else if (xsdType.getURI().equals(XSD.xint)) {
            literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDint);
        } else {
            literal = Node_RuleVariable.createLiteral(argument.toString());
        }
    } else if (argument instanceof String) {
        System.out.println(argument);
        String argString = (String) argument;
        if (argString.startsWith("\"") && argString.endsWith("\"")) {
            argString = argString.substring(1, argString.length() - 1);
        }
        literal = Node_RuleVariable.createLiteral(argString);
    } else if (argument instanceof Integer) {
        literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDint);
    } else {
        literal = Node_RuleVariable.createLiteral(argument.toString());
    }
    return literal;
}
Also used : URIResource(org.apache.stanbol.rules.base.api.URIResource) Node(com.hp.hpl.jena.graph.Node) TypedLiteralAtom(org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom)

Example 3 with Node

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

the class ClassAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom classResource = tmp.getClassResource();
    ClauseEntry argumentClauseEntry = adapter.adaptTo(argument1, Rule.class);
    ClauseEntry classClauseEntry = adapter.adaptTo(classResource, Rule.class);
    Node argumnetNode;
    Node classNode;
    if (argumentClauseEntry instanceof NodeClauseEntry) {
        argumnetNode = ((NodeClauseEntry) argumentClauseEntry).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (classClauseEntry instanceof NodeClauseEntry) {
        classNode = ((NodeClauseEntry) classClauseEntry).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) new TriplePattern(argumnetNode, Node_RuleVariable.createURI(RDF.type.getURI()), classNode);
}
Also used : Node(com.hp.hpl.jena.graph.Node) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) 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)

Example 4 with Node

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

the class DatavaluedPropertyAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom datatypeProperty = tmp.getDatatypeProperty();
    RuleAtom argument2 = tmp.getArgument2();
    ClauseEntry argument2ClauseEntry = adapter.adaptTo(argument2, Rule.class);
    ClauseEntry argument1ClauseEntry = adapter.adaptTo(argument1, Rule.class);
    ClauseEntry datatypePropertyClauseEntry = adapter.adaptTo(datatypeProperty, Rule.class);
    Node subjectNode = null;
    Node predicateNode = null;
    Node objectNode = null;
    if (argument1ClauseEntry instanceof NodeClauseEntry) {
        subjectNode = ((NodeClauseEntry) argument1ClauseEntry).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (datatypePropertyClauseEntry instanceof NodeClauseEntry) {
        predicateNode = ((NodeClauseEntry) datatypePropertyClauseEntry).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) 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) RuleAtom(org.apache.stanbol.rules.base.api.RuleAtom)

Example 5 with Node

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

the class DivisionAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String div_result = "div_result" + System.currentTimeMillis();
    Node arg1Node = null;
    Node arg2Node = null;
    Node arg3Node = Node_RuleVariable.createVariable(div_result);
    org.apache.stanbol.rules.manager.atoms.DivisionAtom tmp = (org.apache.stanbol.rules.manager.atoms.DivisionAtom) ruleAtom;
    NumericFunctionAtom numericFunctionAtom1 = tmp.getNumericFunctionAtom1();
    NumericFunctionAtom numericFunctionAtom2 = tmp.getNumericFunctionAtom2();
    ClauseEntry clauseEntry1 = adapter.adaptTo(numericFunctionAtom1, Rule.class);
    ClauseEntry clauseEntry2 = adapter.adaptTo(numericFunctionAtom2, 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);
    nodes.add(arg3Node);
    ClauseEntry clauseEntry = new Functor("quotient", nodes, BuiltinRegistry.theRegistry);
    clauseEntries.add(clauseEntry);
    return (T) new HigherOrderClauseEntry(arg3Node, clauseEntries);
}
Also used : Node(com.hp.hpl.jena.graph.Node) ArrayList(java.util.ArrayList) Functor(com.hp.hpl.jena.reasoner.rulesys.Functor) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) 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)

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