Search in sources :

Example 26 with ExpressionAtom

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

the class StartsWithAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.StartsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.StartsWithAtom) ruleAtom;
    ExpressionAtom argument = tmp.getArgument();
    ExpressionAtom term = tmp.getTerm();
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    SWRLAtom swrlAtom1 = (SWRLAtom) adapter.adaptTo(argument, SWRLRule.class);
    SWRLAtom swrlAtom2 = (SWRLAtom) adapter.adaptTo(term, 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);
    return (T) factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.STARTS_WITH.getIRI(), swrldArguments);
}
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) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) SWRLArgument(org.semanticweb.owlapi.model.SWRLArgument) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 27 with ExpressionAtom

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

the class DifferentAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.DifferentAtom tmp = (org.apache.stanbol.rules.manager.atoms.DifferentAtom) ruleAtom;
    ExpressionAtom stringFunctionAtom1 = tmp.getStringFunctionAtom1();
    ExpressionAtom stringFunctionAtom2 = tmp.getStringFunctionAtom1();
    ClerezzaSparqlObject argument1 = (ClerezzaSparqlObject) adapter.adaptTo(stringFunctionAtom1, ConstructQuery.class);
    ClerezzaSparqlObject argument2 = (ClerezzaSparqlObject) adapter.adaptTo(stringFunctionAtom2, ConstructQuery.class);
    Expression lhe = (Expression) argument1.getClerezzaObject();
    Expression rhe = (Expression) argument2.getClerezzaObject();
    BinaryOperation binaryOperation = new BinaryOperation("!=", lhe, rhe);
    return (T) new ClerezzaSparqlObject(binaryOperation);
}
Also used : BinaryOperation(org.apache.clerezza.rdf.core.sparql.query.BinaryOperation) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) 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 28 with ExpressionAtom

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

the class LessThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LessThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessThanAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getArgument1();
    ExpressionAtom argument2 = tmp.getArgument2();
    ClerezzaSparqlObject clerezzaArgument1 = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
    ClerezzaSparqlObject clerezzaArgument2 = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
    Expression lhe = (Expression) clerezzaArgument1.getClerezzaObject();
    Expression rhe = (Expression) clerezzaArgument2.getClerezzaObject();
    return (T) new ClerezzaSparqlObject(new BinaryOperation("<", lhe, rhe));
}
Also used : BinaryOperation(org.apache.clerezza.rdf.core.sparql.query.BinaryOperation) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) 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 29 with ExpressionAtom

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

the class SameAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    org.apache.stanbol.rules.manager.atoms.SameAtom tmp = (org.apache.stanbol.rules.manager.atoms.SameAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getStringFunctionAtom1();
    ExpressionAtom argument2 = tmp.getStringFunctionAtom2();
    ClerezzaSparqlObject clerezzaArgument1 = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
    ClerezzaSparqlObject clerezzaArgument2 = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
    Expression lhe = (Expression) clerezzaArgument1.getClerezzaObject();
    Expression rhe = (Expression) clerezzaArgument2.getClerezzaObject();
    return (T) new ClerezzaSparqlObject(new BinaryOperation("=", lhe, rhe));
}
Also used : BinaryOperation(org.apache.clerezza.rdf.core.sparql.query.BinaryOperation) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) 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 30 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 {
    org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) ruleAtom;
    ExpressionAtom expressionAtom = tmp.getValue();
    Literal literal = null;
    if (expressionAtom instanceof StringAtom) {
        String value = expressionAtom.toString();
        literal = LiteralFactory.getInstance().createTypedLiteral(value);
    } else if (expressionAtom instanceof NumberAtom) {
        Number number = ((NumberAtom) expressionAtom).getNumberValue();
        literal = LiteralFactory.getInstance().createTypedLiteral(number);
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    LiteralExpression literalExpression = new LiteralExpression(literal);
    return (T) new ClerezzaSparqlObject(literalExpression);
}
Also used : StringAtom(org.apache.stanbol.rules.manager.atoms.StringAtom) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) NumberAtom(org.apache.stanbol.rules.manager.atoms.NumberAtom) Literal(org.apache.clerezza.commons.rdf.Literal) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

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