.. _section-Query using named parameters: 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: .. code-block:: flora 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**. .. figure:: ../../figs/Queries-rule-query.png :alt: New rule and query added to family.flr 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. .. figure:: ../../figs/Queries-rule-query-property-fixed.png :alt: No property can be modified for query ’Who has 1 child?’ 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. .. figure:: ../../figs/Queries-results-1-child.png :alt: Results for individuals with **1** child 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: .. code-block:: flora hasChildrenNamed(Person -> ?Person, NumberChildren -> ?NumberChildren) :- hasChildren(?Person, ?NumberChildren). @!{'Who has 1 child? - Named'(?Person)} !- hasChildrenNamed(Person -> ?Person, NumberChildren -> 1). .. figure:: ../../figs/Queries-named-rule-query.png :alt: Named rule and query added to family.flr 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. .. figure:: ../../figs/Queries-rule-query-property-changeable.png :alt: Properties **Person** and **NumberChildren** can be modified for query ’Who has 1 child? - Named’ 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 :numref:`figure-Queries-input-2-children.png`. .. _figure-Queries-input-2-children.png: .. figure:: ../../figs/Queries-input-2-children.png :alt: Change parameter value of NumberChildren from 1 to 2 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. .. figure:: ../../figs/Queries-results-2-children.png :alt: Results for individuals with **2** children Results for individuals with **2** children