Github user afs commented on the issue:

    https://github.com/apache/jena/pull/139
  
    Apologies that this has taken so long.
    
    > TODO some documentation. Where should it be added? The best form would be 
small sample code. 
    
    Examples can go in `jena-arq/src-examples/arq/examples/riot/`. A new 
section about JSON-LD output for 
https://jena.apache.org/documentation/io/rdf-output.html, and use code links to 
apache/jena github, master branch. 
    
    Symbols are fine but URI's please! (changing `RIOT.riotIRI` to 
"http://jena.apache.org/riot";):
    
    e.g.  in JsonLDWriter
    ```
        public static final Symbol JSONLD_CONTEXT = 
Symbol.create("JSONLD_CONTEXT");
    ```
    
    **RDFDataMgr**
    
    The way to set things specially for a writing is to do:
    
    ```
        WriterDatasetRIOT w = 
RDFDataMgr.createDatasetWriter(RDFFormat.JSONLD_COMPACT_FLAT) ;
        w.write(System.out,  dataset.asDatasetGraph(), null, "http://base";, 
RIOT.getContext()) ;
    ```
    rather than add `RDFDataMgr.write(..., Context cxt)`
    
    See 
[examples/riot/ExRIOT_2](https://github.com/apache/jena/blob/master/jena-arq/src-examples/arq/examples/riot/ExRIOT_2.java)
 for an example for a reader.
    
    If you want, add a new API class specific to JSON output `JsonLdMgr` (to go 
in the same package as `RDFDataMgr`) with JSON-LD-specific functions to wrap 
common ways to call JSON-LD output. 
    
    **Constants**
    
    This could be tidied out with a subclass of `RDFFormatVariant` that carries 
JSON-LD information:
    
    ```
        // From JSON writer
        public static enum JSONLD_FORMAT {
            COMPACT, FLATTEN, EXPAND, FRAME
        }
        
        static class JSONLDFormatVariant extends RDFFormatVariant {
            private JSONLD_FORMAT option ;
            private boolean prettyJson ;
    
            public JSONLDFormatVariant(String name, boolean prettyJson, 
JSONLD_FORMAT option) { 
                super(name) ;
                this.options = option ;
                this.prettyJson = prettyJson ;
            }
            
            public boolean prettyJson() { return prettyJson ; }
            
            public boolean option(JSONLD_FORMAT fmt) {
                for ( JSONLD_FORMAT f : options ) {
                    if ( fmt == f )
                        return true ; 
                }
                return false ;
            }
        }
    
    
        private static final RDFFormatVariant JSONLD_EXPAND_PRETTY      = new 
JSONLDFormatVariant("expand pretty", true, JSONLD_FORMAT.EXPAND) ;
        private static final RDFFormatVariant JSONLD_EXPAND_FLAT        = new 
JSONLDFormatVariant("expand flat", false, JSONLD_FORMAT.COMPACT) ;
        ...
    ```
    then use in JsonLDWriter by casting to and JSONLDFormatVariant
    ```
            JSONLDFormatVariant format = (JSONLDFormatVariant)format ;
    ```
    ```        
            if ( format.option(COMPACT) ) {
              ...
            }
    ```
    
    **Tests**
    
    I ran the tests for JSONLD but got:
    
    ```
    10:13:04 WARN  JsonLDWriter              :: JSONLD_CONTEXT value is not a 
String. Assuming a context object expected by JSON-LD JsonLdProcessor.compact 
or flatten
    10:13:04 INFO  TestJsonLDWriter          :: Sorry to get this exception
    org.apache.jena.riot.RiotException: com.github.jsonldjava.core.JsonLdError: 
loading remote context failed: http://schema.org/
        at 
org.apache.jena.riot.out.JsonLDWriter.serialize(JsonLDWriter.java:218)
        at org.apache.jena.riot.out.JsonLDWriter.write(JsonLDWriter.java:123)
        at org.apache.jena.riot.out.JsonLDWriter.write(JsonLDWriter.java:129)
        at 
org.apache.jena.riot.system.RiotLib$WriterAdapter.write(RiotLib.java:376)
        at org.apache.jena.riot.RDFDataMgr.write$(RDFDataMgr.java:1232)
        ...
    ```
    
    We need to be able to run the tests without assuing that external network 
resources are availanle and functioning.
    
    The tests and build should work if there is no extenral connectivity.
    
    **Code organisation**
    
    If you feel there classes, fell free to create a package 
org.apache.jena.riot.out.jsonld to put them together.
    
    **Other**
    
    Indentation: spaces, not tabs please.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to