Search in sources :

Example 1 with NumericFunctionAtom

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");
}
Also used : StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) SubstringAtom(org.apache.stanbol.rules.manager.atoms.SubstringAtom)

Example 2 with NumericFunctionAtom

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");
}
Also used : SumAtom(org.apache.stanbol.rules.manager.atoms.SumAtom) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)

Example 3 with NumericFunctionAtom

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);
}
Also used : Node(com.hp.hpl.jena.graph.Node) ArrayList(java.util.ArrayList) Functor(com.hp.hpl.jena.reasoner.rulesys.Functor) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) HigherOrderClauseEntry(org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry) ClauseEntry(com.hp.hpl.jena.reasoner.rulesys.ClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry) HigherOrderClauseEntry(org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry) NodeClauseEntry(org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)

Example 4 with NumericFunctionAtom

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);
}
Also used : BinaryOperation(org.apache.clerezza.rdf.core.sparql.query.BinaryOperation) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Example 5 with NumericFunctionAtom

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());
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)

Aggregations

NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)21 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)8 ArrayList (java.util.ArrayList)6 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)5 Expression (org.apache.clerezza.rdf.core.sparql.query.Expression)5 ClerezzaSparqlObject (org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)5 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)5 Node (com.hp.hpl.jena.graph.Node)4 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)4 Functor (com.hp.hpl.jena.reasoner.rulesys.Functor)4 BinaryOperation (org.apache.clerezza.rdf.core.sparql.query.BinaryOperation)4 HigherOrderClauseEntry (org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry)4 NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)4 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)4 SPARQLComparison (org.apache.stanbol.rules.adapters.sparql.SPARQLComparison)3 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)3 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)3 SPARQLFunction (org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)2 IRI (org.apache.clerezza.commons.rdf.IRI)1 FunctionCall (org.apache.clerezza.rdf.core.sparql.query.FunctionCall)1