GitHub user fpservant opened a pull request:

    https://github.com/apache/jena/pull/139

    JSON-LD output

    Hi,
    
    here's my attempt at improving user's control over JSON-LD output and 
therefore, my request for comments.
    
    Following discussions on jena-users list : 
[[1]](http://users.jena.apache.narkive.com/NF0pn3kq/controlling-json-ld-output) 
and 
[[2]](https://mail-archives.apache.org/mod_mbox/jena-users/201604.mbox/%[email protected]%3e)
    
    Mains functionalities:
    - possibility to choose between expanded, compacted, flattened and framed 
output using different RDFFormat variants
    - possibility to set the "@context" used to compute the output 
    - possibility to substitute the "@context" used to compute the output by 
another one
    
    Building on existing jena features, simple functionalities are easy to use, 
or so I hope: you just choose the RDFFormat to choose between expanded, 
compacted..: as in current jena master, a default context is computed for 
formats that need one.
    
    Features that require passing an object to the JSON-LD API (a jsonld 
context or a frame) are built using the jena "Context" mechanism 
(``org.apache.jena.sparql.util.Context``).
    
    The (jsonld) context and frame objects are passed as JSON strings (the user 
doesn't have to build JsonLD API objects).
    
    The (jena) context parameter wasn't available in the write methods of 
``org.apache.jena.riot.RDFDataMgr``however. I just added ``public static void 
write(OutputStream out, Model model, RDFFormat serialization, Context ctx)``to 
it. Should we also do it for the other write methods (write(StringWriter...))? 
Yes, probably.
    
    TODO some documentation. Where should it be added? The best form would be 
small sample code. Easy to create from the existing tests.
    
    QUESTIONS
    - it is OK to have the Symbols used by the Context in JsonLDWriter? Should 
I define one subclass of Context instead?
    - As there already were a JSONLD_PRETTY and a JSONLD_FLAT RDFFormat, I felt 
obliged to create 8 different RDFFormats for JSONLD (expanded, compact, etc. * 
2 - on pretty and one flat for each, eg. JSONLD_EXPAND_FLAT). Without the 2 
pre-existing ones, I would have created only 4, and use the context to pass a 
flag pretty/flat. But now, passing this flag would add complexity without 
decreasing much the number of different RDFformats. BTW: should I create 
"aliases" such as JSONLD_COMPACT, etc.?
    - There is one more functionality that I developed, but I didn't include it 
in here: the possibility to choose to prefer prefixed forms for properties over 
localname based ones in the output. Not clear? Here is an example of what we 
get, giving the way the context is computed (when there is none): 
    
    ```
    {
      "@id" : "_:b0",
      "@type" : "sh:Person",
      "name" : "Jane Doe",
      "url" : "http://www.janedoe.com";,
      "@context" : {
        "url" : {
          "@id" : "http://schema.org/url";
        },
        "name" : {
          "@id" : "http://schema.org/name";
        },
        "sh" : "http://schema.org/";
      }
    }
    ```
    
    Note the "@type" : "sh:Person", while we have "name", etc. for props. 
Person and name are however in the same vocab.
    
    We could choose to prefer to get:
    
    ```
    {
      "@id" : "_:b0",
      "@type" : "sh:Person",
      "sh:name" : "Jane Doe",
      "sh:url" : "http://www.janedoe.com";,
      "@context" : {
        "sh:url" : {
          "@id" : "http://schema.org/url";
        },
        "sh:name" : {
          "@id" : "http://schema.org/name";
        },
        "sh" : "http://schema.org/";
      }
    }
    ```
    Now we have "sh:name", etc, in line with the "sh:Person"
    What do you think? 
    
    Best Regards,
    
    fps
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/fpservant/jena master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/jena/pull/139.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #139
    
----
commit 6a0e1b5ceb111277989b891fe1fee50ab25fcf9c
Author: François-Paul Servant <[email protected]>
Date:   2016-05-05T01:11:49Z

    Initial commit: RDFFormat variants for the different JSON-LD outputs.
    Jena Context mechanism to allow to pass the jsonld "@context"

commit 99db17246f26b44a5b93cf22169dcddf99722ec8
Author: François-Paul Servant <[email protected]>
Date:   2016-05-05T22:57:18Z

    EXPAND_PRETTY was not pretty (and details in comments)

commit 1f7433400edb79ac8e01f2b16ca79ba8a2b7eadc
Author: François-Paul Servant <[email protected]>
Date:   2016-05-05T22:57:50Z

    details

commit 1e2bdc7647ffde9b84e50f831a50a57b3bdcc3c6
Author: François-Paul Servant <[email protected]>
Date:   2016-05-05T22:59:27Z

    testFrames() (new)

commit a5f2e06db9583248f1a33f3c0ca85ee2b4039de0
Author: François-Paul Servant <[email protected]>
Date:   2016-05-05T23:14:43Z

    JSONLD RDFFormat variants no more public

commit 0029b90048c1d06a86a2be08f6670e4cd8897d22
Author: François-Paul Servant <[email protected]>
Date:   2016-05-05T23:17:48Z

    details

commit df45458624694f4605954467a135bd9c26d075bc
Author: François-Paul Servant <[email protected]>
Date:   2016-05-06T09:08:38Z

    Setting the "@context" using a json string

commit 30a044a162075f176c89e7b0cbf977cea2e1ffe4
Author: François-Paul Servant <[email protected]>
Date:   2016-05-06T11:46:47Z

    javadoc comments

commit dda9edeace562d4f5a88208f92b710e2a7b33113
Author: François-Paul Servant <[email protected]>
Date:   2016-05-06T11:48:33Z

    typos

commit 046b6e56c440b0b51e7b035689dd560617ed35cd
Author: François-Paul Servant <[email protected]>
Date:   2016-05-06T12:36:24Z

    Now uses a JSON String to pass the "@context" (the passing of the object
    expected by the JSONLD-java API is still supported, but generates a
    warning)

commit 1c613aec5f396a1fd4882a15d562ce9416bade86
Author: François-Paul Servant <[email protected]>
Date:   2016-05-06T12:51:02Z

    details

commit 66f604c417a7886fc6316329b14596b5164dc529
Author: François-Paul Servant <[email protected]>
Date:   2016-05-06T13:11:06Z

    Details

commit 3c2a469ae2140eba04d3c941d0e23b11e646b404
Author: François-Paul Servant <[email protected]>
Date:   2016-05-06T14:03:26Z

    JSONLD_CONTEXT_SUBSTITUTION to replace the @context in the output

commit 2259ce52619ba1a20656ae7ab8aca44bc7cad137
Author: fpservant <[email protected]>
Date:   2016-05-06T15:27:34Z

    Merge pull request #1 from fpservant/jsonld-output
    
    Jsonld output

----


---
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