Search in sources :

Example 31 with SimpleGraph

use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.

the class ContentItemFactoryTest method testDefaultId.

/**
     * Test the generation of valid IDs if no or <code>null</code> is parsed
     * as id
     */
@Test
public void testDefaultId() throws IOException {
    ContentItem ci = contentItemFactory.createContentItem(TEST_CS);
    assertNotNull(ci);
    assertNotNull(ci.getUri());
    ci = contentItemFactory.createContentItem((IRI) null, TEST_CS);
    assertNotNull(ci);
    assertNotNull(ci.getUri());
    ci = contentItemFactory.createContentItem((IRI) null, TEST_CS, new SimpleGraph());
    assertNotNull(ci);
    assertNotNull(ci.getUri());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) ContentItem(org.apache.stanbol.enhancer.servicesapi.ContentItem) Test(org.junit.Test)

Example 32 with SimpleGraph

use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.

the class AbstractOntologyCollectorImpl method getMergedTc.

private Graph getMergedTc() {
    // Takes less memory than the Indexed one
    Graph result = new SimpleGraph();
    for (OWLOntologyID key : listManagedOntologies()) {
        // TODO when implemented, switch to true.
        Graph managed = getOntology(key, Graph.class, false);
        Set<RDFTerm> exclusions = new HashSet<RDFTerm>();
        Iterator<Triple> it = managed.filter(null, RDF.type, OWL.Ontology);
        while (it.hasNext()) exclusions.add(it.next().getSubject());
        for (Triple t : managed) if (!exclusions.contains(t.getSubject()))
            result.add(t);
    }
    return result;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet)

Example 33 with SimpleGraph

use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.

the class JenaToClerezzaConverter method jenaModelToClerezzaGraph.

/**
	 * 
	 * Converts a Jena {@link Model} to Clerezza {@link Graph}.
	 * 
	 * @param model {@link Model}
	 * @return the equivalent Clerezza {@link Graph}.
	 */
public static org.apache.clerezza.commons.rdf.Graph jenaModelToClerezzaGraph(Model model) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    model.write(out);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    ParsingProvider parser = new JenaParserProvider();
    org.apache.clerezza.commons.rdf.Graph mGraph = new SimpleGraph();
    parser.parse(mGraph, in, SupportedFormat.RDF_XML, null);
    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)

Example 34 with SimpleGraph

use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.

the class IndexedGraphTest method testPerformance.

@Test
public void testPerformance() {
    //Reduced values to fix STANBOL-
    Set<Triple> graph = new HashSet<Triple>();
    //reduced from 1000
    int iterations = 100;
    int graphsize = 100000;
    Long seed = System.currentTimeMillis();
    log.info("Test Seed: {}", seed);
    createGraph(graph, graphsize, seed);
    log.info("Load Time ({} triples)", graph.size());
    long start = System.currentTimeMillis();
    Graph sg = new SimpleGraph(graph);
    log.info("  ... {}: {}", sg.getClass().getSimpleName(), System.currentTimeMillis() - start);
    start = System.currentTimeMillis();
    Graph ig = new IndexedGraph(graph);
    log.info("  ... {}: {}", ig.getClass().getSimpleName(), System.currentTimeMillis() - start);
    //Simple ImmutableGraph reference test
    //reduced form 100,5,100
    TestCase testCase = new TestCase(sg, 20, 5, 20);
    log.info("Filter Performance Test (graph size {} triples, iterations {})", graphsize, iterations);
    log.info(" --- TEST {} with {} triples ---", sg.getClass().getSimpleName(), sg.size());
    start = System.currentTimeMillis();
    List<Long> sgr = executeTest(sg, testCase, iterations);
    log.info(" --- TEST completed in {}ms", System.currentTimeMillis() - start);
    log.info(" --- TEST {} {} triples ---", ig.getClass().getSimpleName(), sg.size());
    start = System.currentTimeMillis();
    List<Long> igr = executeTest(ig, testCase, iterations);
    log.info(" --- TEST completed in {}ms", System.currentTimeMillis() - start);
    //validate filter implementation
    Assert.assertEquals(sgr, igr);
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test) GraphTest(org.apache.clerezza.rdf.core.test.GraphTest)

Example 35 with SimpleGraph

use of org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph in project stanbol by apache.

the class TestHtmlExtractor method testRdfaExtraction.

/**
     * This tests the RDFa extraction.
     *
     * @throws ExtractorException if there is an error during extraction
     * @throws IOException if there is an error when reading the document
     */
@Test
public void testRdfaExtraction() throws Exception {
    HtmlExtractor extractor = new HtmlExtractor(registry, parser);
    Graph model = new SimpleGraph();
    String testFile = "test-rdfa.html";
    // extract text from RDFa annotated html
    InputStream in = getResourceAsStream(testFile);
    assertNotNull("failed to load resource " + testFile, in);
    extractor.extract("file://" + testFile, in, null, "text/html", model);
    // show triples
    int tripleCounter = model.size();
    LOG.debug("RDFa triples: {}", tripleCounter);
    printTriples(model);
    assertEquals(8, tripleCounter);
    ClerezzaRDFUtils.makeConnected(model, new IRI("file://" + testFile), new IRI(NIE_NS + "contains"));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) InputStream(java.io.InputStream) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) HtmlExtractor(org.apache.stanbol.enhancer.engines.htmlextractor.impl.HtmlExtractor) Test(org.junit.Test)

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