Git Product home page Git Product logo

neo4jena's Introduction

Neo4Jena

Overview

For the integration of Jena and neo4j we have implemented Jena graph interfaces using neo4j native API. Neo4Jena is a property graph model interface. It provides the mapping of RDF to property graph (Neo4J) using Jena API. The main work focuses on how RDF triple is converted to Neo4j graph and vice versa. After the successful loading of RDF in graph we retrieve the data using SPARQL. We made the following contributions:

  • Firstly RDF triples (subject, predicate and object) are converted to Neo4j node and relationship.
  • After the conversion, it store triples in Neo4j graph.
  • After the successful loading of RDF triples in graph Neo4Jena retrieve the data using SPARQL. For this neo4j nodes and relationship is converted to RDF triples (subject, predicate and object).
  • Neo4Jena has full support of SPARQL 1.1.

Mapping RDF to Neo4j

RDF triple consist of subject, predicate and object.

  • Subjects in rdf triples are URIs or blank nodes.
  • All predicates are URIs.
  • Objects can be URIs, blank nodes or literal values.

When mapping RDF to Neo4j following points are taken in considertaion:

  • Each neo4j node has a label that is either uri , literal or bnode.
  • Nodes having label uri or bnode have one property
    • uri
  • Nodes having label literal have three properties
    • value
    • datatype
    • lang

Follwing figure demostrats how uri and literals are modeled in Neo4j.

alt tag

Example: RDF Statement

The following RDF statment is taken from RDF primer. This RDF statement have:

alt tag

The subject and object are resources so while mapping them neo4j node has label uri.The following figure shows how this statement is represented in Neo4j. (In mapping prefixes are used)

alt tag

Example: RDF Statement with Literal

This RDF statement has:

alt tag

The subject is a resource so while mapping them neo4j node has label uri.Literal values can have their datatype and language as well.

alt tag

Example: Multiple Statemnets including Literal values

Following figure have multiple statements about the same subject. The object can be a URI or literal value.

alt tag

Subjects and objects when mapped in neo4j node have label uri while literal values have label literal. The properties of uri and literals are different. !https://github.com/semr/neo4jena/raw/master/doc/image/example2.PNG!

Example: Statement with Blank node

Subject and object can also be a blank node (a resource having no URI)

alt tag

While mapping blank node the neo4j node has label bnode.

!(alt tag

How to use Neo4Jena?

Create a Jena model and read RDF file/triples in it.

Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open( inputFileName );
model.read(in,"","TTL"); 

For initialization of NeoGraph there are two constructors.

  • public NeoGraph(final String directory)
  • public NeoGraph(final GraphDatabaseService graphdb)
GraphDatabaseService njgraph = new GraphDatabaseFactory().newEmbeddedDatabase(NEO_STORE);
NeoGraph graph = new NeoGraph(njgraph);

After initialization an instance of NeoGraph is created. Then create a Jena model for graph and pass NeoGraph instance as parameter.

Model njmodel = ModelFactory.createModelForGraph(graph);

Load triples from model into njmodel.

njmodel.add(model);

Bulk Load Example

Create a Jena model and read RDF file/triples in it.

Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open( inputFileName );
model.read(in,"","TTL"); 

Create a bacth inserter (act as graph service)

BatchInserter db = BatchInserters.inserter(NEO_STORE);

Initialize a batch handler and register the model.

BatchHandler handler = new BatchHandler(inserter,500000,60);
model.register(handler);

Read the model and close the handler

model.read(in,"","TTL");	
handler.close();

Search RDF data with Sparql

String queryString = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
            	"PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>" +
                "SELECT ?X ?name "+
                "WHERE" +
                "{ ?X ub:name ?name ." +
                 "FILTER regex(?name,\"^Publication\") ."+
                "}"; 
       	          
        Query query = QueryFactory.create(queryString);
        QueryExecution qExe = QueryExecutionFactory.create(query, njmodel);
        ResultSet results = qExe.execSelect();

neo4jena's People

Contributors

mahekhanfi avatar klatifch avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.