Search in sources :

Example 1 with TypedLiteralAtom

use of org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom 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 TypedLiteralAtom

use of org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom in project stanbol by apache.

the class RuleParserImpl method literal.

public final ExpressionAtom literal() throws ParseException {
    ExpressionAtom literal;
    IObjectAtom typedLiteral;
    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case STRING:
            literal = getString();
            typedLiteral = typedLiteral();
            break;
        case NUM:
            literal = getInt();
            typedLiteral = typedLiteral();
            break;
        default:
            jj_la1[13] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    if (typedLiteral != null) {
        {
            if (true)
                return new TypedLiteralAtom(literal, typedLiteral);
        }
    } else {
        {
            if (true)
                return literal;
        }
    }
    throw new Error("Missing return statement in function");
}
Also used : TypedLiteralAtom(org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom)

Example 3 with TypedLiteralAtom

use of org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom 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)

Aggregations

TypedLiteralAtom (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom)3 URIResource (org.apache.stanbol.rules.base.api.URIResource)2 Node (com.hp.hpl.jena.graph.Node)1 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)1 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)1 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)1 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)1