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();
}
}
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());
}
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);
}
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());
}
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;
}
Aggregations