use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class RuleParserImpl method substringAtom.
public final SubstringAtom substringAtom() throws ParseException {
StringFunctionAtom arg;
NumericFunctionAtom start;
NumericFunctionAtom length;
jj_consume_token(SUBSTRING);
jj_consume_token(LPAR);
arg = stringFunctionAtom();
jj_consume_token(COMMA);
start = numericFunctionAtom();
jj_consume_token(COMMA);
length = numericFunctionAtom();
jj_consume_token(RPAR);
{
if (true)
return new SubstringAtom(arg, start, length);
}
throw new Error("Missing return statement in function");
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class RuleParserImpl method sumAtom.
public final SumAtom sumAtom() throws ParseException {
NumericFunctionAtom numericFunctionAtom1;
NumericFunctionAtom numericFunctionAtom2;
jj_consume_token(PLUS);
jj_consume_token(LPAR);
numericFunctionAtom1 = numericFunctionAtom();
jj_consume_token(COMMA);
numericFunctionAtom2 = numericFunctionAtom();
jj_consume_token(RPAR);
{
if (true)
return new SumAtom(numericFunctionAtom1, numericFunctionAtom2);
}
throw new Error("Missing return statement in function");
}
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 {
String div_result = "div_result" + System.currentTimeMillis();
Node arg1Node = null;
Node arg2Node = null;
Node arg3Node = Node_RuleVariable.createVariable(div_result);
org.apache.stanbol.rules.manager.atoms.DivisionAtom tmp = (org.apache.stanbol.rules.manager.atoms.DivisionAtom) 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("quotient", 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 MultiplicationAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) 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 {
org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) ruleAtom;
NumericFunctionAtom argument1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom argument2 = tmp.getNumericFunctionAtom2();
SPARQLObject sparqlArgument1 = adapter.adaptTo(argument1, SPARQLObject.class);
SPARQLObject sparqlArgument2 = adapter.adaptTo(argument2, SPARQLObject.class);
String sparqlFunction1 = sparqlArgument1.getObject();
String sparqlFunction2 = sparqlArgument2.getObject();
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(sparqlFunction1);
sb.append(" * ");
sb.append(sparqlFunction2);
sb.append(")");
return (T) new SPARQLComparison(sb.toString());
}
Aggregations