use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class SubtractionAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
String div_result = "subtraction_result" + System.currentTimeMillis();
Node arg1Node = null;
Node arg2Node = null;
Node arg3Node = Node_RuleVariable.createVariable(div_result);
org.apache.stanbol.rules.manager.atoms.SubtractionAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubtractionAtom) ruleAtom;
NumericFunctionAtom numericFunctionAtom1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom numericFunctionAtom2 = tmp.getNumericFunctionAtom2();
ClauseEntry clauseEntry1 = adapter.adaptTo(numericFunctionAtom1, Rule.class);
ClauseEntry clauseEntry2 = adapter.adaptTo(numericFunctionAtom2, Rule.class);
List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
if (clauseEntry1 instanceof HigherOrderClauseEntry) {
arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
} else if (clauseEntry1 instanceof NodeClauseEntry) {
arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (clauseEntry2 instanceof HigherOrderClauseEntry) {
arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
} else if (clauseEntry2 instanceof NodeClauseEntry) {
arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
java.util.List<Node> nodes = new ArrayList<Node>();
nodes.add(arg1Node);
nodes.add(arg2Node);
nodes.add(arg3Node);
ClauseEntry clauseEntry = new Functor("difference", nodes, BuiltinRegistry.theRegistry);
clauseEntries.add(clauseEntry);
return (T) new HigherOrderClauseEntry(arg3Node, clauseEntries);
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class SubtractionAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.SubtractionAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubtractionAtom) ruleAtom;
NumericFunctionAtom numericFunctionAtom1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom numericFunctionAtom2 = tmp.getNumericFunctionAtom2();
ClerezzaSparqlObject argument1 = (ClerezzaSparqlObject) adapter.adaptTo(numericFunctionAtom1, ConstructQuery.class);
ClerezzaSparqlObject argument2 = (ClerezzaSparqlObject) adapter.adaptTo(numericFunctionAtom2, ConstructQuery.class);
Expression lhsOperand = (Expression) argument1.getClerezzaObject();
Expression rhsOperand = (Expression) argument2.getClerezzaObject();
BinaryOperation binaryOperation = new BinaryOperation("-", lhsOperand, rhsOperand);
return (T) new ClerezzaSparqlObject(binaryOperation);
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class MultiplicationAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
String div_result = "mul_result" + System.currentTimeMillis();
Node arg1Node = null;
Node arg2Node = null;
Node arg3Node = Node_RuleVariable.createVariable(div_result);
org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) ruleAtom;
NumericFunctionAtom numericFunctionAtom1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom numericFunctionAtom2 = tmp.getNumericFunctionAtom2();
ClauseEntry clauseEntry1 = adapter.adaptTo(numericFunctionAtom1, Rule.class);
ClauseEntry clauseEntry2 = adapter.adaptTo(numericFunctionAtom2, Rule.class);
List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
if (clauseEntry1 instanceof HigherOrderClauseEntry) {
arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
} else if (clauseEntry1 instanceof NodeClauseEntry) {
arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (clauseEntry2 instanceof HigherOrderClauseEntry) {
arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
} else if (clauseEntry2 instanceof NodeClauseEntry) {
arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
java.util.List<Node> nodes = new ArrayList<Node>();
nodes.add(arg1Node);
nodes.add(arg2Node);
nodes.add(arg3Node);
ClauseEntry clauseEntry = new Functor("product", nodes, BuiltinRegistry.theRegistry);
clauseEntries.add(clauseEntry);
return (T) new HigherOrderClauseEntry(arg3Node, clauseEntries);
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class DivisionAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.DivisionAtom tmp = (org.apache.stanbol.rules.manager.atoms.DivisionAtom) ruleAtom;
NumericFunctionAtom numericFunctionAtom1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom numericFunctionAtom2 = tmp.getNumericFunctionAtom2();
ClerezzaSparqlObject argument1 = (ClerezzaSparqlObject) adapter.adaptTo(numericFunctionAtom1, ConstructQuery.class);
ClerezzaSparqlObject argument2 = (ClerezzaSparqlObject) adapter.adaptTo(numericFunctionAtom2, ConstructQuery.class);
Expression lhsOperand = (Expression) argument1.getClerezzaObject();
Expression rhsOperand = (Expression) argument2.getClerezzaObject();
BinaryOperation binaryOperation = new BinaryOperation("/", lhsOperand, rhsOperand);
return (T) new ClerezzaSparqlObject(binaryOperation);
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class SubstringAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
StringFunctionAtom argument = tmp.getStringFunctionAtom();
NumericFunctionAtom start = tmp.getStart();
NumericFunctionAtom length = tmp.getLength();
ClerezzaSparqlObject clerezzaArgument = (ClerezzaSparqlObject) adapter.adaptTo(argument, ConstructQuery.class);
ClerezzaSparqlObject clerezzaStart = (ClerezzaSparqlObject) adapter.adaptTo(start, ConstructQuery.class);
ClerezzaSparqlObject clerezzaLength = (ClerezzaSparqlObject) adapter.adaptTo(length, ConstructQuery.class);
List<Expression> argumentExpressions = new ArrayList<Expression>();
argumentExpressions.add((Expression) clerezzaArgument.getClerezzaObject());
argumentExpressions.add((Expression) clerezzaStart.getClerezzaObject());
argumentExpressions.add((Expression) clerezzaLength.getClerezzaObject());
FunctionCall functionCall = new FunctionCall(new IRI("<http://www.w3.org/2005/xpath-functions#substring>"), argumentExpressions);
return (T) new ClerezzaSparqlObject(functionCall);
}
Aggregations