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;
}
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());
}
}
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;
}
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);
}
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);
}
Aggregations