use of org.apache.clerezza.rdf.core.sparql.query.LiteralExpression 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();
ClerezzaSparqlObject argument1CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
ClerezzaSparqlObject datatypePropertyCSO = (ClerezzaSparqlObject) adapter.adaptTo(datatypeProperty, ConstructQuery.class);
ClerezzaSparqlObject argument2CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
Object arg1 = argument1CSO.getClerezzaObject();
Object dt = datatypePropertyCSO.getClerezzaObject();
Object arg2 = argument2CSO.getClerezzaObject();
UriRefOrVariable subject;
UriRefOrVariable predicate;
ResourceOrVariable object;
if (arg1 instanceof Variable) {
subject = new UriRefOrVariable((Variable) arg1);
} else if (arg1 instanceof IRI) {
subject = new UriRefOrVariable((IRI) arg1);
} else {
throw new RuleAtomCallExeption(getClass());
}
if (dt instanceof Variable) {
predicate = new UriRefOrVariable((Variable) dt);
} else if (dt instanceof IRI) {
predicate = new UriRefOrVariable((IRI) dt);
} else {
throw new RuleAtomCallExeption(getClass());
}
if (arg2 instanceof Variable) {
object = new ResourceOrVariable((Variable) arg2);
} else if (arg2 instanceof LiteralExpression) {
object = new ResourceOrVariable(((LiteralExpression) arg2).getLiteral());
} else {
throw new RuleAtomCallExeption(getClass());
}
return (T) new ClerezzaSparqlObject(new SimpleTriplePattern(subject, predicate, object));
}
use of org.apache.clerezza.rdf.core.sparql.query.LiteralExpression in project stanbol by apache.
the class NumberAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.NumberAtom tmp = (org.apache.stanbol.rules.manager.atoms.NumberAtom) ruleAtom;
String number = tmp.getNumber();
Expression exp = null;
if (number.startsWith("\"") && number.endsWith("\"")) {
number = number.substring(1, number.length() - 1);
}
if (number.startsWith(Symbols.variablesPrefix)) {
exp = new Variable(number.replace(Symbols.variablesPrefix, ""));
} else {
exp = new LiteralExpression(LiteralFactory.getInstance().createTypedLiteral(number));
}
return (T) new ClerezzaSparqlObject(exp);
}
use of org.apache.clerezza.rdf.core.sparql.query.LiteralExpression in project stanbol by apache.
the class StringAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.StringAtom tmp = (org.apache.stanbol.rules.manager.atoms.StringAtom) ruleAtom;
String string = tmp.getString();
Expression exp = null;
if (string.startsWith("\"") && string.endsWith("\"")) {
string = string.substring(1, string.length() - 1);
}
if (string.startsWith(Symbols.variablesPrefix)) {
exp = new Variable(string.replace(Symbols.variablesPrefix, ""));
} else {
exp = new LiteralExpression(new PlainLiteralImpl(string));
}
return (T) new ClerezzaSparqlObject(exp);
}
use of org.apache.clerezza.rdf.core.sparql.query.LiteralExpression in project stanbol by apache.
the class TypedLiteralAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) ruleAtom;
ExpressionAtom expressionAtom = tmp.getValue();
Literal literal = null;
if (expressionAtom instanceof StringAtom) {
String value = expressionAtom.toString();
literal = LiteralFactory.getInstance().createTypedLiteral(value);
} else if (expressionAtom instanceof NumberAtom) {
Number number = ((NumberAtom) expressionAtom).getNumberValue();
literal = LiteralFactory.getInstance().createTypedLiteral(number);
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
LiteralExpression literalExpression = new LiteralExpression(literal);
return (T) new ClerezzaSparqlObject(literalExpression);
}
Aggregations