Skip to content

stardog-union/stardog-examples

Repository files navigation

Join the chat at https://gitter.im/Complexible/stardog-examples

Programming Stardog: Examples

This is a small collection of examples of working with Stardog via its APIs, as well as examples of how to use some of the extension points within Stardog.

How to build examples

First, you'll need a valid Stardog download.

You can use the included Gradle Wrapper script to build the examples in examples/api, example/foaf, examples/function.

To compile or run the examples, gradle will automatically download the dependencies from our public maven repository:

$ ./gradlew compileJava

To run the examples, they require a valid $STARDOG_HOME; you can provide this via the parameter stardog.home (eg -PstardogHome=/my/stardog/home).

To run any of the examples, you can use the Gradle execute task. By default, this will run the ConnectionAPIExample program, but you can specify the fully-qualified class name of any of the other examples using the mainClass parameter.

$ ./gradlew execute -PmainClass=com.complexible.stardog.examples.api.ICVExample

.NET Examples

To compile the .NET examples, you will need to install .NET Core. Make sure that the dotnet tool is on your PATH

While you can build the sample with the latest version of the .NET Core SDK you will need .NET Core runtime installed to run the example. You can download it from here - you can verify which .NET Core runtimes you have installed by running:

dotnet --list-runtimes

Once you have installed .NET Core SDK and runtime,you can build the sample with the following command:

$ ./gradlew compileDotnet

To run the .NET examples you should have Stardog running locally and listening on port 5820 (you can change this by editing the connection string in ./examples/dotnet/TrinityConsoleSample/Program.cs. In addition, the example expects Stardog to have a database named 'music' loaded with the data from ./examples/dotnet/TrinityConsoleSample/Ontologies/music_schema.ttl and music.ttl.gz in a named graph called http://stardog.com/tutorial

You can run the sample with the following command (NOTE: the following command will automatically rebuild the sample):

$ ./gradlew runDotnet

The sample project will connect to Stardog and execute several queries using SPARQL and LINQ. It will print the results to the console.

For additional information see the DotNet Samples' README file - ./examples/dotnet/README.md

Generating Documentation

The Stardog documentation and its javadocs are a good place to start. But some examples in this repository are annotated using Markdown; they can be processed by Docco.

If you don't have Docco installed, it's pretty easy to get started:

$ sudo npm install -g docco

Then, you can run it directly against any example:

$ docco -o docs main/src/com/complexible/stardog/api/ConnectionAPIExample.java

Or you can use the supplied gradle docs task in each build file that will run Docco against all annotated source files.

Service Loading

You'll notice that a number of examples have in their source a directory META-INF/services, these are the service registrations for each example.

Stardog uses the JDK ServiceLoader to load new services at runtime and make them available to the various parts of the system. The files in the services directory should be the fully qualified class name of the class/service, such as com.complexible.stardog.plan.filter.functions.Function, and the contents of the file should be a list of the fully qualified class names of the implementations of that service.

These need to be a part of your classpath, usually embedded in the jar file with the compiled source, in order for the ServiceLoader to make them up.

List of Examples

  1. Custom Analyzers
  2. Stardog API Examples
  3. Integrity Constraint Validation
  4. CSV example
  5. Docs Examples
  6. Database Archetype Extensibility
  7. DotNet Examples
  8. Function Extensibility
  9. Transaction Listener
  10. Cloud Foundry Example Application
  11. Machine Learning
  12. Anti-money laundering (AML) Example
  13. Transaction listener
  14. Http handler
  15. Stardog Free Examples