# OPTIONAL

## Overview

The `OPTIONAL` operator is used to write sub-conditions that can trigger or not in a rule. This allows you to write a minor number of rules, each one triggering with more sentences that would normally require a higher number of rules.

For example, these rules will trigger:

``````SCOPE SENTENCE
{
DOMAIN(dom1)
{
LEMMA("dog")
<1:5>
!LEMMA("good")
<1:2>
!LEMMA("boy")
}

DOMAIN(dom1)
{
LEMMA("dog")
<1:5>
LEMMA("good")
<1:2>
LEMMA("boy")
}
}
``````

if they are applied to the following sentences:

``````I have a beautiful dog.
My dog is really a good boy.
``````

Because of the second rule, you need to put negations (`!`) at the first rule.

With the `OPTIONAL` operator, you need a single rule:

``````SCOPE SENTENCE
{
DOMAIN(dom1)
{
LEMMA("dog")
OPTIONAL
{
<1:5>
LEMMA("good")
<1:2>
LEMMA("boy")
}
}
}
``````

Note

If the `OPTIONAL` operator is introduced by sequences or logical operators, they will have to be inserted inside parenthesis. If such operator is succeded by sequences or logical operators, they will have to be inserted outside parenthesis.

Warning

It is not possible to use boolean operators inside an `OPTIONAL` statement when writing a sub-condition.

The syntax of the `OPTIONAL` operator is the following:

``````operand
OPTIONAL
{
sub-condition
}
...``````

where `OPTIONAL` is in uppercase and can be placed wherever you need it in the rule.

One more complex example. This rule will trigger:

``````SCOPE SENTENCE
{
DOMAIN(dom1)
{
LEMMA("woman")
OPTIONAL
{
<1:3>
TYPE(PRE)
<1:3>
LEMMA("umbrella")
}
<1:3>
LEMMA("go")
<1:3>
LEMMA("cinema")
OPTIONAL
{
<1:2>
TYPE(PRE)
<1:3>
LEMMA("partner")
}
}
}
``````

if run against the following texts:

``````The woman went to the cinema.
The woman with the umbrella went to the cinema.
The woman went to the cinema with her partner.
The woman with the umbrella went to the cinema with her partner.
``````

because the optional sub-conditions allow the rule to trigger with or without them.

Normally, more specific rules with negations would be required—like the example above—to trigger in case of these sentences, because of all the various elements in each sentence, all of them enclosed in two `OPTIONAL` of a single rule.

## OPTIONAL attributes in OR

It is possible to define an logical OR relationship between attributes in the `OPTIONAL` operator using the comma as a separator.

This rule:

``````SCOPE SENTENCE
{
DOMAIN(dom1)
{
ROLE(SUBJECT)
&SV
TYPE(VER)
OPTIONAL
{
<1:6>
LEMMA("lottery"),
<1:6>
TYPE(MON)
}
}
}
``````

is equivalent to these three distinct rules:

``````SCOPE SENTENCE
{
DOMAIN(dom1)
{
ROLE(SUBJECT)
&SV
TYPE(VER)
}

DOMAIN(dom1)
{
ROLE(SUBJECT)
&SV
TYPE(VER)
<1:6>
LEMMA("lottery)
}

DOMAIN(dom1)
{
ROLE(SUBJECT)
&SV
TYPE(VER)
<1:6>
TYPE(MON)
}
}
``````

The rule above will trigger in texts like:

``````My father won the lottery.
My father won 1.000.000€.
My father won the lottery, 1.000.000€ all of a sudden.
``````