Search in sources :

Example 21 with ExpressionAtom

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

the class RuleParserImpl method lessEqualThanAtom.

public final LessEqualThanAtom lessEqualThanAtom() throws ParseException {
    ExpressionAtom obj1;
    ExpressionAtom obj2;
    jj_consume_token(LESSEQUALTHAN);
    jj_consume_token(LPAR);
    obj1 = expressionAtom();
    jj_consume_token(COMMA);
    obj2 = expressionAtom();
    jj_consume_token(RPAR);
    {
        if (true)
            return new LessEqualThanAtom(obj1, obj2);
    }
    throw new Error("Missing return statement in function");
}
Also used : LessEqualThanAtom(org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom)

Example 22 with ExpressionAtom

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

the class RuleParserImpl method expressionAtom.

public final ExpressionAtom expressionAtom() throws ParseException {
    ExpressionAtom expressionAtom;
    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case SUBSTRING:
        case UPPERCASE:
        case LOWERCASE:
        case CONCAT:
        case NAMESPACE:
        case LOCALNAME:
        case STR:
        case CREATE_LABEL:
        case PROP:
        case VARIABLE:
        case STRING:
            expressionAtom = stringFunctionAtom();
            break;
        case LENGTH:
        case PLUS:
        case MINUS:
        case NUM:
            expressionAtom = numericFunctionAtom();
            break;
        default:
            jj_la1[6] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    {
        if (true)
            return expressionAtom;
    }
    throw new Error("Missing return statement in function");
}
Also used : ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom)

Example 23 with ExpressionAtom

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

the class GreaterEqualThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.GreaterEqualThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.GreaterEqualThanAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getArgument1();
    ExpressionAtom argument2 = tmp.getArgument2();
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    SWRLAtom swrlAtom1 = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
    SWRLAtom swrlAtom2 = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
    SWRLDArgument swrldArgument1;
    SWRLDArgument swrldArgument2;
    List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
    if (swrlAtom1 instanceof HigherOrderSWRLAtom) {
        swrldArgument1 = ((HigherOrderSWRLAtom) swrlAtom1).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom1).getAtoms());
    } else if (swrlAtom1 instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom1).getSwrlArgument();
        swrldArgument1 = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (swrlAtom2 instanceof HigherOrderSWRLAtom) {
        swrldArgument2 = ((HigherOrderSWRLAtom) swrlAtom2).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom2).getAtoms());
    } else if (swrlAtom2 instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom2).getSwrlArgument();
        swrldArgument2 = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    List<SWRLDArgument> swrldArguments = new ArrayList<SWRLDArgument>();
    swrldArguments.add(swrldArgument1);
    swrldArguments.add(swrldArgument2);
    SWRLBuiltInAtom swrlBuiltInAtom = factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.GREATER_THAN_OR_EQUAL.getIRI(), swrldArguments);
    return (T) swrlBuiltInAtom;
}
Also used : ArrayList(java.util.ArrayList) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) 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) SWRLBuiltInAtom(org.semanticweb.owlapi.model.SWRLBuiltInAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) SWRLArgument(org.semanticweb.owlapi.model.SWRLArgument) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 24 with ExpressionAtom

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

the class MultiplicationAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String mul_result = "mul_result" + System.currentTimeMillis();
    org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getNumericFunctionAtom1();
    ExpressionAtom argument2 = tmp.getNumericFunctionAtom2();
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    SWRLAtom swrlAtom1 = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
    SWRLAtom swrlAtom2 = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
    SWRLDArgument swrldArgument1 = factory.getSWRLVariable(IRI.create(Symbols.variablesPrefix + mul_result));
    SWRLDArgument swrldArgument2;
    SWRLDArgument swrldArgument3;
    List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
    if (swrlAtom1 instanceof HigherOrderSWRLAtom) {
        swrldArgument2 = ((HigherOrderSWRLAtom) swrlAtom1).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom1).getAtoms());
    } else if (swrlAtom1 instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom1).getSwrlArgument();
        swrldArgument2 = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (swrlAtom2 instanceof HigherOrderSWRLAtom) {
        swrldArgument3 = ((HigherOrderSWRLAtom) swrlAtom2).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom2).getAtoms());
    } else if (swrlAtom2 instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom2).getSwrlArgument();
        swrldArgument3 = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    List<SWRLDArgument> swrldArguments = new ArrayList<SWRLDArgument>();
    swrldArguments.add(swrldArgument1);
    swrldArguments.add(swrldArgument2);
    swrldArguments.add(swrldArgument3);
    SWRLBuiltInAtom swrlBuiltInAtom = factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.MULTIPLY.getIRI(), swrldArguments);
    listOfArguments.add(swrlBuiltInAtom);
    return (T) new HigherOrderSWRLAtom(swrldArgument1, listOfArguments);
}
Also used : ArrayList(java.util.ArrayList) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) 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) SWRLBuiltInAtom(org.semanticweb.owlapi.model.SWRLBuiltInAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) SWRLArgument(org.semanticweb.owlapi.model.SWRLArgument) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 25 with ExpressionAtom

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

the class TypedLiteralAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) ruleAtom;
    ExpressionAtom valueExpression = tmp.getValue();
    URIResource xsdTypeResource = tmp.getXsdType();
    SPARQLObject sparqlObject = null;
    sparqlObject = adapter.adaptTo(valueExpression, SPARQLObject.class);
    String value = sparqlObject.getObject();
    if (!value.startsWith("\"")) {
        value = "\"" + value;
    }
    if (!value.endsWith("\"")) {
        value += "\"";
    }
    String xsdType = "<" + xsdTypeResource.getURI().toString() + ">";
    return (T) new SPARQLFunction(value + "^^" + xsdType);
}
Also used : URIResource(org.apache.stanbol.rules.base.api.URIResource) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Aggregations

ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)40 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)20 ArrayList (java.util.ArrayList)18 Node (com.hp.hpl.jena.graph.Node)9 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)9 Functor (com.hp.hpl.jena.reasoner.rulesys.Functor)9 HigherOrderClauseEntry (org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry)9 NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)9 ArgumentSWRLAtom (org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom)9 HigherOrderSWRLAtom (org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom)9 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)9 SWRLArgument (org.semanticweb.owlapi.model.SWRLArgument)9 SWRLAtom (org.semanticweb.owlapi.model.SWRLAtom)9 SWRLDArgument (org.semanticweb.owlapi.model.SWRLDArgument)9 SWRLRule (org.semanticweb.owlapi.model.SWRLRule)9 SWRLBuiltInAtom (org.semanticweb.owlapi.model.SWRLBuiltInAtom)8 ClerezzaSparqlObject (org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)7 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)7 BinaryOperation (org.apache.clerezza.rdf.core.sparql.query.BinaryOperation)6 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)6