Search in sources :

Example 6 with NumericFunctionAtom

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 {
    org.apache.stanbol.rules.manager.atoms.SubtractionAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubtractionAtom) ruleAtom;
    NumericFunctionAtom argument1 = tmp.getNumericFunctionAtom1();
    NumericFunctionAtom argument2 = tmp.getNumericFunctionAtom2();
    try {
        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());
    } catch (UnsupportedTypeForExportException e) {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    } catch (UnavailableRuleObjectException e) {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Example 7 with NumericFunctionAtom

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 {
    org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
    StringFunctionAtom stringFunctionAtom = tmp.getStringFunctionAtom();
    NumericFunctionAtom startAtom = tmp.getStart();
    NumericFunctionAtom lengthAtom = tmp.getLength();
    try {
        SPARQLObject stringSparqlAtom = adapter.adaptTo(stringFunctionAtom, SPARQLObject.class);
        SPARQLObject startSparqlAtom = adapter.adaptTo(startAtom, SPARQLObject.class);
        SPARQLObject lengthSparqlAtom = adapter.adaptTo(lengthAtom, SPARQLObject.class);
        String uriResourceString = stringSparqlAtom.getObject();
        String start = startSparqlAtom.getObject();
        String length = lengthSparqlAtom.getObject();
        String sparql = "<http://www.w3.org/2005/xpath-functions#substring> (" + uriResourceString + ", " + start + ", " + length + ")";
        return (T) new SPARQLFunction(sparql);
    } catch (UnsupportedTypeForExportException e) {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    } catch (UnavailableRuleObjectException e) {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Example 8 with NumericFunctionAtom

use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.

the class SumAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String div_result = "sum_result" + System.currentTimeMillis();
    Node arg1Node = null;
    Node arg2Node = null;
    Node arg3Node = Node_RuleVariable.createVariable(div_result);
    org.apache.stanbol.rules.manager.atoms.SumAtom tmp = (org.apache.stanbol.rules.manager.atoms.SumAtom) 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("sum", 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 9 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, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    org.apache.stanbol.rules.manager.atoms.DivisionAtom tmp = (org.apache.stanbol.rules.manager.atoms.DivisionAtom) 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 SPARQLFunction(sb.toString());
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Example 10 with NumericFunctionAtom

use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.

the class RuleParserImpl method divisionAtom.

public final DivisionAtom divisionAtom() throws ParseException {
    NumericFunctionAtom numericFunctionAtom1;
    NumericFunctionAtom numericFunctionAtom2;
    jj_consume_token(DIVIDED);
    jj_consume_token(LPAR);
    numericFunctionAtom1 = numericFunctionAtom();
    jj_consume_token(COMMA);
    numericFunctionAtom2 = numericFunctionAtom();
    jj_consume_token(RPAR);
    {
        if (true)
            return new DivisionAtom(numericFunctionAtom1, numericFunctionAtom2);
    }
    throw new Error("Missing return statement in function");
}
Also used : DivisionAtom(org.apache.stanbol.rules.manager.atoms.DivisionAtom) 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