OBD:Query Objects

From NCBO Wiki

Jump to: navigation, search

Common retrieval operations for the OBD:Java API include:

These are simple to use, but relatively restricted. For more complex, freeform queries OBD provides expressive Query Objects (see QueryObject Pattern description). These allow for boolean queries as well as ontology and annotation based queries.

See:

The basic idea is that you would construct a QueryTerm object in java, and then feed that to one of the API calls that accepts query objects, such as getLinkStatementsByQuery. For the OBDSQL API, this gets translated to SQL. For RDFShard, it is translated to SPARQL. For an OBOSessionShard (over an obo or owl document(s)) in memory, the query is translated to an OBO filterquery.

Examples:

  • annotations to "abnormal leukocyte morphology"
 new AnnotationLinkQueryTerm("MP:0008246")

This simple example is a common query pattern, so there is a basic API call for this

  • annotations to a phenotype coming from a specific source
 q = new AnnotationLinkQueryTerm("MP:0008246")
 q.setSource("NCBO")
  • anything that is part of something that develops from the imaginal disc
   new LinkStatementQueryTerm(partOf,
           new LinkStatementQueryTerm(developsFrom, 
                     new LiteralStatementQueryTerm(NAME, "imaginal disc")))
  • anything size of heart or kidney phenotype
  QueryTerm heartOrKidneyQuery =
   new BooleanQueryTerm( 
     BooleanOperator.OR,
     new LinkQueryTerm(isA, "FMA:7088"),
     new LinkQueryTerm(isA, "FMA:7203"));
  QueryTerm sizeOfHeartOrKidneyQuery =
   new BooleanQueryTerm(
     BooleanOperator.AND,
     new LinkQueryTerm(isA,"PATO:0000117"),
     new LinkQueryTerm(heartOrKidneyQuery));


For more examples, see QueryTest

Query Grammar and RESTful URLs

At the moment the OBD RESTful URLs only support simple by-ID type requests. A few of the URL patterns allow for multiple IDs to be placed, separated by '+'s

For the RESTful URLs to support retrieval of result sets for complex descriptions we need a query grammar. This grammar needs to be context sensitive, i.e. nested expressions (so we cannot simply use http query params for query elements)

The grammar should closely match the QueryTerm java hierarchy

Draft of minimal subset:

 Query = LinkQuery | LiteralQuery | BooleanQuery | Atom
 Atom = QUOTE NONQUOTE* QUOTE | ID
 LinkQuery = 'link' OPEN { 'rel=' Query }? { 'target=' Query }? { 'source=' Query }? CLOSE
 LiteralQuery = Qualifier? Atom
 Qualifier = 'starts_with' | 'ends_with' | 'contains' | 'regex' | 'matches'
 BooleanQuery = BooleanOp OPEN Query+ Close
 BooleanOp = 'and' | 'or' | 'not'
 OPEN = '['
 CLOSE = ']'

Open question: is this pushing REST too far? We could simply have an XML specification of the query and pass that over POST

Open question: what about syntax for class expressions?

Personal tools