Search in sources :

Example 1 with ConstructQuery

use of org.apache.clerezza.rdf.core.sparql.query.ConstructQuery in project stanbol by apache.

the class ClerezzaAdapter method adaptRecipeTo.

@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    List<ConstructQuery> constructQueries = null;
    if (type == ConstructQuery.class) {
        constructQueries = new ArrayList<ConstructQuery>();
        RuleList ruleList = recipe.getRuleList();
        Iterator<Rule> ruleIterator = ruleList.iterator();
        for (int i = 0; ruleIterator.hasNext(); i++) {
            constructQueries.add((ConstructQuery) adaptRuleTo(ruleIterator.next(), type));
        }
    } else {
        throw new UnsupportedTypeForExportException("The adapter for Clerezza does not support the selected serialization : " + type.getCanonicalName());
    }
    return (T) constructQueries;
}
Also used : RuleList(org.apache.stanbol.rules.base.api.util.RuleList) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) Rule(org.apache.stanbol.rules.base.api.Rule) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) SimpleConstructQuery(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleConstructQuery)

Example 2 with ConstructQuery

use of org.apache.clerezza.rdf.core.sparql.query.ConstructQuery 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 3 with ConstructQuery

use of org.apache.clerezza.rdf.core.sparql.query.ConstructQuery 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)

Example 4 with ConstructQuery

use of org.apache.clerezza.rdf.core.sparql.query.ConstructQuery in project stanbol by apache.

the class RefactorerImpl method graphRefactoring.

@SuppressWarnings("unchecked")
@Override
public void graphRefactoring(IRI refactoredOntologyID, IRI datasetID, IRI recipeID) throws RefactoringException, NoSuchRecipeException {
    Recipe recipe;
    try {
        try {
            recipe = ruleStore.getRecipe(recipeID);
            RuleAdapter ruleAdapter = ruleAdapterManager.getAdapter(recipe, ConstructQuery.class);
            List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe, ConstructQuery.class);
            Graph mGraph = tcManager.createGraph(refactoredOntologyID);
            for (ConstructQuery constructQuery : constructQueries) {
                mGraph.addAll(this.sparqlConstruct(constructQuery, datasetID));
            }
        } catch (RecipeConstructionException e) {
            throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
        } 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);
        }
    } catch (NoSuchRecipeException e1) {
        log.error("No Such recipe in the Rule Store", e1);
        throw e1;
    }
}
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) Recipe(org.apache.stanbol.rules.base.api.Recipe) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) 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) RecipeConstructionException(org.apache.stanbol.rules.base.api.RecipeConstructionException) RuleAdapter(org.apache.stanbol.rules.base.api.RuleAdapter) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)

Example 5 with ConstructQuery

use of org.apache.clerezza.rdf.core.sparql.query.ConstructQuery in project stanbol by apache.

the class ClerezzaAdapter method main.

public static void main(String[] args) {
    RuleAdapter ruleAdapter = new ClerezzaAdapter();
    try {
        KB kb = RuleParserImpl.parse("http://sssw.org/2012/rules/", new FileInputStream("/Users/mac/Documents/CNR/SSSW2012/construct/exercise3"));
        System.out.println("Rules: " + kb.getRuleList().size());
        Recipe recipe = new RecipeImpl(new IRI("http://sssw.org/2012/rules/"), "Recipe", kb.getRuleList());
        //List<ConstructQuery> jenaRules = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe, ConstructQuery.class);
        String rules = "[ Exercise1: (http://dbpedia.org/resource/Madrid http://dbpedia.org/ontology/locationOf ?location) (?location rdf:type http://dbpedia.org/ontology/Museum) (?location http://dbpedia.org/ontology/numberOfVisitors ?visitors) greaterThan(?visitors '2000000'^^http://www.w3.org/2001/XMLSchema#integer) -> (?location rdf:type http://www.mytravels.com/Itinerary/MadridItinerary) ]";
        //List<com.hp.hpl.jena.reasoner.rulesys.Rule> jenaRules = com.hp.hpl.jena.reasoner.rulesys.Rule.parseRules(rules);
        String spqral = "CONSTRUCT " + "{ ?city a <http://www.mytravels.com/Itinerary/MovieCityItinerary> . " + "   ?city <http://www.w3.org/2000/01/rdf-schema#label> ?cLabel . " + "   ?event a <http://linkedevents.org/ontology/Event> . " + "   ?event <http://linkedevents.org/ontology/atPlace> ?location . " + "   ?location <http://www.w3.org/2000/01/rdf-schema#label> ?lLabel . " + "   ?location <http://www.w3.org/2002/07/owl#sameAs> ?city" + "} " + "WHERE " + "{ " + "   ?city a <http://www.mytravels.com/Itinerary/MovieCityItinerary> . " + "   ?city <http://www.w3.org/2000/01/rdf-schema#label> ?cLabel . " + "   ?event a <http://linkedevents.org/ontology/Event> . " + "   ?event <http://linkedevents.org/ontology/atPlace> ?location . " + "   ?location <http://www.w3.org/2000/01/rdf-schema#label> ?lLabel . " + "   FILTER(?lLabel = ?cLabel) " + "}";
        Model m = ModelFactory.createDefaultModel();
        Model model = FileManager.get().loadModel("/Users/mac/Documents/CNR/SSSW2012/datasets_new/Exercise5_tmp.rdf");
        //for(ConstructQuery constructQuery : jenaRules){
        //Query query = QueryFactory.create(constructQuery.toString(), Syntax.syntaxARQ);
        Query query = QueryFactory.create(spqral, Syntax.syntaxARQ);
        QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
        //System.out.println(constructQuery.toString());
        m.add(queryExecution.execConstruct());
        //}
        FileOutputStream max = new FileOutputStream("/Users/mac/Documents/CNR/SSSW2012/datasets_new/example5.rdf");
        m.write(max);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
/*catch (RuleAtomCallExeption e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnavailableRuleObjectException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnsupportedTypeForExportException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }*/
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Query(com.hp.hpl.jena.query.Query) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) SimpleConstructQuery(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleConstructQuery) Recipe(org.apache.stanbol.rules.base.api.Recipe) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) QueryExecution(com.hp.hpl.jena.query.QueryExecution) KB(org.apache.stanbol.rules.manager.KB) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) FileOutputStream(java.io.FileOutputStream) Model(com.hp.hpl.jena.rdf.model.Model) RuleAdapter(org.apache.stanbol.rules.base.api.RuleAdapter) AbstractRuleAdapter(org.apache.stanbol.rules.adapters.AbstractRuleAdapter)

Aggregations

ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)7 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)6 List (java.util.List)5 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)5 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)5 RuleAdapter (org.apache.stanbol.rules.base.api.RuleAdapter)3 Test (org.junit.Test)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 SimpleConstructQuery (org.apache.clerezza.rdf.core.sparql.query.impl.SimpleConstructQuery)2 Recipe (org.apache.stanbol.rules.base.api.Recipe)2 RefactoringException (org.apache.stanbol.rules.refactor.api.RefactoringException)2 Query (com.hp.hpl.jena.query.Query)1 QueryExecution (com.hp.hpl.jena.query.QueryExecution)1 Model (com.hp.hpl.jena.rdf.model.Model)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IRI (org.apache.clerezza.commons.rdf.IRI)1