Search in sources :

Example 1 with URIResource

use of org.apache.stanbol.rules.base.api.URIResource 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 2 with URIResource

use of org.apache.stanbol.rules.base.api.URIResource 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();
    URIResource variableUriResource = tmp.getVariable();
    ClerezzaSparqlObject iriArgument;
    iriArgument = (ClerezzaSparqlObject) adapter.adaptTo(parameterFunctionAtom, ConstructQuery.class);
    List<Expression> iriArgumentExpressions = new ArrayList<Expression>();
    iriArgumentExpressions.add((Expression) iriArgument.getClerezzaObject());
    BuiltInCall iriBuiltInCall = new BuiltInCall("IRI", iriArgumentExpressions);
    if (variableUriResource instanceof VariableAtom) {
        String variableName = ((VariableAtom) variableUriResource).getVariableName();
        Variable variable = new Variable(variableName);
        List<Expression> bindArgumentExpressions = new ArrayList<Expression>();
        bindArgumentExpressions.add(iriBuiltInCall);
        bindArgumentExpressions.add(variable);
        BuiltInCall bindBuiltInCall = new BuiltInCall("BIND", iriArgumentExpressions);
        return (T) new ClerezzaSparqlObject(bindBuiltInCall);
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
}
Also used : Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) VariableAtom(org.apache.stanbol.rules.manager.atoms.VariableAtom) URIResource(org.apache.stanbol.rules.base.api.URIResource) ArrayList(java.util.ArrayList) BuiltInCall(org.apache.clerezza.rdf.core.sparql.query.BuiltInCall) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption)

Example 3 with URIResource

use of org.apache.stanbol.rules.base.api.URIResource 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 4 with URIResource

use of org.apache.stanbol.rules.base.api.URIResource in project stanbol by apache.

the class SWRLLiteralBuilder method getSWRLLiteral.

public static SWRLLiteralArgument getSWRLLiteral(Object argument) {
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    OWLLiteral owlLiteral;
    if (argument instanceof TypedLiteralAtom) {
        TypedLiteralAtom typedLiteralAtom = (TypedLiteralAtom) argument;
        URIResource xsdType = typedLiteralAtom.getXsdType();
        if (xsdType.getURI().equals(XSD.xboolean)) {
            owlLiteral = factory.getOWLLiteral(Boolean.valueOf(argument.toString()).booleanValue());
        } else if (xsdType.getURI().equals(XSD.xdouble)) {
            owlLiteral = factory.getOWLLiteral(Double.valueOf(argument.toString()).doubleValue());
        } else if (xsdType.getURI().equals(XSD.xfloat)) {
            owlLiteral = factory.getOWLLiteral(Float.valueOf(argument.toString()).floatValue());
        } else if (xsdType.getURI().equals(XSD.xint)) {
            owlLiteral = factory.getOWLLiteral(Integer.valueOf(argument.toString()).intValue());
        } else {
            owlLiteral = factory.getOWLLiteral(argument.toString());
        }
    } else if (argument instanceof String) {
        owlLiteral = factory.getOWLLiteral((String) argument);
    } else if (argument instanceof Integer) {
        owlLiteral = factory.getOWLLiteral(((Integer) argument).intValue());
    } else if (argument instanceof Double) {
        owlLiteral = factory.getOWLLiteral(((Double) argument).doubleValue());
    } else if (argument instanceof Float) {
        owlLiteral = factory.getOWLLiteral(((Float) argument).floatValue());
    } else if (argument instanceof Boolean) {
        owlLiteral = factory.getOWLLiteral(((Boolean) argument).booleanValue());
    } else {
        owlLiteral = factory.getOWLLiteral(argument.toString());
    }
    return factory.getSWRLLiteralArgument(owlLiteral);
}
Also used : URIResource(org.apache.stanbol.rules.base.api.URIResource) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) TypedLiteralAtom(org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom)

Example 5 with URIResource

use of org.apache.stanbol.rules.base.api.URIResource in project stanbol by apache.

the class TypedLiteralAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) ruleAtom;
    ExpressionAtom valueExpression = tmp.getValue();
    URIResource xsdTypeResource = tmp.getXsdType();
    SPARQLObject sparqlObject = null;
    sparqlObject = adapter.adaptTo(valueExpression, SPARQLObject.class);
    String value = sparqlObject.getObject();
    if (!value.startsWith("\"")) {
        value = "\"" + value;
    }
    if (!value.endsWith("\"")) {
        value += "\"";
    }
    String xsdType = "<" + xsdTypeResource.getURI().toString() + ">";
    return (T) new SPARQLFunction(value + "^^" + xsdType);
}
Also used : URIResource(org.apache.stanbol.rules.base.api.URIResource) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Aggregations

URIResource (org.apache.stanbol.rules.base.api.URIResource)5 Node (com.hp.hpl.jena.graph.Node)2 TypedLiteralAtom (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom)2 ArrayList (java.util.ArrayList)1 BuiltInCall (org.apache.clerezza.rdf.core.sparql.query.BuiltInCall)1 Expression (org.apache.clerezza.rdf.core.sparql.query.Expression)1 Variable (org.apache.clerezza.rdf.core.sparql.query.Variable)1 ClerezzaSparqlObject (org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)1 SPARQLFunction (org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)1 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)1 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)1 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)1 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)1 VariableAtom (org.apache.stanbol.rules.manager.atoms.VariableAtom)1 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)1 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)1