Search in sources :

Example 11 with UnsupportedTypeForExportException

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

the class SWRLAdapter method adaptRecipeTo.

@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    List<SWRLRule> swrlRules = null;
    if (type == SWRLRule.class) {
        RuleList ruleList = recipe.getRuleList();
        swrlRules = new ArrayList<SWRLRule>();
        if (ruleList != null && !ruleList.isEmpty()) {
            Iterator<Rule> ruleIterator = ruleList.iterator();
            while (ruleIterator.hasNext()) {
                Rule rule = ruleIterator.next();
                swrlRules.add(adaptRuleTo(rule, SWRLRule.class));
            }
        }
    } else {
        throw new UnsupportedTypeForExportException("The SPARQL Export Provider does not support the selected serialization : " + type.getCanonicalName());
    }
    return (T) swrlRules;
}
Also used : RuleList(org.apache.stanbol.rules.base.api.util.RuleList) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) Rule(org.apache.stanbol.rules.base.api.Rule) SWRLRule(org.semanticweb.owlapi.model.SWRLRule)

Example 12 with UnsupportedTypeForExportException

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

the class SubtractionAtom method adapt.

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

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

the class SubstringAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
    StringFunctionAtom stringFunctionAtom = tmp.getStringFunctionAtom();
    NumericFunctionAtom startAtom = tmp.getStart();
    NumericFunctionAtom lengthAtom = tmp.getLength();
    try {
        SPARQLObject stringSparqlAtom = adapter.adaptTo(stringFunctionAtom, SPARQLObject.class);
        SPARQLObject startSparqlAtom = adapter.adaptTo(startAtom, SPARQLObject.class);
        SPARQLObject lengthSparqlAtom = adapter.adaptTo(lengthAtom, SPARQLObject.class);
        String uriResourceString = stringSparqlAtom.getObject();
        String start = startSparqlAtom.getObject();
        String length = lengthSparqlAtom.getObject();
        String sparql = "<http://www.w3.org/2005/xpath-functions#substring> (" + uriResourceString + ", " + start + ", " + length + ")";
        return (T) new SPARQLFunction(sparql);
    } 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) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Example 14 with UnsupportedTypeForExportException

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

the class UpperCaseAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    StringFunctionAtom argument = ((org.apache.stanbol.rules.manager.atoms.UpperCaseAtom) ruleAtom).getStringFunctionAtom();
    try {
        SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
        String sparql = "<http://www.w3.org/2005/xpath-functions#upper-case> (" + sparqlArgument.getObject() + ")";
        return (T) new SPARQLFunction(sparql);
    } 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) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Example 15 with UnsupportedTypeForExportException

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

the class RefactorerImpl method graphRefactoring.

@SuppressWarnings("unchecked")
@Override
public Graph graphRefactoring(Graph inputGraph, Recipe recipe) throws RefactoringException {
    RuleAdapter ruleAdapter;
    try {
        ruleAdapter = ruleAdapterManager.getAdapter(recipe, ConstructQuery.class);
        List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe, ConstructQuery.class);
        for (ConstructQuery constructQuery : constructQueries) {
            System.out.println(constructQuery.toString());
        }
        Graph unionGraph = new SimpleGraph();
        for (ConstructQuery constructQuery : constructQueries) {
            unionGraph.addAll(sparqlConstruct(constructQuery, inputGraph));
        }
        return unionGraph;
    } catch (UnavailableRuleObjectException e) {
        throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
    } catch (UnsupportedTypeForExportException e) {
        throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
    } catch (RuleAtomCallExeption e) {
        throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
    }
}
Also used : ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) List(java.util.List) RefactoringException(org.apache.stanbol.rules.refactor.api.RefactoringException) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) RuleAdapter(org.apache.stanbol.rules.base.api.RuleAdapter) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)

Aggregations

UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)29 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)21 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)21 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)11 List (java.util.List)10 Test (org.junit.Test)7 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)6 SPARQLComparison (org.apache.stanbol.rules.adapters.sparql.SPARQLComparison)5 Rule (org.apache.stanbol.rules.base.api.Rule)5 RuleAdapter (org.apache.stanbol.rules.base.api.RuleAdapter)5 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)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 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)3 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)3