use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph 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
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class RdfEntityFactoryTest method testTypeStatements.
@Test
public void testTypeStatements() throws Exception {
Graph graph = new SimpleGraph();
RdfEntityFactory factory = RdfEntityFactory.createInstance(graph);
String testUri = "urn:RdfEntityFactoryTest:TestEntity";
IRI node = new IRI(testUri);
TestRdfEntity entity = factory.getProxy(node, TestRdfEntity.class, new Class[] { TestRdfEntity2.class });
// test the if the proxy implements both interfaces
assertTrue(entity instanceof TestRdfEntity);
assertTrue(entity instanceof TestRdfEntity2);
Set<String> typeStrings = getRdfTypes(graph, node);
assertTrue(typeStrings.contains(TestRdfEntity.class.getAnnotation(Rdf.class).id()));
assertTrue(typeStrings.contains(TestRdfEntity2.class.getAnnotation(Rdf.class).id()));
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class ContentItemFactoryTest method testURI.
/**
* Test that the parsed URI is used as ID of the ContentItem
*/
@Test
public void testURI() throws IOException {
ContentItem ci = contentItemFactory.createContentItem(ID, TEST_CS);
assertNotNull(ci);
assertNotNull(ci.getUri());
assertTrue("The ID of the created ContentItem MUST be equals to the parsed ID", ci.getUri().equals(ID));
ci = contentItemFactory.createContentItem(ID, TEST_CS, new SimpleGraph());
assertNotNull(ci);
assertNotNull(ci.getUri());
assertTrue("The ID of the created ContentItem MUST be equals to the parsed ID", ci.getUri().equals(ID));
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class OWLAPIToClerezzaConverter method owlOntologyToClerezzaGraph.
/**
*
* Converts a OWL API {@link OWLOntology} to Clerezza {@link Graph}.
*
* @param ontology
* {@link OWLOntology}
* @return the equivalent Clerezza {@link Graph}.
*/
public static org.apache.clerezza.commons.rdf.Graph owlOntologyToClerezzaGraph(OWLOntology ontology) {
org.apache.clerezza.commons.rdf.Graph mGraph = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
OWLOntologyManager manager = ontology.getOWLOntologyManager();
try {
manager.saveOntology(ontology, new RDFXMLOntologyFormat(), out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ParsingProvider parser = new JenaParserProvider();
mGraph = new SimpleGraph();
parser.parse(mGraph, in, SupportedFormat.RDF_XML, null);
} catch (OWLOntologyStorageException e) {
log.error("Failed to serialize OWL Ontology " + ontology + "for conversion", e);
}
return mGraph;
}
use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.
the class JenaToClerezzaConverterTest method setupClass.
@BeforeClass
public static void setupClass() {
/*
* Set-up the Jena model for the test.
* Simply add the triples:
* AndreaNuzzolese isA Person
* EnricoDaga isA Person
* AndreaNuzzolese knows EnricoDaga
*/
model = ModelFactory.createDefaultModel();
Resource foafPersonInJena = model.createResource(foaf + "Person");
Property knowsInJena = model.createProperty(foaf + "knows");
Resource andreaNuzzoleseInJena = model.createResource(ns + "AndreaNuzzolese", foafPersonInJena);
Resource enricoDagaInJena = model.createResource(ns + "EnricoDaga", foafPersonInJena);
andreaNuzzoleseInJena.addProperty(knowsInJena, enricoDagaInJena);
/*
* Set-up the Clerezza model for the test.
* As before simply add the triples:
* AndreaNuzzolese isA Person
* EnricoDaga isA Person
* AndreaNuzzolese knows EnricoDaga
*/
mGraph = new SimpleGraph();
IRI knowsInClerezza = new IRI(ns + "knows");
IRI rdfType = new IRI(RDF.getURI() + "type");
IRI foafPersonInClerezza = new IRI(foaf + "Person");
BlankNodeOrIRI andreaNuzzoleseInClerezza = new IRI(ns + "AndreaNuzzolese");
BlankNodeOrIRI enricoDagaInClerezza = new IRI(ns + "EnricoDaga");
Triple triple = new TripleImpl(andreaNuzzoleseInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(enricoDagaInClerezza, rdfType, foafPersonInClerezza);
mGraph.add(triple);
triple = new TripleImpl(andreaNuzzoleseInClerezza, knowsInClerezza, enricoDagaInClerezza);
mGraph.add(triple);
}
Aggregations