Search in sources :

Example 26 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.

the class SWRLAdpterTest method wrongAdaptabeClassTest.

@SuppressWarnings("unchecked")
@Test
public void wrongAdaptabeClassTest() {
    try {
        List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipeGood, ConstructQuery.class);
        for (ConstructQuery constructQuery : constructQueries) {
            log.debug(constructQuery.toString());
            Assert.fail("The adapter for Jena should not accept " + ConstructQuery.class.getCanonicalName() + " objects.");
        }
    } catch (UnavailableRuleObjectException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedTypeForExportException e) {
        log.debug(e.getMessage());
    } catch (RuleAtomCallExeption e) {
        Assert.fail(e.getMessage());
    }
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) List(java.util.List) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) Test(org.junit.Test)

Example 27 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.

the class SPARQLAdpterTest method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    try {
        List<SPARQLObject> sparqlObjects = (List<SPARQLObject>) ruleAdapter.adaptTo(recipeGood, SPARQLObject.class);
        for (SPARQLObject sparqlObject : sparqlObjects) {
            log.debug(sparqlObject.getObject());
        }
        Assert.assertTrue(true);
    } catch (UnavailableRuleObjectException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedTypeForExportException e) {
        Assert.fail(e.getMessage());
    } catch (RuleAtomCallExeption e) {
        Assert.fail(e.getMessage());
    }
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) List(java.util.List) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) Test(org.junit.Test)

Example 28 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.

the class ClassAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    IObjectAtom classResource = tmp.getClassResource();
    IObjectAtom argument = tmp.getArgument1();
    SWRLAtom classResourceAtom = (SWRLAtom) adapter.adaptTo(classResource, SWRLRule.class);
    SWRLAtom argumentAtom = (SWRLAtom) adapter.adaptTo(argument, SWRLRule.class);
    OWLClass classPredicate;
    SWRLIArgument argumentResource;
    if (classResourceAtom instanceof ArgumentSWRLAtom) {
        classPredicate = factory.getOWLClass(IRI.create(((ArgumentSWRLAtom) classResourceAtom).getId()));
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (argumentAtom instanceof ArgumentSWRLAtom) {
        argumentResource = (SWRLIArgument) ((ArgumentSWRLAtom) argumentAtom).getSwrlArgument();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) factory.getSWRLClassAtom(classPredicate, argumentResource);
}
Also used : ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) SWRLIArgument(org.semanticweb.owlapi.model.SWRLIArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLClass(org.semanticweb.owlapi.model.OWLClass) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 29 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.

the class GreaterThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.GreaterThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.GreaterThanAtom) 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.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 30 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.

the class LessEqualThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom) 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.LESS_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)

Aggregations

RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)64 ArrayList (java.util.ArrayList)31 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)21 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)21 Node (com.hp.hpl.jena.graph.Node)20 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)20 NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)20 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)20 SWRLRule (org.semanticweb.owlapi.model.SWRLRule)18 Functor (com.hp.hpl.jena.reasoner.rulesys.Functor)16 ArgumentSWRLAtom (org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom)16 SWRLAtom (org.semanticweb.owlapi.model.SWRLAtom)16 HigherOrderClauseEntry (org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry)15 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)15 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)15 SWRLDArgument (org.semanticweb.owlapi.model.SWRLDArgument)13 HigherOrderSWRLAtom (org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom)12 SWRLArgument (org.semanticweb.owlapi.model.SWRLArgument)12 List (java.util.List)10 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)10