Search in sources :

Example 16 with UnavailableRuleObjectException

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

the class ClerezzaAdpterTest method wrongAdaptabeClassTest.

@SuppressWarnings("unchecked")
@Test
public void wrongAdaptabeClassTest() {
    try {
        List<Rule> rules = (List<Rule>) ruleAdapter.adaptTo(recipeGood, Rule.class);
        for (Rule rule : rules) {
            log.debug(rule.toString());
            Assert.fail("The adapter for Clerezza should not accept " + Rule.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) Rule(com.hp.hpl.jena.reasoner.rulesys.Rule) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) Test(org.junit.Test)

Example 17 with UnavailableRuleObjectException

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

the class ClerezzaAdpterTest method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    try {
        List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipeGood, ConstructQuery.class);
        for (ConstructQuery constructQuery : constructQueries) {
            ConstructQuery cq = (ConstructQuery) QueryParser.getInstance().parse(constructQuery.toString());
            System.out.println(cq.toString());
        }
        Assert.assertTrue(true);
    } catch (UnavailableRuleObjectException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedTypeForExportException e) {
        Assert.fail(e.getMessage());
    } catch (RuleAtomCallExeption e) {
        Assert.fail(e.getMessage());
    } catch (ParseException 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) ParseException(org.apache.clerezza.rdf.core.sparql.ParseException) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) Test(org.junit.Test)

Example 18 with UnavailableRuleObjectException

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

the class SWRLAdpterTest method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    try {
        List<SWRLRule> rules = (List<SWRLRule>) ruleAdapter.adaptTo(recipeGood, SWRLRule.class);
        StringBuilder sb = new StringBuilder();
        for (SWRLRule rule : rules) {
            sb.append(rule.toString());
        }
        Assert.assertNotSame(sb.toString(), "");
    } 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) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) List(java.util.List) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) Test(org.junit.Test)

Example 19 with UnavailableRuleObjectException

use of org.apache.stanbol.rules.base.api.UnavailableRuleObjectException 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)

Example 20 with UnavailableRuleObjectException

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

the class UnionAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.UnionAtom tmp = (org.apache.stanbol.rules.manager.atoms.UnionAtom) ruleAtom;
    AtomList atomList1 = tmp.getAtomList1();
    AtomList atomList2 = tmp.getAtomList2();
    String scope1 = "";
    for (RuleAtom inGroupRuleAtom : atomList1) {
        if (!scope1.isEmpty()) {
            scope1 += " . ";
        }
        try {
            SPARQLObject inGroupSparqlAtom = adapter.adaptTo(inGroupRuleAtom, SPARQLObject.class);
            scope1 += inGroupSparqlAtom.getObject();
        } 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());
        }
    }
    String scope2 = "";
    for (RuleAtom inGroupRuleAtom : atomList2) {
        if (!scope2.isEmpty()) {
            scope2 += " . ";
        }
        try {
            SPARQLObject inGroupSparqlAtom = adapter.adaptTo(inGroupRuleAtom, SPARQLObject.class);
            scope2 += inGroupSparqlAtom.getObject();
        } 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());
        }
    }
    String sparqlUnion = " { " + scope1 + " } UNION { " + scope2 + " } ";
    return (T) new SPARQLFunction(sparqlUnion);
}
Also used : AtomList(org.apache.stanbol.rules.base.api.util.AtomList) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) RuleAtom(org.apache.stanbol.rules.base.api.RuleAtom)

Aggregations

UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)22 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)21 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)21 List (java.util.List)10 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)10 Test (org.junit.Test)7 RuleAdapter (org.apache.stanbol.rules.base.api.RuleAdapter)6 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)5 SPARQLComparison (org.apache.stanbol.rules.adapters.sparql.SPARQLComparison)5 SPARQLFunction (org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)4 Recipe (org.apache.stanbol.rules.base.api.Recipe)4 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)4 Rule (com.hp.hpl.jena.reasoner.rulesys.Rule)3 IRI (org.apache.clerezza.commons.rdf.IRI)3 NoSuchRecipeException (org.apache.stanbol.rules.base.api.NoSuchRecipeException)3 RecipeConstructionException (org.apache.stanbol.rules.base.api.RecipeConstructionException)3 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)3 Graph (org.apache.clerezza.commons.rdf.Graph)2 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)2 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)2