-
Notifications
You must be signed in to change notification settings - Fork 18
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
Implement a DSL for API v2 extended search #530
Comments
The client needs to be able to specify which data they want in the results, so we need something like a CONSTRUCT clause as well as a WHERE clause. So actually we can make this work rather like a SPARQL endpoint. The client can actually submit SPARQL, but the submitted SPARQL will be restricted:
The API server can parse this SPARQL using an existing SPARQL parser, validate it, and generate a real SPARQL query from it. The conversion will involve:
So for example, if the client submits something like this:
This will be converted to something like this:
|
In #478 there's now a utility called |
This is a simple sample query which returns the letters exchanged between two persons: Please note that internal Iris are used (they still need to be changed to external Iris).
In Knora, this has to look like this:
|
@benjamingeer Do you think we could allow for the use of Boolean operators in the FILTER and Iris (non literals)? Such as: I want to get all the letters that refer to a person with one of two possible properties. |
Sure, I'll do this on Monday. |
Great, thx.! By the way: I can run the query above (the longer one) and display the results with our standard v2 scala methods as JSON-LD :-) |
* refactor (move Responder): move Responder up the directory tree to be used for both v1 and v2 * feature (add support for V2): create responder manager for V2 * refactor (optimize imports): remove unnecessary import statement * feature (search v2): use SPARQL construct query to perform a fulltext search * feature (search V2): return results * feature (generate JSON-LD from case class): ongoing ... * feature (generate JSON-LD from case class) ongoing ... * feature (search results as JSON-LD): return a list of values for each property * feature (JSON-LD): add more members to search response * feature (search results as JSON-LD): show information about value objects * refactor (fulltext search): rename variables in SPARQL query * feature (add resources route V2): ongoing ... * feature (v2 resource query): add SPARQL for v2 resource query * refactor (add util for construct query results): try to process search and resource request results in a generic way * refactor (util for construct query v2): add utility function to get a predicate's value * feature (resource request v2): try to reuse methods needed for search * refactor (unify response messages for v2): make a generic resource response format * feature (typed literals): represent value literals in a type specific way * feature (value literal types): support more literal value types * refactor (rename v2 response messages components) * refactor (V2 case class): try to make case classes response format independent * refactor (v2 case classes): convert Sparql results to generic case classes * refactor (v2 case classes): try to reuse the same case class components for different API operations * refactor (v2 response format): convert value types to JSON * refactor (restructure v2 case class): reuse v2 case classes in different response formats * refactor (v2 resource response): include standoff in search results * refactor (v2 sparql results): separate resources from standoff nodes * refactor (v2 resource query): handle value props and linking props separately * refactor (v2): split results (ongoing ...) * refactor (v2 response): create case classes from CONSTRUCT query response (organizez by resource) * refactor (v2 results): unify the creation of responses to the highest possible degree between fulltext search and full resource response * refactor (v2 response): include information about a referred resource in a link value representation * refactor (v2 Sparql results): handle Sparql Construct results in a generic way * refactor (construct response for v2): add more documentation and make variable names clearer * feature (v2 date): represent a JDN in an understandable string representation * refactor (v2 fulltext search): return the values of a value object * refactor (v2 sparql queries): use UNION instead of OPTIONAL * refactor (unfify standoff handling): put the creation of standoff nodes in a separate function called by v1 and v2 * refactor (fix some minor inconsistencies) * refactor (reapply some changes from another branch): improve handling of beol data * feature (default XSL transformation): add an optional default XSL transformation to a mapping * refactor (v2 handling of mapping): represent mapping and default XSL transformation with a case class * feature (apply XSL transformation to XML): convert XML before returning it to the client using the default XSL transformation * feature (v2 permission check): check for permissions on resources and values * fix (set cookie for all paths): set path to root to make cookie valid for v1 and v2 * feature (limit query results in fulltext search): use a SELECT subquery to limit search results * refactor (fix typo) * fix (authentication test): fix test (cookie path) * refactor (webapi): Rename some V2 classes for clarity. - ValueObjectV2 -> ValueContentV2 - ValueObject -> ValueRdfData * refactor (v2 fulltext search): do not query standoff nodes * fix (bloody authentication test): set absolute cookie path * refactor (webapi): Rename ValueV2 -> IOValueV2 for clarity. * feature (knora api ontology): add more properties for value types (ongoing) * refactor (api ontology): define knora api entities (ongoing) * refactor (v2 knora api ontology): ongoing * feature (webapi): Add JSON-LD library. * feature (knora api date handling) add utility methods (ongoing) * feature (knora api values): convert a knora-base date to a knora-api date * feature (knora api values): convert a knora-base text value to a knora-api text value * feature (knora api values): integer and decimal value types * refactor (knora api ontology): link value * refactor (knora-api values): handle link values (recursion not supported yet) * feature (v2: flag resources): indicate if a resource is the main resource or a referred resource * refactor (v2 api response): check for isMainResource * fix (value content v2 case classes): fix wrong constant * feature (v2 knora api): support still image file values * refactor (webapi): Refactor code for processing resource with values from query results. * feature (values v2): add missing value types * feature (v2 knora api): add more value types to ontology * feature (knora api v2): construct missing ValueContentV2 case classes from Sparql results * feature (handling of referred resources): follow links recursively * feature (referred resources): represent referred resources as nested structures in link values * refactor (referred resources): follow references to resources when turning them into JSON-LD * refactor (resources route): accept a list of resource Iris * feature (ontologies responder v2): prepare the ontologies responder v2 * fix (webapi): Don’t follow link cycles in an infinite loop. * refactor (ontology responder v2): make ontology responder v1 call ontology responder v2 for cached data * refactor (ontology responder v2): move subclass checks to V2 responder * feature (api v2): provide information for IIIF image API client * refactor (unify responder manager): unify v1 and v2 responder manager * refactor (consistency of ontology responder v2): retun v2 messages - TODO: use v2 directly (eliminate v1) * refactor (ontology information v2 JSON-LD): return an object for resource classes and properties (IRIs are keys) * feature (ontology responder v2): get property definitions v2 * refactor (named graph v2): get entity definitions for named graphs * feature (ontologies v2): return Iris of existing named graphs * feature (JSONLD lib): use JSONLD library to construct response * feature (fallback language): use a preferred and a fallback language when looking for ontology information * refactor (knora-api ontology): use consistent naming schema for knora-api entities * fix (typo): remove superfluous # * ben (apply changes from bulk import branch): apply refactoring of OntologyConstants and InputValidation to this branch * refactor (knora api constants): stick to new refactoring scheme * refactor (expose only knora-api Iris to the outside): translate internal Iris to knora-api Iris * feature (external to internal Iris): convert external ontology and entity Iris to internal Iris * feature (provide default XSL transformation): define a default XSL transformation when creating a mapping * refactor (increase timeout): increase timeout when connecting to the triplestore (for graphdb 8.1.1). * feature (search resources by label): search for resources by their label * feature (webapi): Start proof-of-concept of #530. * feature (resource preview V2): get the preview of a resource * feature (webapi): Start making a data structure to represent a simple SPARQL CONSTRUCT query submitted to API v2. * feature (webapi): Parse simple SPARQL CONSTRUCT queries for extended v2 search. - Add test. * refactor (webapi): Remove unused ANTLR grammar and library. * test: Add more tests for SearchParserV2. * test: Add tests for rejecting nested UNIONs in a SPARQL search query. * test: Add a test for rejecting an OPTIONAL in a search query. * test (add test case for query parser): CONSTRUCT query is not handled correctly (taken for a SELECT by mistake) * feature (webapi): Fix parsing bug in SearchParserV2. - Allow OPTIONALs, but not nested ones. - Sort WHERE clause patterns: statements, UNIONs, OPTIONALs, FILTERs. * tests (add Sparql parser test): add test for Sparql parser * refactor (remove docs for inexistent parameter) * feature (extended search): prepare extended search - template still static * refactor (simplified sparql): allow for Boolean operators in FILTER * refactor (rename regex) * refactor (SearchParserSpec): adapt test for Boolean operator in test * feature (webapi): Support BIND in a CONSTRUCT query for extended search. * feature (convert external Iris to internal Iris): handle external Iris in simplified sparql * feature (webapi): Add ontology entities and SPARQL for key-value store (#524). * feature (webapi): Start implementing persistent maps. - Move triplestore messages out of APIv1-specific package. * refactor (webapi): Keep the messages.store package, just not in v1. * refactor (webapi): Rename MapMessagesV2.scala -> PersistentMapMessagesV2.scala. * feature (extended search): prepare extended search with user provided Sparql * refactor (settings): pass settings obj in the route * feature (sparql processing for extended search) ongoing fight ... * feature (extended search): provide more sample sparql queries * feature (extended search): automatically create additional Sparql statements * feature (webapi): Implement PersistentMapResponderV2 (not tested yet). * feature (webapi): Inspect search SPARQL to extract type information. * feature (webapi): Remove the type annotations from a search WHERE clause. - Disallow BIND. * feature (extended search): crazy stuff at the end of a long workday * feature (webapi): fix type inspector Scaladoc. * feature (extended search): process statements and add more statements based on type info (ongoing) - TODO: try to write a function to avoid redundant code when creating more statements - TODO: try to find a way so that typeInspectionResult may stay immutable * refactor (extended search): disable inference in the Twirl template * refactor (extended search): create additional statements from type info in a function - TODO: try to split this function into more functions that can be reused * refactor (extended search): handle property and non property types in dedicated functions * feature (extended search): handle value props (string) * feature (extended search): keep original where patterns and additional statements separate * refactor (extended search): adapt sample query * feature (extended search): transform FILTER patterns * refactor (extended search): accept url encoded string as Sparql query - provide test case in JS (url encode Sparql string) * refactor (extended search): make some clarifications * refactor (extended search): improve separation of statements provided by the user and additional statements created based on type annotations * feature (extended search): check for isDeleted flag * feature (extended search): support file and geom values * feature (extended search): find out if predicate variables represent value or linking props * feature (extended search): handle color values, start Date handling * refactor (provide assertions and add comments) * refactor (webapi): Remove unused method. * feature (webapi): Add missing case in receive method. * refactor (webapi): Use a consistent naming convention for Akka routers for API V1 and V2 responders. - Add a router for PersistentMapResponderV2. * refactor (webapi): Use java.time.Instant for timestamps instead of java.time.OffsetDateTime. * feature (extended search V2): add more comparison operators to search for a date * tests (add tests for extended search v2): tests for user provided Sparql queries - in parallel, the same tests are added for v1 extended search * tests (extended search v2): add tests for date values - add the same tests for extended search v1 (same results expected) * refactor (remove redundant tests): remove redundant tests * feature (extended search v2): support Filter expressions with a logical operator (And, Or) * refactor (extended search v2): add assertions * test: Add tests for PersistentMapResponderV2. - Fix persistent map bugs. * test: Add copyright. * fix (webapi): Fix SPARQL bugs in persistent map code. * feature (extended search v2): support decimal and Boolean values * test: Disable v2 search tests for now, because they don't yet work with Fuseki. - Don't put knora-api.ttl in the triplestore, since we won't need to query it and it will be removed.
Since API v2 extended search needs to be implemented ASAP as part of #478, I'm going to try the approach I outlined here, i.e. implementing a simple DSL that the GUI can submit to the API, and that will be straightforward to translate to SPARQL. Tobias and I looked for something standard we could use, but didn't find anything that seemed suitable.
It should parse things like the following examples.
Find all the pages with sequence numbers less than or equal to 100, in books whose name contains either "Zeitglöcklein" and "Lebens" or "Itinerarius" and "peregrinarius":
Find a letter that has, either as its author or as its recipient, someone whose IAF identifier is either 123 or 456:
Perhaps I can adjust this syntax a bit and get a SPARQL parser to parse it. Otherwise, I'll look into using a parser generator such as ANTLR.
The text was updated successfully, but these errors were encountered: