Creating a Query Rule and Workflow

It is a common task to query your graph for certain elements. This can easily be done using the interactive Smart Selector tool. However, you might want to include a query in a rule, in a sequence or in a workflow. This article will show an example how to realize this task.

1. Create a query rule

First we create a rule that looks for graph elements that match our query term. In the following example the search term is of the primitive type string and the rule looks for nodes that contain the search term either in their id property or in their name property. If a match is found a line of text is emitted to the Output Pad.

rule findQueryRelatedNodes (var qterm:string): {
   n:Node; //pick a MyNode
   if{( != -1 ||   //if the queried string is contained in id (indexOf used to check for containment, toLower used to make the query term case-insensitive) != -1 ;}    //or in name
      emit("MyNode " + + " matches query.\n");    //then emit this line

By using the string operation indexOf the search term does not need to match the id or name property but only needs to be contained to result in a match.

By using the string operation toLower for the search term and the properties the query term becomes case-insensitive.

2. Create a query workflow

To create a query workflow, where a user can enter a search term as workflow argument and then click on run to retrieve all answers that match the term, we need to proceed as follows.

  1. Create a new workflow, as explained in this article.
  2. Create a new argument in the Arguments tab for the search term, e.g. Name: query_term, Direction:In, Argument type:String, Default value: “SomeDefaultQueryTerm”
  3. In the workflow activity Run Transformation call the rule or sequence that expects the query term as input parameter. Using the rule we created before (see above), the Run Transformation field would read as follows:

After building the project and selecting the workflow in the Workflow Launcher Pad you will see an argument field that can be used to enter a query term, as shown in this image:

Example of a wrokflow with an argument field used to run a query on a data graph.

Et voilá, you have created a workflow that allows a user to run a query on a data graph. You can, of course, make this more advanced, e.g. to reduce a data graph to only those elements that match your query, etc. .

Was this article helpful?

Related Articles