Code Monkey home page Code Monkey logo

lyo-store's Introduction

Lyo Store

Codacy Badge

Lyo Store is a library that provides a simple interface for working with a triplestore via Java objects representing OSLC Resources. Lyo Store and Jena Models in the triple stores.

Javadoc

Prerequisites

  • For an in-memory option: JVM heap should be set to 1G or above (see Jena documentation for more information on this).
  • For an on-disk option: an empty writable folder on disk, around 200MB of space is pre-allocated.
  • For a SPARQL option: a pair of SPARQL Query and SPARQL Update URLs, optionally with basic authentication.

Maven dependency

<dependency>
  <groupId>org.eclipse.lyo.store</groupId>
  <artifactId>store-core</artifactId>
  <version>2.2.0</version>
</dependency>

Initialisation

SPARQL

String sparqlQueryEndpoint = properties.getProperty("sparqlQueryEndpoint");
String sparqlUpdateEndpoint = properties.getProperty("sparqlUpdateEndpoint");
Store store = StoreFactory.sparql(sparqlQueryEndpoint, sparqlUpdateEndpoint);

On-disk

String storeDirProp = properties.getProperty("storeDir");
Path storeDir = Paths.get(storeDirProp);
Store store = StoreFactory.onDisk(storeDir);

In-memory

Store store = StoreFactory.inMemory();

Basic usage

Add the new resources and overwrite the existing ones

try {
    store.updateResources(GRAPH_NAME, // URI of the named graph
            resourceArray);           // an array of OSLC Resources
} catch (StoreAccessException e) {
    logger.error("Error executing a query on a triplestore");
}

Retrieving the resources from the triplestore

if (store.namedGraphExists(GRAPH_NAME)) {
    try {
        final int limit = 10; // fetch 10 resources
        final int offset = 0; // start with the first page
        // 'limit+1' is a technique that allows you to determine if there are
        // more results on the next page
        List<Requirement> requirements = store.getResources(GRAPH_NAME,
                Requirement.class, // resources of this class will be fetched and unmarshalled
                limit + 1,         // resource limit
                offset));          // how many resources to skip, use for paging
    } catch (StoreAccessException e) {
        logger.error("Error executing a query on a triplestore");
    } catch ( ModelUnmarshallingException e) {
        logger.error("Error unmarshalling the RDF from triplestore into Requirement class instances");
    }
}

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.