Currently, all libraries of the Linked Data Client are available only via Maven or as part of the Marmotta source code.
To use the Linked Data Client in your own projects, please add the following Maven dependencies to your project build:
<dependency> <groupId>org.apache.marmotta</groupId> <artifactId>ldclient-api</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.apache.marmotta</groupId> <artifactId>ldclient-core</artifactId> <version>3.3.0</version> </dependency>
This will add the basic Linked Data Client support to your project. In addition, you will need at least one data provider backend. Typically, you would at least add the RDF backend for accessing resources conforming to the Linked Data principles:
<dependency> <groupId>org.apache.marmotta</groupId> <artifactId>ldclient-provider-rdf</artifactId> <version>3.3.0</version> </dependency>
Backends are automatically used by the Linked Data Client as soon as they are found on the classpath. We provide many more backends for different legacy systems. Please see the list in the Introduction and the detailed description in Modules. Some of the backends will be applied automatically, others need to be configured explicitly using so-called “endpoint” configurations (see below).
Basic usage of the Linked Data Client library is very straightforward. You can create a new Linked Data Client with default configuration by simply adding the following statement:
LDClient ldclient = new LDClient();
Optionally, you can also pass a client configuration that allows you to customize the way LDClient will handle requests, e.g. socket and connection timeouts, number of parallel requests, default endpoint configurations, etc. The client configuration can also be updated later using the getClientConfiguration() method.
A resource is requested using the following statement:
ClientResponse result = ldclient.retrieveResource("http://...");
The result is a client response object giving you access to the retrieved triples as well as some metadata about the request (e.g. expiry time as communicated by the server). In case the retrieval fails (timeout or parse errors), the method call will throw a DataRetrievalException that should be handled by the caller. You can access the retrieved triples as follows:
RepositoryConnection con = result.getTriples().getConnection(); con.begin(); // access the connection, e.g. using SPARQL ... con.commit(); con.close();
The LDClient instance manages an internal connection pool and connection monitor. To avoid resource leakage, you should:
To allow access to different kinds of data sources and therefore wrap different formats into RDF, the LDClient library has two important concepts: providers and endpoints:
In some cases, a provider will only have a single endpoint definition, e.g. when accessing popular webservices like YouTube. Similarly, in some cases there will be reasonable default endpoint configurations (e.g. mapping Wikipedia to MediaWiki API). In both cases, such endpoints will be registered automatically when the library is found on the classpath using the Java service registry. In all other cases, it is necessary to explicitly register endpoint configurations with the LDClient instance. See the API Javadoc for more details.