Search in sources :

Example 16 with SimpleGraph

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
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ArrayList(java.util.ArrayList) URI(java.net.URI) URL(java.net.URL) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) RdfEntityFactory(org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with SimpleGraph

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()));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) RdfEntityFactory(org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory) Rdf(org.apache.stanbol.enhancer.rdfentities.Rdf) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Test(org.junit.Test)

Example 18 with SimpleGraph

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));
}
Also used : SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 19 with SimpleGraph

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;
}
Also used : JenaParserProvider(org.apache.clerezza.rdf.jena.parser.JenaParserProvider) ParsingProvider(org.apache.clerezza.rdf.core.serializedform.ParsingProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) RDFXMLOntologyFormat(org.semanticweb.owlapi.io.RDFXMLOntologyFormat) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 20 with SimpleGraph

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);
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) Resource(com.hp.hpl.jena.rdf.model.Resource) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) Property(com.hp.hpl.jena.rdf.model.Property) BeforeClass(org.junit.BeforeClass)

Aggregations

SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)46 Graph (org.apache.clerezza.commons.rdf.Graph)34 IRI (org.apache.clerezza.commons.rdf.IRI)24 Test (org.junit.Test)17 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)15 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)12 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)11 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)10 Triple (org.apache.clerezza.commons.rdf.Triple)10 HashSet (java.util.HashSet)9 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InputStream (java.io.InputStream)5 HtmlExtractor (org.apache.stanbol.enhancer.engines.htmlextractor.impl.HtmlExtractor)5 RdfEntityFactory (org.apache.stanbol.enhancer.rdfentities.RdfEntityFactory)5 BlankNode (org.apache.clerezza.commons.rdf.BlankNode)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 JenaParserProvider (org.apache.clerezza.rdf.jena.parser.JenaParserProvider)3