Skip to content

Commit

Permalink
calling the json-ld (0.8.3) method that assumes no duplicates in dataset
Browse files Browse the repository at this point in the history
(cf. jsonld-java/jsonld-java#173)
Changes following Andy's comments: RDFFormatVariant, indentation using
spaces
  • Loading branch information
fpservant committed Aug 28, 2016
1 parent 7f0f061 commit 39c881a
Show file tree
Hide file tree
Showing 4 changed files with 584 additions and 576 deletions.
61 changes: 47 additions & 14 deletions jena-arq/src/main/java/org/apache/jena/riot/RDFFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class RDFFormat {
public static final RDFFormatVariant UTF8 = new RDFFormatVariant("utf-8") ;
/** Variant for RDF Thrift using values */
public static final RDFFormatVariant ValueEncoding = new RDFFormatVariant("Value") ;

/** Turtle - pretty form */
public static final RDFFormat TURTLE_PRETTY = new RDFFormat(Lang.TURTLE, PRETTY) ;
/** Turtle - default form */
Expand Down Expand Up @@ -79,19 +79,52 @@ public class RDFFormat {
/** TriG - one line per triple */
public static final RDFFormat TRIG_FLAT = new RDFFormat(Lang.TRIG, FLAT) ;

//
// JSONLD related
//

public static class JSONLDVariant extends RDFFormatVariant {
private static enum JSONLD_FORMAT {
COMPACT,
FLATTEN,
EXPAND,
FRAME
}

private JSONLD_FORMAT format ;
private boolean prettyJson ;

JSONLDVariant(String name, boolean prettyJson, JSONLD_FORMAT format) {
super(name) ;
this.format = format ;
this.prettyJson = prettyJson ;
}

public boolean isPretty() { return prettyJson ; }

private boolean isFormat(JSONLD_FORMAT fmt) {
return (fmt == format);
}

public boolean isCompact() { return isFormat(JSONLD_FORMAT.COMPACT); }
public boolean isFlatten() { return isFormat(JSONLD_FORMAT.FLATTEN); }
public boolean isExpand() { return isFormat(JSONLD_FORMAT.EXPAND); }
public boolean isFrame() { return isFormat(JSONLD_FORMAT.FRAME); }

}

// variants for the JsonLD outputs.
// because of the prexisting JSONLD_PRETTY and JSONLD_FLAT,
// because of the preexisting JSONLD_PRETTY and JSONLD_FLAT,
// we're more or less obliged to create all of these
// (I'd have preferred to use a flag for pretty vs flat)

private static final RDFFormatVariant EXPAND_PRETTY = new RDFFormatVariant("expand pretty") ;
private static final RDFFormatVariant EXPAND_FLAT = new RDFFormatVariant("expand flat") ;
private static final RDFFormatVariant COMPACT_PRETTY = new RDFFormatVariant("compact pretty") ;
private static final RDFFormatVariant COMPACT_FLAT = new RDFFormatVariant("compact flat") ;
private static final RDFFormatVariant FLATTEN_PRETTY = new RDFFormatVariant("flatten pretty") ;
private static final RDFFormatVariant FLATTEN_FLAT = new RDFFormatVariant("flatten flat") ;
private static final RDFFormatVariant FRAME_PRETTY = new RDFFormatVariant("frame pretty") ;
private static final RDFFormatVariant FRAME_FLAT = new RDFFormatVariant("frame flat") ;

private static final RDFFormatVariant EXPAND_PRETTY = new JSONLDVariant("expand pretty", true, JSONLDVariant.JSONLD_FORMAT.EXPAND) ;
private static final RDFFormatVariant EXPAND_FLAT = new JSONLDVariant("expand flat", false, JSONLDVariant.JSONLD_FORMAT.EXPAND) ;
private static final RDFFormatVariant COMPACT_PRETTY = new JSONLDVariant("compact pretty", true, JSONLDVariant.JSONLD_FORMAT.COMPACT) ;
private static final RDFFormatVariant COMPACT_FLAT = new JSONLDVariant("compact flat", false, JSONLDVariant.JSONLD_FORMAT.COMPACT) ;
private static final RDFFormatVariant FLATTEN_PRETTY = new JSONLDVariant("flatten pretty", true, JSONLDVariant.JSONLD_FORMAT.FLATTEN) ;
private static final RDFFormatVariant FLATTEN_FLAT = new JSONLDVariant("flatten flat", false, JSONLDVariant.JSONLD_FORMAT.FLATTEN) ;
private static final RDFFormatVariant FRAME_PRETTY = new JSONLDVariant("frame pretty", true, JSONLDVariant.JSONLD_FORMAT.FRAME) ;
private static final RDFFormatVariant FRAME_FLAT = new JSONLDVariant("frame flat", false, JSONLDVariant.JSONLD_FORMAT.FRAME) ;

public static final RDFFormat JSONLD_EXPAND_PRETTY = new RDFFormat(Lang.JSONLD, EXPAND_PRETTY) ;
public static final RDFFormat JSONLD_EXPAND_FLAT = new RDFFormat(Lang.JSONLD, EXPAND_FLAT) ;
Expand All @@ -102,7 +135,7 @@ public class RDFFormat {
public static final RDFFormat JSONLD_FRAME_PRETTY = new RDFFormat(Lang.JSONLD, FRAME_PRETTY) ;
public static final RDFFormat JSONLD_FRAME_FLAT = new RDFFormat(Lang.JSONLD, FRAME_FLAT) ;

// redefine following ones in a way that preserve what they were doing in previous version
// redefine following ones in a way that preserve what they were doing in previous version
public static final RDFFormat JSONLD_PRETTY = JSONLD_COMPACT_PRETTY ;
public static final RDFFormat JSONLD = JSONLD_COMPACT_PRETTY ;
public static final RDFFormat JSONLD_FLAT = JSONLD_COMPACT_FLAT ;
Expand All @@ -127,7 +160,7 @@ public class RDFFormat {
*
* @see #RDF_THRIFT_VALUES
*/

public static final RDFFormat RDF_THRIFT = new RDFFormat(THRIFT) ;
/**
* A variant of an an RDFFormat that uses value encoding (e.g. integers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

package org.apache.jena.riot;

import java.io.OutputStream ;
import java.io.OutputStream;
import java.io.Writer ;

import org.apache.jena.riot.Lang ;
import org.apache.jena.riot.system.PrefixMap ;
import org.apache.jena.riot.system.RiotLib;
import org.apache.jena.sparql.core.DatasetGraph ;
import org.apache.jena.sparql.util.Context ;

Expand All @@ -47,6 +48,10 @@ public interface WriterDatasetRIOT
* @param context Context (see specific implementation for details)
*/
public void write(OutputStream out, DatasetGraph datasetGraph, PrefixMap prefixMap, String baseURI, Context context) ;

default public void write(OutputStream out, DatasetGraph datasetGraph, String baseURI, Context context) {
write(out, datasetGraph, RiotLib.prefixMap(datasetGraph), baseURI, context);
}

// /** Use of Writer is discouraged - let the serializer manage character sets in accordance with the format */
// public void write(Writer out, DatasetGraph datasetGraph) ;
Expand Down

0 comments on commit 39c881a

Please sign in to comment.