Search in sources :

Example 11 with NumericFunctionAtom

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

the class RuleParserImpl method multiplicationAtom.

public final MultiplicationAtom multiplicationAtom() throws ParseException {
    NumericFunctionAtom numericFunctionAtom1;
    NumericFunctionAtom numericFunctionAtom2;
    jj_consume_token(MULTIPLIED);
    jj_consume_token(LPAR);
    numericFunctionAtom1 = numericFunctionAtom();
    jj_consume_token(COMMA);
    numericFunctionAtom2 = numericFunctionAtom();
    jj_consume_token(RPAR);
    {
        if (true)
            return new MultiplicationAtom(numericFunctionAtom1, numericFunctionAtom2);
    }
    throw new Error("Missing return statement in function");
}
Also used : MultiplicationAtom(org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)

Example 12 with NumericFunctionAtom

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

the class RuleParserImpl method numericFunctionAtom.

public final NumericFunctionAtom numericFunctionAtom() throws ParseException {
    NumericFunctionAtom numericFunctionAtom;
    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case PLUS:
            numericFunctionAtom = sumAtom();
            break;
        case MINUS:
            numericFunctionAtom = subtractionAtom();
            break;
        case LENGTH:
            numericFunctionAtom = lengthAtom();
            break;
        case NUM:
            numericFunctionAtom = numberAtom();
            break;
        case VARIABLE:
            numericFunctionAtom = numericVariable();
            break;
        default:
            jj_la1[7] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    {
        if (true)
            return numericFunctionAtom;
    }
    throw new Error("Missing return statement in function");
}
Also used : NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)

Example 13 with NumericFunctionAtom

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

the class RuleParserImpl method subtractionAtom.

public final SubtractionAtom subtractionAtom() throws ParseException {
    NumericFunctionAtom numericFunctionAtom1;
    NumericFunctionAtom numericFunctionAtom2;
    jj_consume_token(MINUS);
    jj_consume_token(LPAR);
    numericFunctionAtom1 = numericFunctionAtom();
    jj_consume_token(COMMA);
    numericFunctionAtom2 = numericFunctionAtom();
    jj_consume_token(RPAR);
    {
        if (true)
            return new SubtractionAtom(numericFunctionAtom1, numericFunctionAtom2);
    }
    throw new Error("Missing return statement in function");
}
Also used : NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) SubtractionAtom(org.apache.stanbol.rules.manager.atoms.SubtractionAtom)

Example 14 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, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String substring_result = "substrig_result" + System.currentTimeMillis();
    org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
    StringFunctionAtom stringFunction = tmp.getStringFunctionAtom();
    NumericFunctionAtom start = tmp.getStart();
    NumericFunctionAtom length = tmp.getLength();
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    SWRLAtom stringFunctionAtom = (SWRLAtom) adapter.adaptTo(stringFunction, SWRLRule.class);
    SWRLAtom startAtom = (SWRLAtom) adapter.adaptTo(start, SWRLRule.class);
    SWRLAtom lengthAtom = (SWRLAtom) adapter.adaptTo(length, SWRLRule.class);
    SWRLDArgument retArgument = factory.getSWRLVariable(IRI.create(Symbols.variablesPrefix + substring_result));
    ;
    SWRLDArgument stringArgument;
    SWRLDArgument startArgument;
    SWRLDArgument lengthArgument;
    List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
    if (stringFunctionAtom instanceof HigherOrderSWRLAtom) {
        stringArgument = ((HigherOrderSWRLAtom) stringFunctionAtom).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) stringFunctionAtom).getAtoms());
    } else if (stringFunctionAtom instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) stringFunctionAtom).getSwrlArgument();
        stringArgument = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (startAtom instanceof HigherOrderSWRLAtom) {
        startArgument = ((HigherOrderSWRLAtom) startAtom).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) startAtom).getAtoms());
    } else if (startAtom instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) startAtom).getSwrlArgument();
        startArgument = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (lengthAtom instanceof HigherOrderSWRLAtom) {
        lengthArgument = ((HigherOrderSWRLAtom) lengthAtom).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) lengthAtom).getAtoms());
    } else if (lengthAtom instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) lengthAtom).getSwrlArgument();
        lengthArgument = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    List<SWRLDArgument> swrldArguments = new ArrayList<SWRLDArgument>();
    swrldArguments.add(retArgument);
    swrldArguments.add(stringArgument);
    swrldArguments.add(startArgument);
    swrldArguments.add(lengthArgument);
    return (T) factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.SUBSTRING.getIRI(), swrldArguments);
}
Also used : ArrayList(java.util.ArrayList) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) SWRLDArgument(org.semanticweb.owlapi.model.SWRLDArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) SWRLArgument(org.semanticweb.owlapi.model.SWRLArgument) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 15 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 {
    org.apache.stanbol.rules.manager.atoms.SumAtom tmp = (org.apache.stanbol.rules.manager.atoms.SumAtom) 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)

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