Home   :   Matrix Language   :   Primitive Action Statements   :   Context Selection Statements

Context Selection Statements

 

Statements

 

    SelectionHead

    SelectionTail

    SelectionInit

    SelectionLast

 

 

Overview

 

Context selection statements can be used to select objects through an ordered relationship when used within a TraverseSelection subregion.  They can also be used to select objects that belong to an entity when used within an EntitySelection subregion.

 

They do not change the context but merely reduce the number of objects to be processed.

 

These are typically used to find one object or the first or last object of some list determined by an ordered relationship.

 

It is possible to combine context selection statements to give other object selections.

 

 

SelectionHead

 

    SelectionHead

 

This statement will return the first object found.

 

 

SelectionTail

 

    SelectionTail

 

This statement will return all objects except the first.

 

 

SelectionInit

 

    SelectionInit

 

This statement will return all objects except the last.

 

 

SelectionLast

 

    SelectionLast

 

This statement will return the last object found.

 

 

Statement Interaction

 

Various statement pairs are possible, although not all give useful results.

 

Some pairs return identical objects to other pairs.  This duplication is retained for reasons of symmetry.

 

In the tables below assume the following entities: Small, Regular and Large with the following number of objects:

 

    Large             Regular          Small

    ~~~~~~~~~~        ~~~~~~~~~        ~~~~~~~~~~

    First  (F)        First (F)        Single (S)

    Middle (M)        Last  (L)

    Last   (L)

 

 

Single Statement Selection

 

The table below summarises the objects returned for each statement:

 

    Single     Context Selection  Large  Regular  Small  Returns

    ~~~~~~~~~  ~~~~~~~~~~~~~~~~~  ~~~~~  ~~~~~~~  ~~~~~  ~~~~~~~

    HEAD       SelectionHead        F         F       S   Always

    TAIL       SelectionTail         ML        L      :     >= 2

    INIT       SelectionInit        FM        F       :     >= 2

    LAST       SelectionLast          L        L      S   Always

 

 

Paired Statement Selection

 

The table below summarises the objects returned for each pair of statements:

 

    Pair       Context Selection  Large  Regular  Small  Returns

    ~~~~~~~~~  ~~~~~~~~~~~~~~~~~  ~~~~~  ~~~~~~~  ~~~~~  ~~~~~~~

    HEAD+INIT  SelectionHead        F         F       :     >= 2

                   SelectionInit

    HEAD+LAST  SelectionHead        :::       ::      S     == 1

                   SelectionLast

    TAIL+INIT  SelectionTail         M        ::      :     >= 3

                   SelectionInit

    TAIL+LAST  SelectionTail          L        L      :     >= 2

                   SelectionLast

    ~~~~~~~~~  ~~~~~~~~~~~~~~~~~  ~~~~~  ~~~~~~~  ~~~~~  ~~~~~~~

    INIT+HEAD  SelectionInit        F         F       :     >= 2

                   SelectionHead

    INIT+TAIL  SelectionInit         M        ::      :     >= 3

                   SelectionTail

    LAST+HEAD  SelectionLast        :::       ::      S     == 1

                   SelectionHead

    LAST+TAIL  SelectionLast          L        L      :     >= 2

                   SelectionTail

 

 

Pair Interaction Summary

 

    Entity Containing 3 Objects Returns:

        HEAD+INIT & INIT+HEAD -> First

        TAIL+INIT & INIT+TAIL -> Middle

        TAIL+LAST & LAST+TAIL -> Last

 

    Entity Containing 2 Objects Returns:

        HEAD+INIT & INIT+HEAD -> First

        TAIL+LAST & LAST+TAIL -> Last

 

    Entity Containing 1 Object Returns:

        HEAD+LAST & LAST+HEAD -> Single

 

Other pairings return no objects.

 

 

Context Selection Examples

 

    EntitySelection:Dog

        Selection

            SelectionHead

                |

                | first or single object returned

 

 

    Traverse

        Navigation

            Customer : Owns : Account

        TraverseSelection

            SelectionHead

                SelectionLast

                    GenerateEvent

                        Customer : Last_account_closed

 

 

    | Full Set

    |

    EntitySelection:Dog

        Selection

            | all dogs

            SelectionHead

                | first dog

                SelectionInit

                    | first dog

                SelectionLast

                    | single dog

            SelectionTail

                | middle and last dogs

                SelectionInit

                    | middle dogs

                SelectionLast

                    | last dog

            SelectionInit

                | first and middle dogs

                SelectionHead

                    | first dog

                SelectionTail

                    | middle dogs

            SelectionLast

                | last dog

                SelectionHead

                    | single dog

                SelectionTail

                    | last dog

 

 

    | Minimum Set

    |

    EntitySelection:Dog

        Selection

            | all dogs

            SelectionHead

                | first dog

                SelectionLast

                    | single dog

            SelectionTail

                | middle and last dogs

                SelectionInit

                    | middle dogs

            SelectionInit

                | first and middle dogs

            SelectionLast

                | last dog

Copyright © 2017 Dark Matter Systems Ltd. All Rights Reserved.