Search in sources :

Example 36 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 37 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)

Example 38 with SimpleGraph

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

the class OWLAPIToClerezzaConverterTest method setupClass.

@BeforeClass
public static void setupClass() {
    /*
         * Set-up the OWL ontology for the test. Simply add the axioms: AndreaNuzzolese isA Person -> class
         * assertion axiom EnricoDaga isA Person -> class assertion axiom AndreaNuzzolese knows EnricoDaga ->
         * object property assertion axiom
         */
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLDataFactory factory = manager.getOWLDataFactory();
    try {
        ontology = manager.createOntology(org.semanticweb.owlapi.model.IRI.create(ns + "testOntology"));
    } catch (OWLOntologyCreationException e) {
        log.error(e.getMessage());
    }
    if (ontology != null) {
        OWLClass personClass = factory.getOWLClass(org.semanticweb.owlapi.model.IRI.create(foaf + "Person"));
        OWLNamedIndividual andreaNuzzoleseOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "AndreaNuzzolese"));
        OWLNamedIndividual enricoDagaOWL = factory.getOWLNamedIndividual(org.semanticweb.owlapi.model.IRI.create(ns + "EnricoDaga"));
        OWLObjectProperty knowsOWL = factory.getOWLObjectProperty(org.semanticweb.owlapi.model.IRI.create(foaf + "knows"));
        OWLAxiom axiom = factory.getOWLClassAssertionAxiom(personClass, andreaNuzzoleseOWL);
        manager.addAxiom(ontology, axiom);
        axiom = factory.getOWLClassAssertionAxiom(personClass, enricoDagaOWL);
        manager.addAxiom(ontology, axiom);
        axiom = factory.getOWLObjectPropertyAssertionAxiom(knowsOWL, andreaNuzzoleseOWL, enricoDagaOWL);
        manager.addAxiom(ontology, axiom);
    }
    /*
         * 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) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) BeforeClass(org.junit.BeforeClass)

Example 39 with SimpleGraph

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

the class UserResource method getUserRolesGraph.

/**
     * Provides a graph containing Role triples associated with a given user
     *
     * @param userName
     * @return roles graph
     */
private Graph getUserRolesGraph(String userName) {
    GraphNode userNode = getUser(userName);
    Iterator<RDFTerm> functionIterator = userNode.getObjects(SIOC.has_function);
    SimpleGraph rolesGraph = new SimpleGraph();
    while (functionIterator.hasNext()) {
        GraphNode functionNode = new GraphNode(functionIterator.next(), systemGraph);
        Iterator<Triple> roleIterator = systemGraph.filter((BlankNodeOrIRI) functionNode.getNode(), RDF.type, PERMISSION.Role);
        // needs lock?
        while (roleIterator.hasNext()) {
            Triple roleTriple = roleIterator.next();
            // rolesGraph.add(roleTriple);
            BlankNodeOrIRI roleNode = roleTriple.getSubject();
            SimpleGraph detailsGraph = new SimpleGraph(systemGraph.filter(roleNode, null, null));
            rolesGraph.addAll(detailsGraph);
        }
    }
    return rolesGraph;
}
Also used : Triple(org.apache.clerezza.commons.rdf.Triple) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm)

Example 40 with SimpleGraph

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

the class OpenCalaisEngine method readModel.

/**
     * Parses an InputStream of RDF data and produces an Graph from them
     *
     * @param in The InputStream of RDF data
     * @param format the format of the RDF data
     *
     * @return the resulting Graph or null if the RDF serialization format is not supported by the parser
     */
public Graph readModel(InputStream in, String format) {
    Parser parser = Parser.getInstance();
    if (parser.getSupportedFormats().contains(format)) {
        ImmutableGraph graph = parser.parse(in, format);
        Graph model = new SimpleGraph(graph);
        return model;
    } else {
        log.warn("Unsupported RDF format: {}\nSupported RDF formats: {}", format, parser.getSupportedFormats());
    }
    return null;
}
Also used : ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) 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) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) QueryParser(org.apache.clerezza.rdf.core.sparql.QueryParser) Parser(org.apache.clerezza.rdf.core.serializedform.Parser)

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