Search in sources :

Example 16 with Node

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

the class PropertyPrefixFilterTest method testMappings.

@Test
public void testMappings() {
    Node subject = Node.createURI("urn:subject");
    Node value = Node.createURI("urn:value");
    Node rdfType = Node.createURI(NamespaceEnum.rdf + "type");
    Assert.assertTrue(importFilter.accept(subject, rdfType, value));
    Node rdfsLabel = Node.createURI(NamespaceEnum.rdfs + "label");
    Assert.assertTrue(importFilter.accept(subject, rdfsLabel, value));
    Node guid = Node.createURI(FB + "type.object.guid");
    Assert.assertFalse(importFilter.accept(subject, guid, value));
    Node permission = Node.createURI(FB + "type.object.permission");
    Assert.assertFalse(importFilter.accept(subject, permission, value));
    Node name = Node.createURI(FB + "type.object.name");
    Assert.assertTrue(importFilter.accept(subject, name, value));
    Node description = Node.createURI(FB + "type.object.description");
    Assert.assertTrue(importFilter.accept(subject, description, value));
    Node dummy = Node.createURI(FB + "type.dummy");
    Assert.assertFalse(importFilter.accept(subject, dummy, value));
    Node typePlain = Node.createURI(FB + "type");
    Assert.assertFalse(importFilter.accept(subject, typePlain, value));
    Node other = Node.createURI(NamespaceEnum.cc + "license");
    Assert.assertFalse(importFilter.accept(subject, other, value));
}
Also used : Node(com.hp.hpl.jena.graph.Node) Test(org.junit.Test)

Example 17 with Node

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

the class CreateURI method execEvaluated.

@Override
public QueryIterator execEvaluated(Binding binding, PropFuncArg argumentSubject, Node predicate, PropFuncArg argumentObject, ExecutionContext execCxt) {
    Binding b = null;
    if (argumentObject.getArg().isLiteral()) {
        Node ref = argumentSubject.getArg();
        if (ref.isVariable()) {
            String argumentString = argumentObject.getArg().toString().replace("\"", "");
            //STANBOL-621: Binding1 has no longer a public constructor
            //b = new Binding1(binding, Var.alloc(ref), NodeFactory.createURI(argumentString));
            b = BindingFactory.binding(binding, Var.alloc(ref), NodeFactory.createURI(argumentString));
        }
    }
    if (b == null) {
        b = binding;
    }
    return IterLib.result(b, execCxt);
}
Also used : Binding(com.hp.hpl.jena.sparql.engine.binding.Binding) Node(com.hp.hpl.jena.graph.Node)

Example 18 with Node

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

the class AbstractRuleAtom method getTypedLiteral.

protected 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) {
        literal = Node_RuleVariable.createLiteral((String) argument, null, XSDDatatype.XSDstring);
    } else if (argument instanceof Integer) {
        literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDinteger);
    } else if (argument instanceof Double) {
        literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDdouble);
    } else if (argument instanceof Float) {
        literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDfloat);
    } else if (argument instanceof Boolean) {
        literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDboolean);
    } else {
        literal = Node_RuleVariable.createLiteral((String) argument);
    }
    return literal;
}
Also used : URIResource(org.apache.stanbol.rules.base.api.URIResource) Node(com.hp.hpl.jena.graph.Node)

Example 19 with Node

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

the class MultiplicationAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String div_result = "mul_result" + System.currentTimeMillis();
    Node arg1Node = null;
    Node arg2Node = null;
    Node arg3Node = Node_RuleVariable.createVariable(div_result);
    org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) 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("product", 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)

Example 20 with Node

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

the class LetAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LetAtom tmp = (org.apache.stanbol.rules.manager.atoms.LetAtom) ruleAtom;
    StringFunctionAtom parameterFunctionAtom = tmp.getParameterFunctionAtom();
    IObjectAtom variableIObjectAtom = tmp.getVariable();
    ClauseEntry parameterClauseEntry = adapter.adaptTo(parameterFunctionAtom, Rule.class);
    ClauseEntry variableClauseEntry = adapter.adaptTo(variableIObjectAtom, Rule.class);
    List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
    Node parameterNode;
    Node variableNode;
    if (parameterClauseEntry instanceof HigherOrderClauseEntry) {
        parameterNode = ((HigherOrderClauseEntry) parameterClauseEntry).getBindableNode();
        clauseEntries.addAll(((HigherOrderClauseEntry) parameterClauseEntry).getClauseEntries());
    } else if (parameterClauseEntry instanceof NodeClauseEntry) {
        parameterNode = ((NodeClauseEntry) parameterClauseEntry).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (variableClauseEntry instanceof NodeClauseEntry) {
        variableNode = ((NodeClauseEntry) variableClauseEntry).getNode();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    java.util.List<Node> nodes = new ArrayList<Node>();
    nodes.add(variableNode);
    nodes.add(parameterNode);
    ClauseEntry clauseEntry = new Functor("makeSkolem", nodes, BuiltinRegistry.theRegistry);
    clauseEntries.add(clauseEntry);
    return (T) new HigherOrderClauseEntry(variableNode, clauseEntries);
}
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) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) 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)

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