Query using named parameters

Fixed value variables used in a query can be made modifible in the Queries window. The following illustrates how to do this with an example.

Double click family.flr to load it into the Text Editor. Add the following rule and query to the file:

hasChildren(?Person, ?NumberChildren) :- numberOfChildren(?Person, ?NumberChildren).

@!{'Who has 1 child?'(?Person)} !- hasChildren(?Person, 1).

The above rule counts how many children a person has, and the query returns individuals who have 1 child. Note that the query has a fixed input value of 1 for variable ?NumberChildren.

New rule and query added to family.flr

Fig. 200 New rule and query added to family.flr

Save the file family.flr. This can be done using option File > Save or the Save button from the main navigation menu. Launch the Queries plugin by clicking the Queries tab. Select ’Who has 1 child?’ from the list. Click Parameters and there is no property which can be modified.

No property can be modified for query ’Who has 1 child?’

Fig. 201 No property can be modified for query ’Who has 1 child?’

Execute the query. Results returned in the Query Results window are individuals with 1 child.

Results for individuals with **1** child

Fig. 202 Results for individuals with 1 child

Now the same query can be made to find out who has 2 or other number of children. In other words, we can turn 1 into a variable so that it can be modified when the query is run. We accomplish this by adding the following new rule and new query:

hasChildrenNamed(Person -> ?Person, NumberChildren -> ?NumberChildren) :-
    hasChildren(?Person, ?NumberChildren).

@!{'Who has 1 child? - Named'(?Person)} !- hasChildrenNamed(Person -> ?Person, NumberChildren -> 1).
Named rule and query added to family.flr

Fig. 203 Named rule and query added to family.flr

The above new rule is exactly the same as the old, except the variables ?Person and ?NumberChildren are now named, and the new query makes use of the new rule instead of the old.

Save the new rule and query to family.flr. In Queries, select ’Who has 1 child? - Named’. Click Parameters. Both Person and NumberChildren show up as properties which can be modified in their respective Modified Value fields before query execution.

Properties **Person** and **NumberChildren** can be modified for query ’Who has 1 child? - Named’

Fig. 204 Properties Person and NumberChildren can be modified for query ’Who has 1 child? - Named’

Click the Modified Value field for NumberChildren and type in 2, as shown in Fig. 205.

Change parameter value of NumberChildren from 1 to 2

Fig. 205 Change parameter value of NumberChildren from 1 to 2

Then Execute the query. Results returned in Query Results show all individuals who have 2 children.

Results for individuals with **2** children

Fig. 206 Results for individuals with 2 children