use of org.apache.stanbol.rules.manager.atoms.ExpressionAtom in project stanbol by apache.
the class StartsWithAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.StartsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.StartsWithAtom) ruleAtom;
ExpressionAtom argument = tmp.getArgument();
ExpressionAtom term = tmp.getTerm();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
SWRLAtom swrlAtom1 = (SWRLAtom) adapter.adaptTo(argument, SWRLRule.class);
SWRLAtom swrlAtom2 = (SWRLAtom) adapter.adaptTo(term, SWRLRule.class);
SWRLDArgument swrldArgument1;
SWRLDArgument swrldArgument2;
List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
if (swrlAtom1 instanceof HigherOrderSWRLAtom) {
swrldArgument1 = ((HigherOrderSWRLAtom) swrlAtom1).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom1).getAtoms());
} else if (swrlAtom1 instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom1).getSwrlArgument();
swrldArgument1 = (SWRLDArgument) swrlArgument;
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (swrlAtom2 instanceof HigherOrderSWRLAtom) {
swrldArgument2 = ((HigherOrderSWRLAtom) swrlAtom2).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom2).getAtoms());
} else if (swrlAtom2 instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom2).getSwrlArgument();
swrldArgument2 = (SWRLDArgument) swrlArgument;
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
List<SWRLDArgument> swrldArguments = new ArrayList<SWRLDArgument>();
swrldArguments.add(swrldArgument1);
swrldArguments.add(swrldArgument2);
return (T) factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.STARTS_WITH.getIRI(), swrldArguments);
}
use of org.apache.stanbol.rules.manager.atoms.ExpressionAtom in project stanbol by apache.
the class DifferentAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.DifferentAtom tmp = (org.apache.stanbol.rules.manager.atoms.DifferentAtom) ruleAtom;
ExpressionAtom stringFunctionAtom1 = tmp.getStringFunctionAtom1();
ExpressionAtom stringFunctionAtom2 = tmp.getStringFunctionAtom1();
ClerezzaSparqlObject argument1 = (ClerezzaSparqlObject) adapter.adaptTo(stringFunctionAtom1, ConstructQuery.class);
ClerezzaSparqlObject argument2 = (ClerezzaSparqlObject) adapter.adaptTo(stringFunctionAtom2, ConstructQuery.class);
Expression lhe = (Expression) argument1.getClerezzaObject();
Expression rhe = (Expression) argument2.getClerezzaObject();
BinaryOperation binaryOperation = new BinaryOperation("!=", lhe, rhe);
return (T) new ClerezzaSparqlObject(binaryOperation);
}
use of org.apache.stanbol.rules.manager.atoms.ExpressionAtom in project stanbol by apache.
the class LessThanAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.LessThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessThanAtom) ruleAtom;
ExpressionAtom argument1 = tmp.getArgument1();
ExpressionAtom argument2 = tmp.getArgument2();
ClerezzaSparqlObject clerezzaArgument1 = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
ClerezzaSparqlObject clerezzaArgument2 = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
Expression lhe = (Expression) clerezzaArgument1.getClerezzaObject();
Expression rhe = (Expression) clerezzaArgument2.getClerezzaObject();
return (T) new ClerezzaSparqlObject(new BinaryOperation("<", lhe, rhe));
}
use of org.apache.stanbol.rules.manager.atoms.ExpressionAtom in project stanbol by apache.
the class SameAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
org.apache.stanbol.rules.manager.atoms.SameAtom tmp = (org.apache.stanbol.rules.manager.atoms.SameAtom) ruleAtom;
ExpressionAtom argument1 = tmp.getStringFunctionAtom1();
ExpressionAtom argument2 = tmp.getStringFunctionAtom2();
ClerezzaSparqlObject clerezzaArgument1 = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
ClerezzaSparqlObject clerezzaArgument2 = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
Expression lhe = (Expression) clerezzaArgument1.getClerezzaObject();
Expression rhe = (Expression) clerezzaArgument2.getClerezzaObject();
return (T) new ClerezzaSparqlObject(new BinaryOperation("=", lhe, rhe));
}
use of org.apache.stanbol.rules.manager.atoms.ExpressionAtom 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