{"action":"created","issue":{"url":"https://api.github.com/repos/apache/jena/issues/139","repository_url":"https://api.github.com/repos/apache/jena","labels_url":"https://api.github.com/repos/apache/jena/issues/139/labels{/name}","comments_url":"https://api.github.com/repos/apache/jena/issues/139/comments","events_url":"https://api.github.com/repos/apache/jena/issues/139/events","html_url":"https://github.com/apache/jena/pull/139","id":153487885,"number":139,"title":"JSON-LD output","user":{"login":"fpservant","id":5287470,"avatar_url":"https://avatars.githubusercontent.com/u/5287470?v=3","gravatar_id":"","url":"https://api.github.com/users/fpservant","html_url":"https://github.com/fpservant","followers_url":"https://api.github.com/users/fpservant/followers","following_url":"https://api.github.com/users/fpservant/following{/other_user}","gists_url":"https://api.github.com/users/fpservant/gists{/gist_id}","starred_url":"https://api.github.com/users/fpservant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fpservant/subscriptions","organizations_url":"https://api.github.com/users/fpservant/orgs","repos_url":"https://api.github.com/users/fpservant/repos","events_url":"https://api.github.com/users/fpservant/events{/privacy}","received_events_url":"https://api.github.com/users/fpservant/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-05-06T16:24:10Z","updated_at":"2016-09-26T15:37:31Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/jena/pulls/139","html_url":"https://github.com/apache/jena/pull/139","diff_url":"https://github.com/apache/jena/pull/139.diff","patch_url":"https://github.com/apache/jena/pull/139.patch"},"body":"Hi,\r\n\r\nhere's my attempt at improving user's control over JSON-LD output and therefore, my request for comments.\r\n\r\nFollowing 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/%3c6F2CAA77-7586-4330-8903-16A81C5AB60E@gmail.com%3e)\r\n\r\nMains functionalities:\r\n- possibility to choose between expanded, compacted, flattened and framed output using different RDFFormat variants\r\n- possibility to set the \"@context\" used to compute the output \r\n- possibility to substitute the \"@context\" used to compute the output by another one\r\n\r\nBuilding 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.\r\n\r\nFeatures 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``).\r\n\r\nThe (jsonld) context and frame objects are passed as JSON strings (the user doesn't have to build JsonLD API objects).\r\n\r\nThe (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.\r\n\r\nTODO some documentation. Where should it be added? The best form would be small sample code. Easy to create from the existing tests.\r\n\r\nQUESTIONS\r\n- it is OK to have the Symbols used by the Context in JsonLDWriter? Should I define one subclass of Context instead?\r\n- 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.?\r\n- 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): \r\n\r\n```\r\n{\r\n  \"@id\" : \"_:b0\",\r\n  \"@type\" : \"sh:Person\",\r\n  \"name\" : \"Jane Doe\",\r\n  \"url\" : \"http://www.janedoe.com\",\r\n  \"@context\" : {\r\n    \"url\" : {\r\n      \"@id\" : \"http://schema.org/url\"\r\n    },\r\n    \"name\" : {\r\n      \"@id\" : \"http://schema.org/name\"\r\n    },\r\n    \"sh\" : \"http://schema.org/\"\r\n  }\r\n}\r\n```\r\n\r\nNote the \"@type\" : \"sh:Person\", while we have \"name\", etc. for props. Person and name are however in the same vocab.\r\n\r\nWe could choose to prefer to get:\r\n\r\n```\r\n{\r\n  \"@id\" : \"_:b0\",\r\n  \"@type\" : \"sh:Person\",\r\n  \"sh:name\" : \"Jane Doe\",\r\n  \"sh:url\" : \"http://www.janedoe.com\",\r\n  \"@context\" : {\r\n    \"sh:url\" : {\r\n      \"@id\" : \"http://schema.org/url\"\r\n    },\r\n    \"sh:name\" : {\r\n      \"@id\" : \"http://schema.org/name\"\r\n    },\r\n    \"sh\" : \"http://schema.org/\"\r\n  }\r\n}\r\n```\r\nNow we have \"sh:name\", etc, in line with the \"sh:Person\"\r\nWhat do you think? \r\n\r\nBest Regards,\r\n\r\nfps\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/apache/jena/issues/comments/249607094","html_url":"https://github.com/apache/jena/pull/139#issuecomment-249607094","issue_url":"https://api.github.com/repos/apache/jena/issues/139","id":249607094,"user":{"login":"fpservant","id":5287470,"avatar_url":"https://avatars.githubusercontent.com/u/5287470?v=3","gravatar_id":"","url":"https://api.github.com/users/fpservant","html_url":"https://github.com/fpservant","followers_url":"https://api.github.com/users/fpservant/followers","following_url":"https://api.github.com/users/fpservant/following{/other_user}","gists_url":"https://api.github.com/users/fpservant/gists{/gist_id}","starred_url":"https://api.github.com/users/fpservant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fpservant/subscriptions","organizations_url":"https://api.github.com/users/fpservant/orgs","repos_url":"https://api.github.com/users/fpservant/repos","events_url":"https://api.github.com/users/fpservant/events{/privacy}","received_events_url":"https://api.github.com/users/fpservant/received_events","type":"User","site_admin":false},"created_at":"2016-09-26T15:37:31Z","updated_at":"2016-09-26T15:37:31Z","body":"@stain yes, JSONLD-java can download a context from a URL, and cache it. The problem is, there is no way that I know of that would allow me to use that context in a write operation initiated from jena. I opened a JSONLD-java [issue](https://github.com/jsonld-java/jsonld-java/issues/184) about this."}}
{"actor":{"display_login":"fpservant"}}