Extending SMTK’s Query Mechanism
Current Formats:
- Model Syntax
- Attribute Syntax - attribute[type =‘foo’]
So examples used in an association rule could look like:
<Resource Name="smtk::attribute::Resource" Filter="attribute[type='testDef']" />
<Resource Name="smtk::model::Resource" Filter="face[string{'pedigree'='zz'}]" />
What Needs to be Extended
- The ability to for queries on the resource side of the query so we can search based on properties on the resource
- The ability to have more than one predicate on the component side of the query
- Expand beyond always assuming the property is a vector
- The ability to make sure of parent child relationships that may exist among the components.
- Do we need the ability to search resources based on its name instead of its type?
- Side Note: In the attribute XML (and probably in the JSON format as well) - we use a Name key when in reality it should be a Type key
Possible XPATH derived Syntax
Instead of creating a new grammar John suggested that we should look at existing query grammars such as XPATH which is used to search HTML/XML structures. There is definitely some similarities between a SMTK resource structure and those for which XPATH was designed:
- Nodes in XML could be analogous to Persistent Objects
- Attributes (w/r XML) could be analogous to SMTK Properties
In terms of differences:
- XPATH was designed for trees and not general graphs - though if you treat the root as the resource itself then at least both do have a single root
- Assuming we do treat the resource as the root - then unlike XPATH we might want to put constraints on the root node (for example only consider those roots with certain properties
- XPATH attributes are uniquely defined by a name while SMTK Properties are uniquely defined by data structure and name so the simple @ syntax will not be enough.
Should the resource be part of the query?
Currently the Resource Manager is handed a string that refers to the type of resource. Using this, the manager matches the resource type either directly or by asking the resource if it is derived from it using the manager’s find method. Instead we could pass the manager a query string itself and have it return the result directly. This would involve delegating part of the query to the resource itself.
Else we will need to extend resource::Manager::find to be a resource query method.
Possible Syntax
- /[…] - refers to a resource that matches a set of predicates
- name=’…’ - resource name constraint
- type=’…’ - resource type constraint
- @[…] - property constraint
- name=’…’ property with name constraint
- type=’…’ property with type constraint
- val=’…’ property with value constraint
- constraints can be combined using and / or
- /res - resource of name = res - equivalent to /[name=‘res’]
- /res[…] - equivalent to /[name=‘res’ and …]
- /res//[…] - returns a set of components that match a set of constraints that are part of a resource named res
- name=’…’ - component name constraint
- type=’…’ - component type constraint
- @[…] - property constraint
- name=’…’ property with name constraint
- type=’…’ property with type constraint
- val=’…’ property with value constraint
- constraints can be combined using and / or
- a/b - refers to all components named b that is a child of component named a
Possible Examples
- /res - refers to the resource named res
- /res//alpha - the component named alpha under resource named res
- /res//alpha/beta - the component named beta whose parent is named alpha that is part of resource res
- /[type=‘smtk::model::Resource’]//[type=‘face’] - all faces that are part of resources of type model
- /[type=‘smtk::model::Resource’ and @[name=‘alpha’ and type=‘string’ and val=‘a’]//[type=‘face’] - all faces that are part of resources of type model that contains a string property call alpha whose value is a.
- /[type=‘smtk::attribute::Resource’ and @[name=‘alpha’ and type=‘string’ and val=‘a’]//[type=‘attribute’ and @[name=‘beta’] - all attributes that have a property called beta and that are part of resources of type attribute that contains a string property call alpha whose value is a.