Search in sources :

Example 21 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class ClerezzaYard method remove.

@Override
public void remove(String id) throws YardException, IllegalArgumentException {
    if (id == null) {
        throw new IllegalArgumentException("The parsed Representation id MUST NOT be NULL!");
    }
    IRI resource = new IRI(id);
    final Lock writeLock = writeLockGraph();
    try {
        Iterator<Triple> it = graph.filter(resource, null, null);
        while (it.hasNext()) {
            it.next();
            it.remove();
        }
    // if(isRepresentation(resource)){
    // graph.removeAll(createRepresentationGraph(resource, graph));
    // } //else not found  -> nothing to do
    } finally {
        writeLock.unlock();
    }
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Lock(java.util.concurrent.locks.Lock)

Example 22 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class RdfResultListTest method testRdfResultSorting.

/**
 * Providing a sorted Iteration over query results stored in an RDF
 * graph is not something trivial. Therefore this test
 */
@Test
public void testRdfResultSorting() {
    SortedMap<Double, RdfRepresentation> sorted = new TreeMap<Double, RdfRepresentation>();
    Graph resultGraph = new IndexedGraph();
    RdfValueFactory vf = new RdfValueFactory(resultGraph);
    IRI resultListNode = new IRI(RdfResourceEnum.QueryResultSet.getUri());
    IRI resultProperty = new IRI(RdfResourceEnum.queryResult.getUri());
    for (int i = 0; i < 100; i++) {
        Double rank;
        do {
            // avoid duplicate keys
            rank = Math.random();
        } while (sorted.containsKey(rank));
        RdfRepresentation r = vf.createRepresentation("urn:sortTest:rep." + i);
        // link the representation with the query result set
        resultGraph.add(new TripleImpl(resultListNode, resultProperty, r.getNode()));
        r.set(RdfResourceEnum.resultScore.getUri(), rank);
        sorted.put(rank, r);
    }
    RdfQueryResultList resultList = new RdfQueryResultList(new FieldQueryImpl(), resultGraph);
    if (log.isDebugEnabled()) {
        log.debug("---DEBUG Sorting ---");
        for (Iterator<Representation> it = resultList.iterator(); it.hasNext(); ) {
            Representation r = it.next();
            log.debug("{}: {}", r.getFirst(RdfResourceEnum.resultScore.getUri()), r.getId());
        }
    }
    log.debug("---ASSERT Sorting ---");
    for (Iterator<Representation> it = resultList.iterator(); it.hasNext(); ) {
        Representation r = it.next();
        Double lastkey = sorted.lastKey();
        Representation last = sorted.get(lastkey);
        Assert.assertEquals("score: " + r.getFirst(RdfResourceEnum.resultScore.getUri()) + " of Representation " + r.getId() + " is not as expected " + last.getFirst(RdfResourceEnum.resultScore.getUri()) + " of Representation " + last.getId() + "!", r, last);
        sorted.remove(lastkey);
    }
    Assert.assertTrue(sorted.isEmpty());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) TreeMap(java.util.TreeMap) FieldQueryImpl(org.apache.stanbol.entityhub.core.query.FieldQueryImpl) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) RdfValueFactory(org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory) Test(org.junit.Test)

Example 23 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class RdfValueFactoryTest method testNullGraphRepresentation.

@Test(expected = IllegalArgumentException.class)
public void testNullGraphRepresentation() {
    IRI rootNode = new IRI("urn:test.rootNode");
    valueFactory.createRdfRepresentation(rootNode, null);
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Test(org.junit.Test) ValueFactoryTest(org.apache.stanbol.entityhub.test.model.ValueFactoryTest)

Example 24 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class SWRLAdpterTest method setUp.

@Before
public void setUp() {
    String separator = System.getProperty("line.separator");
    String recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . values(kres:age, ?x, ?age) . gt(?age, sum(sub(70, ?k), ?z)) -> is(kres:OldPerson, ?x)]";
    KB kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeGood = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
    recipeString = "kres = <http://kres.iks-project.eu/ontology.owl#> . " + separator + "foaf = <http://xmlns.com/foaf/0.1/> . " + separator + "rule1[ is(kres:Person, ?x) . has(kres:friend, ?x, ?y) -> is(foaf:Person, ?x) . has(foaf:knows, ?x, ?y) . is(foaf:Person, ?y)] . " + "rule2[ is(kres:Person, ?x) . same(\"Andrea\", localname(?x)) -> is(kres:OldPerson, ?x)]";
    kb = RuleParserImpl.parse("http://incubator.apache.com/stanbol/rules/adapters/jena/test/", recipeString);
    recipeWrong = new RecipeImpl(new IRI("http://incubator.apache.com/stanbol/rules/adapters/jena/test"), "A recipe.", kb.getRuleList());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) KB(org.apache.stanbol.rules.manager.KB) RecipeImpl(org.apache.stanbol.rules.manager.RecipeImpl) Before(org.junit.Before)

Example 25 with IRI

use of org.apache.clerezza.commons.rdf.IRI in project stanbol by apache.

the class ClerezzaRuleStore method addRulesToRecipe.

/**
 * Parse the set of rules provided by the rulesStream parameter as Stanbol syntax rules and add them to
 * the Recipe in the store.<br/>
 * The recipe is a {@link Graph} managed by the {@link TcManager}.
 *
 * @param recipe
 *            {@link Recipe} the recipe
 * @param rulesStream
 *            {@link InputStream} the rule in Stanbol syntax
 *
 * @return the recipe with the new rule.
 */
@Override
public Recipe addRulesToRecipe(Recipe recipe, InputStream rulesStream, String description) {
    log.debug("Adding rule to recipe " + recipe);
    IRI recipeID = recipe.getRecipeID();
    String namespace = recipeID.toString().substring(1, recipeID.toString().length() - 1) + "/";
    log.info("Rule Namespace is " + namespace);
    RuleList ruleList = RuleParserImpl.parse(namespace, rulesStream).getRuleList();
    for (Rule rule : ruleList) {
        recipe = addRuleToRecipe(recipe, rule, description);
    }
    return recipe;
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RuleList(org.apache.stanbol.rules.base.api.util.RuleList) Rule(org.apache.stanbol.rules.base.api.Rule)

Aggregations

IRI (org.apache.clerezza.commons.rdf.IRI)346 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)113 Graph (org.apache.clerezza.commons.rdf.Graph)109 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)104 Triple (org.apache.clerezza.commons.rdf.Triple)88 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)84 Test (org.junit.Test)78 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)58 HashSet (java.util.HashSet)50 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)46 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)37 ArrayList (java.util.ArrayList)37 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)36 Literal (org.apache.clerezza.commons.rdf.Literal)35 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)31 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)29 Recipe (org.apache.stanbol.rules.base.api.Recipe)29 Language (org.apache.clerezza.commons.rdf.Language)24