-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] First attempt at using Open Annotation Data Model #83
Conversation
Woot! 😄 Can you paste an example of what the output JSON-LD created by this looks like and at what URL(s) it's available? Thanks! |
Here's an example annotation. Put the whole thing into the JSON-LD playground to see the data in different formats. Note this is by no means the final version. I took the freedom to introduce Annotator's selector as The JSON-LD representation is not yet available at any URL. There are two questions here though: which URL(s) is it to be available, and which URI does the annotation itself have (preferably these overlap). The latter question seems more important to me and is not yet addressed in this first attempt. It probably depends on the particular application which URI they wish their annotations to have, and a base URI can be specified to achieve this. The default URI could be the URL that serves this individual annotation, e.g. {
"@context": {
"cnt": "http://www.w3.org/2011/content#",
"prov": "http://www.w3.org/ns/prov#",
"annotator": "http://annotatorjs.org/ns/",
"oa": "http://www.w3.org/ns/oa#",
"dc": "http://purl.org/dc/elements/1.1/",
"dctypes": "http://purl.org/dc/dcmitype/",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"@id": "4zAZEVMpTvq3hQjp8vzBnA",
"@type": "oa:Annotation",
"oa:hasBody": [
{
"cnt:chars": "bla bla blub",
"@type": "cnt:ContentAsText",
"dc:format": "text/plain"
}
],
"oa:hasTarget": {
"oa:hasSource": {
"@id": "http://localhost:4000/dev.html"
},
"oa:hasSelector": {
"annotator:endContainer": "/ul[1]/li[1]",
"annotator:startOffset": 0,
"annotator:startContainer": "/ul[1]/li[1]",
"@type": "annotator:TextRangeSelector",
"annotator:endOffset": 26
},
"@type": "oa:SpecificResource"
},
"oa:annotatedBy": "alice",
"oa:annotatedAt": {
"@value": "2014-07-25T19:17:36.121460+00:00",
"@type": "xsd:dateTime"
},
"oa:serializedBy": {
"foaf:name": "annotator-store",
"@id": "annotator:annotator-store",
"@type": "prov:Software-agent",
"foaf:homepage": {
"@id": "http://annotatorjs.org"
}
},
"oa:serializedAt": {
"@value": "2014-07-25T19:17:36.121478+00:00",
"@type": "xsd:dateTime"
},
"oa:motivatedBy": [
{
"@id": "oa:commenting"
}
]
} |
A question now is how would we want the content negotiation to happen? It appears that there is no mimetype associated with JSON-LD "because it is just JSON". I do not agree with that decision, as it is a specific and well-defined usage of json, so there should be a mime type that uses the An alternative to content negotiation is to simply have another URL to obtain the JSON-LD version, but that seems somewhat silly. |
@Treora "application/ld+json" |
I'm happy to accept a PR that adds the API without adding to store.py first. CONNEG and REST in another step. |
The instance data should be moved to the top of the class ( |
Thanks. I was using exactly that one for now, but I could not remember where I had taken it from. I already made the CONNEG and REST stuff so if it's okay I'll just include it in this pull request. |
@Treora make it a separate PR. The discussion is cleaner that way. And perhaps @nickstenning and @azaroth42 can take a look at this in isolation and we can get it merged more quickly. |
If we want to continue to support Python 2.6 we can also add a conditional test against the Python version when declaring the requirements in setup.py if it's desirable to run tests on Travis over the JSON-LD work. |
A few simplifications are possible:
context = "http://www.w3.org/ns/oa-context-20130208.json"
Thanks for the work!! |
Regarding the contexts, you could also do: context = ["http://www.w3.org/ns/oa-context-20130208.json", {"annotator" : "http://annotatorjs.org/ns/"}] And then ignore the comment about L169 |
Thanks for the comments. I did not know w3c published the OA JSON-LD context, that's a nice service, makes our code and JSON-LD documents cleaner. |
@@ -40,6 +52,8 @@ class Annotation(es.Model): | |||
__type__ = TYPE | |||
__mapping__ = MAPPING | |||
|
|||
jsonld_baseurl = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels better to leave this out to me. Otherwise we might end up setting a base=''
. I don't know what JSON-LD processors are supposed to do with that. Let the caller add it to the context if necessary, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's nice to have some default setting for it, so it's immediately obvious that it can be set, there's a place for its documentation, it shows up in tab completion in IDEs, etcetera. Setting it to None seems to be the elegant approach here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you have to guard the setting so you don't have null in the JSON there.
On Jul 29, 2014 4:09 PM, "Gerben" [email protected] wrote:
In annotator/annotation.py:
@@ -40,6 +52,8 @@ class Annotation(es.Model):
type = TYPE
mapping = MAPPING
- jsonld_baseurl = ''
I think it's nice to have some default setting for it, so it's immediately
obvious that it can be set, there's a place for its documentation, it shows
up in tab completion in IDEs, etcetera. Setting it to None seems to be the
elegant approach here.—
Reply to this email directly or view it on GitHub
https://github.com/openannotation/annotator-store/pull/83/files#r15558751
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the @base
was already conditional on the trueness of jsonld_baseurl
. (so in fact it would not even end up setting @base=""
by default like you feared)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Seems fine but unnecessary.
Looking really good! |
I'm very happy to defer to the experts (@azaroth42) on the subject of whether the serialization is good. It certainly looks very sensible to me. That said, from a programming point of view, I think this should probably not be implemented as a property on
This will make it much easier to test, and avoid the problem of having numerous methods on the |
From a programming point of view there could be many improvements, for example using something like I think that, to achieve the vision of a distributed annotation network on the web, I would like to have some sort of graph-based, semantic-web-minded storage system at some moment, rather than using Elasticsearch as a primary database with a non-standard data format that can be presented as OA JSON-LD when requested. However, this idea is so far away from the current annotator-store, which is at its core an Elasticsearch wrapper plus a REST API, that it probably makes more sense to start such a system from scratch. I guess that for annotator-store it would be okay to just have a JSON-LD renderer, as you suggested, and consider it a nice compatibility extra, so OA-based systems can read from it. |
Agreed on all counts, Gerben. I do think there's something to keeping the
|
Does the code need access to any private information about the model instance in order to render JSON-LD? If not, it probably shouldn't be part of the model class, for a number of different reasons (testability, readability, security to name a few). More generally, given that a model object has a potentially limitless number of representations, I think it's clear that we couldn't keep adding representation code into the model. But I'm totally agreed that there need to be some pretty major changes to the annotator-store if it's to be more widely used, and it's worth noting that this repository was originally meant to be a reference implementation of the storage API, not a production-ready storage application. I'm already firmly of the opinion that using ElasticSearch as a persistence layer is ridiculous, and am hoping to find time to change that soon. That said, the direction I want to move in is a database (AKA postgres) and not a triplestore. |
+1
|
No complaints from me, about any of it :) OA is intended for |
To @nickstenning's point about this repo being a reference implementation, I'd like to highlight the following--and perhaps move this discussion elsewhere soon. 😃 Despite what the README currently states, this repo is actually an implementation of the Store API expected by the Perhaps a good way forward on all these fronts is:
Regardless, we've got a solid JSON-LD representation built by @Treora and I'm excited to see it in use. 😸 |
Yes! And there will need to be, because this naive "REST" API is not going to work for shipping annotations between providers in the bold new world of interoperable annotations we're aiming for. I'm looking forward to discussing this with you in more detail. |
Discussing ... on the Open Annotation community group list? :) |
Why yes, @azaroth42. You read my mind! |
👍 🍻 |
So, just in case I came across negatively -- I think this is great, @Treora! I'll happily merge this (and the attendant code to expose this repr in the API) if the object creation moves into a separate annotation renderer class with its own tests. |
No worries, you don't sound negative. I was not aware it was originally intended as a reference implementation. If you wish to keep it more like that, it's totally okay with me to keep it separate (I could put it in Hypothes.is instead, so my effort would not be useless). On the other hand, it's perhaps also nice if there's a reference implementation for converting annotator's annotations to OA. |
Annotations can now be serialised into JSON-LD formatted RDF, following the data model spec: http://www.openannotation.org/spec/core/
Because JSON-LD spec recommends keeping @context at the top.
Let's keep the default very generic, for example we don't even know if users are Persons. Implementors can subclass Annotation to add more user info (as with any of the properties).
Closing in favor of #119 |
Annotations can now be serialised into JSON-LD formatted RDF, following
the data model spec: http://www.openannotation.org/spec/core/
Addresses #74