Skip to content
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

Return API v2 responses in Turtle and RDF/XML #851

Merged
merged 34 commits into from
May 30, 2018

Conversation

benjamingeer
Copy link

@benjamingeer benjamingeer commented May 14, 2018

This PR allows all API v2 responses to be returned in Turtle and RDF/XML as well as in JSON-LD, using HTTP content negotation.

  • Change ontology response format to return a single ontology (using @graph in JSON-LD) as per hasClasses and hasProperties produce nonsensical Turtle #854 (requires change in SALSAH 2).
  • Change resource response format to use @graph in JSON-LD as per hasClasses and hasProperties produce nonsensical Turtle #854 (requires change in SALSAH 2).
  • Serve all Knora API v2 responses in other formats:
    • Turtle
    • RDF/XML
  • Specify literal datatypes where necessary in resource responses in the simple schema.
  • Use short, human-readable prefix labels when possible.
  • Add tests.
    • Test serving ontologies in:
      • Turtle
      • RDF/XML
    • Test serving resources in:
      • Turtle
      • RDF/XML
    • Test serving lists in:
      • Turtle
      • RDF/XML
  • Update docs.
    • Docs on querying/editing ontologies.
    • Docs on querying resources.
    • TypeScript definitions and sample responses.
  • Update release notes.

I was going to support returning API responses as HTML, but it would be a lot of work, and it doesn't seem worth it, since that's already being done in SALSAH 2.

The conversion from JSON-LD to other formats is done by writing the JSON-LD to a string, then parsing and reformatting it using RDF4J Rio (in RouteUtilV2.formatResponse). I tried converting our JSON-LD data structure directly to a Rio model, but the code to do this turned out to be rather complex, so I decided not to. And a test with ab shows that, even with the extra formatting and parsing, there is no noticeable difference in performance between formats.

The necessary changes to SALSAH 2 are in dhlab-basel/Salsah#252.

Resolves #609.
Resolves #854.
Resolves #857.
Resolves #855.
Resolves #853.
Resolves #863.
Resolves #865.

@benjamingeer benjamingeer added the enhancement improve existing code or new feature label May 14, 2018
@benjamingeer benjamingeer added this to the v1.5.0 milestone May 14, 2018
@benjamingeer benjamingeer self-assigned this May 14, 2018
@benjamingeer benjamingeer mentioned this pull request May 18, 2018
@benjamingeer benjamingeer changed the title Return API v2 responses in formats other than JSON-LD Return API v2 responses in Turtle and RDF/XML May 18, 2018
@benjamingeer
Copy link
Author

benjamingeer commented May 18, 2018

Example of a book resource in the simple schema in Turtle, with a knora-api:Date datatype:

@prefix knora-api: <http://api.knora.org/ontology/knora-api/simple/v2#> .
@prefix incunabula: <http://0.0.0.0:3333/ontology/0803/incunabula/simple/v2#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<http://rdfh.ch/2a6221216701> a incunabula:book;
  incunabula:book_comment "Katalogaufnahme anhand ISTC und v.d.Haegen";
  incunabula:citation "Borm 1751", "C 3833", "FairMur(G) 283", "Goff M165", "IBP 3556",
    "Klebs 651.2", "Schr 4799", "Schramm XXI p. 9 & 26", "Van der Haegen I: 9,14";
  incunabula:location "Basel UB, Sign: Aleph D III 13:1";
  incunabula:note "Besitzervermerke: Kartause, H. Zscheckenbürlin", "Holzschnitte nicht koloriert",
    "Rubr. mit Init. J zu Beginn", "Zusammengebunden mit: Die zehen Gebote ; Was und wie man beten soll und Auslegung des hlg. Pater nosters / Hans von Warmont. Strassburg, 1516",
    "deutsch von Otto von Diemeringen";
  incunabula:physical_desc "Extent: 1 Bd.; Dimensions: f°";
  incunabula:pubdate "JULIAN:1481 CE"^^knora-api:Date;
  incunabula:publisher "Bernhard Richel";
  incunabula:publoc "Basel";
  incunabula:title "Itinerarius", "Reise ins Heilige Land", "Reysen und wanderschafften durch das Gelobte Land";
  incunabula:url "http://aleph.unibas.ch/F/?local_base=DSV01&con_lng=GER&func=find-b&find_code=SYS&request=002610320";
  rdfs:label "Reise ins Heilige Land" .

@tobiasschweizer
Copy link
Contributor

@benjamingeer I managed to create the test data, but now some tests have to be fixed. I cannot do it before Wednesday. Could you have a look at it? I think it is just the tests that search for things that now have a different result since I added another thing.

@tobiasschweizer
Copy link
Contributor

@benjamingeer I fixed a general problem with the test function in PR #862 but I think some of those should be applied immediately:

webapi/src/test/scala/org/knora/webapi/e2e/v2/ResponseCheckerR2RV2.scala: two additional asserts

webapi/src/test/scala/org/knora/webapi/responders/v2/ResourcesResponseCheckerV2.scala three additional asserts

Shall I add them to this PR?

@benjamingeer
Copy link
Author

Yes please.

@tobiasschweizer
Copy link
Contributor

done in 6274fb8

this is just what is absolutely needed, more will come with my PR

@tobiasschweizer
Copy link
Contributor

or probably I decide to make an own PR just for that to be faster

@benjamingeer benjamingeer merged commit 75152d5 into develop May 30, 2018
@benjamingeer benjamingeer deleted the wip/ontology-doc-formats branch May 30, 2018 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment