MANDATORY
Overview
The MANDATORY
operator is used to write sub-conditions that must trigger in a rule. This allows you to write a minor number of rules—or longer ones—each one triggering with more sentences that would normally require a higher number of rules.
For example:
SCOPE SENTENCE
{
IDENTIFY(PERSONAL_DATA)
{
@Name[TYPE(NPH)]
<1:3>
LEMMA("live", "have")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
MANDATORY
{
@Location_of_house[LEMMA("beach", "woods", "forest")],
@Location_of_house[ANCESTOR(100179164)], //unitary state,
LEMMA("city centre", "city center")
<1:3>
@Location_of_house[SYNCON(12631236, 100001781)]//@SYN: #12631236# [London] //@SYN: #100001781# [Budapest]
}
}
}
Note
If the MANDATORY
operator is introduced by sequences or operators, they will have to be inserted outside parenthesis. If such operator is succeded by sequences or operators, they will have to be inserted outside parenthesis.
The extraction rule above will trigger, if run against the following texts:
John has a big villa in the city center of Budapest.
John has a big villa in the woods.
John has a big villa in Italy.
Such sentences would normally require either three almost identical rules, with the only difference lying in the Location_of_house field, like the following case:
SCOPE SENTENCE
{
IDENTIFY(PERSONAL_DATA)
{
@Name[TYPE(NPH)
<1:3>
LEMMA("live", "have")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
@Location_of_house[LEMMA("beach", "woods", "forest")]
}
IDENTIFY(PERSONAL_DATA)
{
@Name[TYPE(NPH)
<1:3>
LEMMA("live", "have")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
@Location_of_house[ANCESTOR(100179164)] //unitary state
}
IDENTIFY(PERSONAL_DATA)
{
@Name[TYPE(NPH)
<1:3>
LEMMA("live", "have")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
@Location_of_house[SYNCON(12631236, 100001781)]//@SYN: #12631236# [London] //@SYN: #100001781# [Budapest]
}
}
or an extremely long rule with more OR
operators, like the following case:
SCOPE SENTENCE
{
IDENTIFY(PERSONAL_DATA)
{
@Name[TYPE(NPH)]
<1:3>
LEMMA("have", "live")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
@Location_of_house[LEMMA("beach", "woods", "forest")]
OR
@Name[TYPE(NPH)]
<1:3>
LEMMA("have", "live")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
@Location_of_house[ANCESTOR(100179164)] //unitary state
OR
@Name[TYPE(NPH)]
<1:3>
LEMMA("have", "live")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
@Location_of_house[SYNCON(12631236, 100001781)]//@SYN: #12631236# [London] //@SYN: #100001781# [Budapest]
}
}
The syntax for writing a MANDATORY
statement is the follwing:
operand
sequence/operator
MANDATORY
{
sub-condition
}
...
where MANDATORY
is in uppercase and can be placed wherever you need it in the rule.
There are a few things to remark in terms of functionalities of this operator:
- It is possible to use the same field multiple times.
- It is possible to insert a comma at the end of each attribute, as you can see in the example above. The comma acts like an
OR
operator between theMANDATORY
statements. - Unlike the
OPTIONAL
operator, it is possible to introduce theMANDATORY
operator with boolean operators.
Negation management inside MANDATORY
As stated in the example above, the comma (,
) at the end of each attribute inside a MANDATORY
statement acts as an OR
operator between them. The use of negations in combination with comma-separated attributes can be tricky.
For example, consider the following template and rule where all the attributes inside a MANDATORY
statement are negated and separated by a comma(,
):
TEMPLATE(HOUSE_OWNER)
{
@Name,
@Type_of_house
}
SCOPE SENTENCE
{
IDENTIFY(HOUSE_OWNER)
{
@Name[TYPE(NPH)]
<1:3>
LEMMA("live", "have", "buy")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
MANDATORY
{
!TYPE(NPH),
!LEMMA("city centre", "city center"),
!SYNCON(100001781)//@SYN: #100001781# [Budapest]
}
}
}
Even though there are negations inside the MANDATORY
statement, the rule will equally trigger in a sentence like this:
John bought a house with Mary in the city center of Budapest.
This happens because the rule above is equivalent to these three:
SCOPE SENTENCE
{
IDENTIFY(HOUSE_OWNER)
{
@Name[TYPE(NPH)]
<1:3>
LEMMA("live", "have", "buy")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
!LEMMA("city centre", "city center")
}
IDENTIFY(HOUSE_OWNER)
{
@Name[TYPE(NPH)]
<1:3>
LEMMA("live", "have", "buy")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
!TYPE(NPH)
}
IDENTIFY(HOUSE_OWNER)
{
@Name[TYPE(NPH)]
<1:3>
LEMMA("live", "have", "buy")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
!SYNCON(100001781)//@SYN: #100001781# [Budapest]
}
}
Two rules out of three will trigger because while an attribute of the initial MANDATORY
statement is negated in a rule, it is not in the other two, and the rule will trigger because of the common attribute and fields in all the rules.
The only way to negate a whole sequence of attributes is with positional sequences like this, without the MANDATORY
statement:
SCOPE SENTENCE
{
IDENTIFY(PERSONAL_DATA)
{
@Name[TYPE(NPH)]
<1:3>
LEMMA("live", "have", "buy")
<1:4>
@Type_of_house[LEMMA("house", "flat", "villa", "shotgun house")]
<1:3>
!TYPE(NPH)
<1:3>
!LEMMA("city centre", "city center")
<1:3>
!SYNCON(100001781)//@SYN: #100001781# [Budapest]
}
}