A question about custom sentences

Please look at the following example from the official doc:

language: en
intents:
  GetLocked:
    data:
      - sentences:
          - is the door <state>
        requires_context:
          domain: binary_sensor
        expansion_rules:
          state: "{binary_state}"

      - sentences:
          - is the door <state>
        requires_context:
          domain: lock
        expansion_rules:
          state: "{lock_state}"

lists:
  binary_state:
    values:
      - in: "locked"
        out: "off"
      - in: "unlocked"
        out: "on"
  lock_state:
    values:
      - "locked"
      - "unlocked"

You can see that both of them require a specific context. But I can’t understand what happens here. My understanding is that:
step 1. People say “is the door locked?”
step 2. Then what??? How can HA deduce the current context just from that sentence and match the correct sentence?

If it matches the intent then the GetLocked reply is sent. Where is that defined?

I have no idea.

The question is I don’t know which one will be matched, if people say “is the door locked”?

      # first
      - sentences:
          - is the door <state>
        requires_context:
          domain: binary_sensor
        expansion_rules:
          state: "{binary_state}"
      #second
      - sentences:
          - is the door <state>
        requires_context:
          domain: lock
        expansion_rules:
          state: "{lock_state}"

That depends on what type of entity you have reporting the door state.

If it is a binary sensor then it will match the first one, if it is a lock then the second one.

What if I have both?

Another problem is these sentences only match “state”, then how can HA know which entity it should control? Both {lock_state} and {binary_state} are custom lists, I don’t think they have special meaning to HA.

Then it’s either a race or the first one. Either way the outcome is the same.

That intent does not offer control. It only tells you what the current state is. There will be another intent for control.