Exemplo n.º 1
0
    def get(self):
        """GET method handler.

        Provides only minimal search query options and no JSON-LD export.
        Currently used only for IDentifying annotation objects.
        """
        annos = get_annotations(request.args.to_dict())
        return get_jsonld_multiple(annos, context={})
Exemplo n.º 2
0
    def post(self):
        """POST method handler.

        Allows performing complex queries and exporting annotations in JSON-LD
        format. It accepts a JSON document as input, with the following
        structure (defaults as values):
        {"query": {}       // The search query
         "ldexport: "full" // JSON-LD export format, can be: full, inline,
                           // compacted, expanded, flattened, framed,
                           // normalized.
         "context": "oaf"  // JSON-LD context or name/ URL of one to use for
                           // serialisation. Only "oaf" (Open Annotation) is
                           // currently supported
         "new_context": {} // new context to use for compacted format, tree
                           // tree structure for framed, options for normalised.

        Example requests:
        Get all annotation on record 1, full OA JSON-LD:
        curl invenio/api/annotations/export/ \
             -H "Content-Type: application/json" \
             --data '{"query": {"where.record": 1}, "ldexport": "full"}'

        Get specific annotation, compacted JSON-LD with field substitution:
        curl invenio/api/annotations/export/ \
             -H "Content-Type: application/json" \
             --data '{"query": {"_id": "3921323f-5849-4f47-83c4-97f048112b8f"},\
                      "ldexport": "compacted", \
                      "new_context":{"CUSTOM_BODY": "http://www.w3.org/ns/oa#hasBody"}}'

        Get specfic annotation, RDF triples in N-Quads format:
        curl invenio/api/annotations/export/ \
             -H "Content-Type: application/json" \
             --data '{"query": {"_id": "3921323f-5849-4f47-83c4-97f048112b8f"},\
                      "new_context":{"format": "application/nquads"}, \
                      "ldexport": "normalized"}'
        """
        rqj = request.json
        annos = get_annotations(rqj["query"])
        if "ldexport" in rqj:
            try:
                return get_jsonld_multiple(annos,
                                           context=rqj.get("context", "oaf"),
                                           new_context=rqj.get("new_context",
                                                               {}),
                                           format=rqj.get("ldexport", "full"))
            except:
                abort(400)
        return None