This is a Java library for nanopublications (see http://nanopub.net) based on RDF4J.
It implements the formal structure defined in the official nanopublication guidelines.
The easiest way to use this library in your project is to let Maven download it from The Central Repository, with an entry in your pom.xml file as shown here.
Alternatively, you might want to use one of the pre-built jar files.
In a nutshell, to create and publish nanopublications, you need to first make sure you have a local keypair. To create such a keypair, run just once:
MakeKeys.make("~/.nanopub/id", SignatureAlgorithm.RSA);And then nanopublications can be created and published programmatically like this:
System.err.println("# Creating nanopub...");
NanopubCreator npCreator = new NanopubCreator(true);
final ValueFactory vf = SimpleValueFactory.getInstance();
final IRI anne = vf.createIRI("https://example.com/anne");
npCreator.addAssertionStatement(anne, RDF.TYPE, vf.createIRI("https://schema.org/Person"));
npCreator.addProvenanceStatement(PROV.WAS_ATTRIBUTED_TO, anne);
npCreator.addPubinfoStatement(RDF.TYPE, vf.createIRI("http://purl.org/nanopub/x/ExampleNanopub"));
Nanopub np = npCreator.finalizeNanopub(true);
System.err.println("# Nanopub before signing:");
NanopubUtils.writeToStream(np, System.err, RDFFormat.TRIG);
System.err.println("# Signing nanopub...");
Nanopub signedNp = SignNanopub.signAndTransform(np, TransformContext.makeDefault());
System.err.println("# Final nanopub after signing:");
NanopubUtils.writeToStream(signedNp, System.err, RDFFormat.TRIG);
System.err.println("# Publishing to test server...");
PublishNanopub.publishToTestServer(signedNp);
//System.err.println("# Publishing to real server...");
//PublishNanopub.publish(signedNp);
System.err.println("# Published");For the complete code checkout UsageExamples.java.
See the JavaDocs for the API and source code documentation.
Here you can find more documentation.
Check out this list of all command line commands.
To use this library on the command line, just run:
macOS, Linux, WSL:
curl -LsSf https://raw.githubusercontent.com/Nanopublication/nanopub-java/master/bin/install.sh | bashWindows PowerShell:
irm https://raw.githubusercontent.com/Nanopublication/nanopub-java/master/bin/install.ps1 | iexThis automatically downloads the latest release as a jar file on the first run.
You can use this image from DockerHub.
Sign a nanopublication (nanopub.trig file in current dir here):
docker run -it --rm -v ~/.nanopub:/root/.nanopub -v $(pwd):/data nanopub/nanopub-java sign /data/nanopub.trigPublish a signed nanopublication:
docker run -it --rm -v ~/.nanopub:/root/.nanopub -v $(pwd):/data nanopub/nanopub-java publish /data/signed.nanopub.trigBuild the Docker image:
docker build -t nanopub/nanopub-java .Maven has to be installed to compile the library:
./mvnw clean packageThe library features can then be accessed by calling scripts/run.sh (with the
same commands as for the np script above, but using the locally compiled code
and not the jar file).
Create the file target/jacoco.exec which includes the test coverage information in a binary format.
./mvnw clean verifyTo create a HTML report out of jacoco.exec (target/site/jacoco/index.html) use:
./mvnw jacoco:report- Tobias Kuhn. nanopub-java: A Java Library for Nanopublications. In Proceedings of the 5th Workshop on Linked Science (LISC 2015). 2015.
nanopub-java is free software under the MIT License. See LICENSE.
For an overview of the dependencies and their licenses, run ./mvnw project-info-reports:dependencies and then visit target/reports/dependencies.html.