Skip to content

Commit

Permalink
Test serialization of GND RDF to compact JSON-LD
Browse files Browse the repository at this point in the history
See #1
  • Loading branch information
fsteeg committed Jun 30, 2017
1 parent 074f6cd commit 47e442b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ target
.classpath
.project
.settings/org.scala-ide.sdt.core.prefs
logs
27 changes: 27 additions & 0 deletions app/controllers/TestRdfSerialization.java
@@ -0,0 +1,27 @@
package controllers;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.github.jsonldjava.core.JsonLdError;
import com.github.jsonldjava.core.JsonLdOptions;
import com.github.jsonldjava.core.JsonLdProcessor;
import com.github.jsonldjava.jena.JenaRDFParser;
import com.github.jsonldjava.utils.JsonUtils;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class TestRdfSerialization {

public static void main(String[] args) throws JsonLdError, JsonGenerationException, IOException {
Model model = ModelFactory.createDefaultModel();
model.read("http://d-nb.info/gnd/2047974-8/about/lds");
Object jsonLd = JsonLdProcessor.fromRDF(model, new JenaRDFParser());
String context = "http://hub.culturegraph.org/entityfacts/context/v1/entityfacts.jsonld";
JsonLdOptions options = new JsonLdOptions();
options.setCompactArrays(false);
jsonLd = JsonLdProcessor.compact(jsonLd, context, options);
System.out.println(JsonUtils.toPrettyString(jsonLd));
}

}
4 changes: 4 additions & 0 deletions build.sbt
Expand Up @@ -8,3 +8,7 @@ lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.12.2"

libraryDependencies += guice

libraryDependencies += "com.github.jsonld-java" % "jsonld-java" % "0.10.0"

libraryDependencies += "com.github.jsonld-java" % "jsonld-java-jena" % "0.4.1"

0 comments on commit 47e442b

Please sign in to comment.