Search in sources :

Example 1 with JenaParserProvider

use of org.apache.clerezza.rdf.jena.parser.JenaParserProvider in project stanbol by apache.

the class ClerezzaBackendTest method readTestData.

@BeforeClass
public static void readTestData() throws IOException {
    ParsingProvider parser = new JenaParserProvider();
    //NOTE(rw): the new third parameter is the base URI used to resolve relative paths
    graph = new IndexedGraph();
    InputStream in = ClerezzaBackendTest.class.getClassLoader().getResourceAsStream("testdata.rdf.zip");
    assertNotNull(in);
    ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(in));
    InputStream uncloseable = new UncloseableStream(zipIn);
    ZipEntry entry;
    while ((entry = zipIn.getNextEntry()) != null) {
        if (entry.getName().endsWith(".rdf")) {
            parser.parse(graph, uncloseable, SupportedFormat.RDF_XML, null);
        }
    }
    assertTrue(graph.size() > 0);
    zipIn.close();
}
Also used : JenaParserProvider(org.apache.clerezza.rdf.jena.parser.JenaParserProvider) ParsingProvider(org.apache.clerezza.rdf.core.serializedform.ParsingProvider) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FilterInputStream(java.io.FilterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) BeforeClass(org.junit.BeforeClass)

Example 2 with JenaParserProvider

use of org.apache.clerezza.rdf.jena.parser.JenaParserProvider in project stanbol by apache.

the class ZemantaAPIWrapper method parseResponse.

private ImmutableGraph parseResponse(InputStream is) {
    JenaParserProvider jenaParserProvider = new JenaParserProvider();
    //NOTE(rw): the new third parameter is the base URI used to resolve relative paths
    Graph g = new SimpleGraph();
    jenaParserProvider.parse(g, is, SupportedFormat.RDF_XML, null);
    log.debug("graph: " + g.toString());
    return g.getImmutableGraph();
}
Also used : JenaParserProvider(org.apache.clerezza.rdf.jena.parser.JenaParserProvider) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) Graph(org.apache.clerezza.commons.rdf.Graph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)

Example 3 with JenaParserProvider

use of org.apache.clerezza.rdf.jena.parser.JenaParserProvider in project stanbol by apache.

the class TopicEngineTest method testImportModelFromSKOS.

@Test
public void testImportModelFromSKOS() throws Exception {
    log.info(" --- testImportModelFromSKOS --- ");
    Parser parser = Parser.getInstance();
    parser.bindParsingProvider(new JenaParserProvider());
    ImmutableGraph graph = parser.parse(getClass().getResourceAsStream("/sample-scheme.skos.rdf.xml"), SupportedFormat.RDF_XML);
    int imported = classifier.importConceptsFromGraph(graph, OntologicalClasses.SKOS_CONCEPT, Properties.SKOS_BROADER);
    assertEquals(imported, 4);
    assertEquals(0, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/100").size());
    assertEquals(0, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/200").size());
    assertEquals(1, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/010").size());
    assertEquals(1, classifier.getBroaderConcepts("http://example.com/ns#someconceptscheme/020").size());
    assertEquals(2, classifier.getRootConcepts().size());
}
Also used : JenaParserProvider(org.apache.clerezza.rdf.jena.parser.JenaParserProvider) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) Parser(org.apache.clerezza.rdf.core.serializedform.Parser) Test(org.junit.Test)

Example 4 with JenaParserProvider

use of org.apache.clerezza.rdf.jena.parser.JenaParserProvider 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 5 with JenaParserProvider

use of org.apache.clerezza.rdf.jena.parser.JenaParserProvider 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)

Aggregations

JenaParserProvider (org.apache.clerezza.rdf.jena.parser.JenaParserProvider)7 ParsingProvider (org.apache.clerezza.rdf.core.serializedform.ParsingProvider)5 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Graph (org.apache.clerezza.commons.rdf.Graph)3 BeforeClass (org.junit.BeforeClass)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FilterInputStream (java.io.FilterInputStream)2 ZipInputStream (java.util.zip.ZipInputStream)2 IRI (org.apache.clerezza.commons.rdf.IRI)2 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)2 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)2 Triple (org.apache.clerezza.commons.rdf.Triple)2 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)2 ByteArraySource (org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource)2 ZipEntry (java.util.zip.ZipEntry)1 Parser (org.apache.clerezza.rdf.core.serializedform.Parser)1 Test (org.junit.Test)1