use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class TestOWLUtils method namedIRI.
/*
* Extracting the OWL ontology identifier on a *whole* ontology.
*/
@Test
public void namedIRI() throws Exception {
InputStream inputStream = getClass().getResourceAsStream("/owl/maincharacters.owl");
Graph mg = TcManager.getInstance().createGraph(uri);
parser.parse(mg, inputStream, "application/rdf+xml", uri);
assertNotNull(OWLUtils.extractOntologyID(mg.getImmutableGraph()));
}
use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class OWLAPIToClerezzaConverterTest method testOWLOntologyToGraph.
@Test
public void testOWLOntologyToGraph() {
/*
* Transform the OWLOntology into a Clerezza Graph.
*/
Graph mGraph = OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(ontology);
/*
* Print all the triples contained in the Clerezza Graph.
*/
Iterator<Triple> tripleIt = mGraph.iterator();
while (tripleIt.hasNext()) {
Triple triple = tripleIt.next();
log.info(triple.toString());
}
}
use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class EnhancementEngineHelper method getChainExecutionProperties.
/**
* Getter for the {@link Chain} scoped (chain and chain-engine scoped) properties
* for the parsed enhancement engine and content item.
* @param engine the enhancement engine
* @param ci the content item
* @return the chain scoped enhancement properties. This will not include any
* request scoped properties.
* @since 0.12.1 (<a href="https://issues.apache.org/jira/browse/STANBOL-1361">STANBOL-1361</a>)
*/
public static Map<String, Object> getChainExecutionProperties(EnhancementEngine engine, ContentItem ci) {
if (engine == null) {
throw new IllegalArgumentException("The parsed EnhancementEngine MUST NOT be NULL");
}
if (ci == null) {
throw new IllegalArgumentException("The parsed ContentItem MUST NOT be NULL");
}
Map<String, Object> chainExProps = new HashMap<String, Object>();
Map<String, Object> engineExProps = new HashMap<String, Object>();
ci.getLock().readLock().lock();
try {
Graph em = ExecutionMetadataHelper.getExecutionMetadata(ci);
//(1.a) retrieve EnhancementProperties from the ep:ExecutionPlan
log.debug("> extract EnhancementProperties form the ExecutionPlan");
BlankNodeOrIRI executionPlanNode = ExecutionMetadataHelper.getExecutionPlanNode(em, ExecutionMetadataHelper.getChainExecution(em, ci.getUri()));
extractEnhancementProperties(chainExProps, em, executionPlanNode, "Chain Execution");
//(1.b) retrieve Enhancement Properties from the ep:ExectutionNode
// for the parsed EnhancementEngine
log.debug("> extract EnhancementProperties form the ExecutionNode of Engine {}", engine.getName());
Iterator<Triple> engineExecutions = em.filter(null, ExecutionPlan.ENGINE, new PlainLiteralImpl(engine.getName()));
// there are multiple we will merge the properties of those
while (engineExecutions.hasNext()) {
BlankNodeOrIRI engineExecution = engineExecutions.next().getSubject();
if (em.contains(new TripleImpl(executionPlanNode, ExecutionPlan.HAS_EXECUTION_NODE, engineExecution))) {
extractEnhancementProperties(engineExProps, em, engineExecution, "Engine Execution");
}
//else engine execution of a different execution plan
}
} catch (NoSuchPartException e) {
//no execution metadata are present
log.debug(" - no ExecutionMetadata are present ...");
} finally {
ci.getLock().readLock().unlock();
}
//finally merge the chain-engine scoped properties into the chain scoped properties
chainExProps.putAll(engineExProps);
return chainExProps;
}
use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class RdfEntityFactoryTest method testInterfaceHierarchies.
@Test
public void testInterfaceHierarchies() throws Exception {
Graph graph = new SimpleGraph();
RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
String testUri = "urn:RdfEntityFactoryTest:SubTestEntity";
String testUri2 = "urn:RdfEntityFactoryTest:TestEntity2";
String testUri3 = "urn:RdfEntityFactoryTest:TestEntity";
IRI node = new IRI(testUri);
IRI node2 = new IRI(testUri2);
IRI node3 = new IRI(testUri3);
SubTestRdfEntity entity = factory.getProxy(node, SubTestRdfEntity.class);
TestRdfEntity entity2 = factory.getProxy(node2, TestRdfEntity.class, SubTestRdfEntity.class, TestRdfEntity2.class);
TestRdfEntity entity3 = factory.getProxy(node3, TestRdfEntity.class);
//Start with checking the types for entity2
//first type cast to the hierarchy
assertTrue(entity instanceof TestRdfEntity);
assertTrue(entity instanceof RdfEntity);
// test if the rdf:type triples are present in the Graph
Set<String> typeStrings = getRdfTypes(graph, node);
assertTrue(typeStrings.contains(SubTestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));
typeStrings = null;
//now the same for entity2
//first type cast to the hierarchy
assertTrue(entity2 instanceof SubTestRdfEntity);
assertTrue(entity2 instanceof TestRdfEntity2);
assertTrue(entity2 instanceof RdfEntity);
// test if the rdf:type triples are present in the Graph
typeStrings = getRdfTypes(graph, node2);
assertTrue(typeStrings.contains(SubTestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity2.class.getAnnotation(Rdf.class).id()));
typeStrings = null;
//Now check Entity3
assertTrue(!(entity3 instanceof SubTestRdfEntity));
assertTrue(entity3 instanceof TestRdfEntity);
//Now create an new Entity for the same Node that implements SubEntity2
SubTestRdfEntity entity4 = factory.getProxy(node3, SubTestRdfEntity.class);
//check if entity4 implements SubTestRefEntity
assertTrue(entity4 instanceof SubTestRdfEntity);
//now check if the additional type was added to node3
typeStrings = getRdfTypes(graph, node3);
assertTrue(typeStrings.contains(SubTestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));
//and that entity3 still dose not implement SubTestEntity
// ... because adding/removing rdf:type triples in the graph can not affect existing proxy instances!
assertTrue(!(entity3 instanceof SubTestRdfEntity));
}
use of org.apache.clerezza.commons.rdf.Graph in project stanbol by apache.
the class RdfEntityFactoryTest method testObjectProperties.
@Test
public void testObjectProperties() throws Exception {
Graph graph = new SimpleGraph();
RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
String testUri = "urn:RdfEntityFactoryTest:TestEntity";
String testUri2 = "urn:RdfEntityFactoryTest:TestEntity2";
IRI node = new IRI(testUri);
IRI node2 = new IRI(testUri2);
TestRdfEntity entity = factory.getProxy(node, TestRdfEntity.class);
TestRdfEntity2 entity2 = factory.getProxy(node2, TestRdfEntity2.class);
URI testURI = new URI("urn:test:URI");
entity.setURI(testURI);
assertEquals(testURI, entity.getURI());
URL testURL = new URL("http://www.iks-project.eu");
entity.setURL(testURL);
assertEquals(testURL, entity.getURL());
entity.setIRI(node2);
assertEquals(node2, entity.getIRI());
entity2.setTestEntity(entity);
assertEquals(entity, entity2.getTestEntity());
Collection<TestRdfEntity> testEntities = entity2.getTestEntities();
//check that entity is not in the collection
assertTrue(testEntities.isEmpty());
Set<IRI> testIRIs = new HashSet<IRI>();
int NUM = 10;
for (int i = 0; i < NUM; i++) {
IRI testNode = new IRI(testUri + ':' + '_' + i);
testIRIs.add(testNode);
testEntities.add(factory.getProxy(testNode, TestRdfEntity.class));
}
//now get a new collection and test if the added entities are there
//add to a list to check for duplicates
Collection<IRI> resultIRIs = new ArrayList<IRI>();
for (TestRdfEntity e : entity2.getTestEntities()) {
//I used IRIs for the generation ...
assertTrue(e.getId() instanceof IRI);
resultIRIs.add((IRI) e.getId());
}
//now cross check
assertTrue(testIRIs.containsAll(resultIRIs));
assertTrue(resultIRIs.containsAll(testIRIs));
//now one could try to remove some Elements ...
// ... but things like that are already tested for Integers in testPrimitiveDataTypes
}
Aggregations