Filters#
Filters are a special kind of rule that remove unwanted results. Filters are very useful because they can deal with exceptions, which are very common in languages: you can make a general rule, and then filter the exceptions.
Filters look like annotations, where the attribute concept points to the annotation that needs to be filtered out:
Syntax:
wow::filter@(concept=”annotation”)
Example:
lexicon : { apple, kiwi, melon } = Fruit;
rule :
{
"Adam" "\'s"
{ "apple" } = wow::filter@(concept="Fruit")
};
“He has an apple and a big Adam’s apple”
{Sentence
t(0,2) "He" (init-cap, init-token)['he':Pron-Pers]
t(3,6) "has" ['have':V-Pres-3-Sg-have]
t(7,9) "an" ['a':Det-Indef]
{Fruit
t(10,15) "apple" ['apple':Nn-Sg]
}Fruit
t(16,19) "and" ['and':Conj-Coord]
t(20,21) "a" ['a':Det-Indef]
t(22,25) "big" ['big':Adj-Std]
t(26,30) "Adam" (init-cap)['Adam':Prop-Std, +giv]
t(30,32) "'s" [''s':Part-Poss]
t(33,38) "apple" ['apple':Nn-Sg]
}Sentence
You can also use regular expressions in your filters (ECMAScript regex notation):
lexicon:
{
chicken
} = Poultry_Animal;
lexicon:
{
salmon
} = Fish_Animal;
// chicken pie is no animal
rule:
{
<>
'pie'
} = wow::filter@(concept=/.*Animal/);
Try:
wow -p english,rules -i “I like chicken, I like salmon, I like chicken pie and salmon pie.”
Output:
t(0,1) “I” (init-token)[‘I’:Pron-Pers]t(2,6) “like” [‘like’:V-Pres, +inf, +positive]{ Poultry_Animalt(7,14) “chicken” [‘chicken’:Nn-Sg]} Poultry_Animalt(14,15) “,” [‘,’:Punct-Comma]t(16,17) “I” [‘I’:Pron-Pers]t(18,22) “like” [‘like’:V-Pres, +inf, +positive]{ Fish_Animalt(23,29) “salmon” [‘salmon’:Nn-Sg]} Fish_Animalt(29,30) “,” [‘,’:Punct-Comma]t(31,32) “I” [‘I’:Pron-Pers]t(33,37) “like” [‘like’:V-Pres, +inf, +positive]t(38,45) “chicken” [‘chicken’:Nn-Sg]t(46,49) “pie” [‘pie’:Nn-Sg]t(50,53) “and” [‘and’:Conj-Coord]t(54,60) “salmon” [‘salmon’:Nn-Sg]t(61,64) “pie” [‘pie’:Nn-Sg]t(64,65) “.” [‘.’:Punct-Sent]
As you can see “chicken” and “salmon” when followed by pie are no longer found as animals.
Note as well that the filter can function on a bigger scope than the annotation itself, it takes all annotations of type “concept” from the capture and filters them out.
You can also delete attributes, without deleting the concepts:
wow::filter@(concept=”name_of_concept”,name_of_attribute=”value”)
This can be very useful to fine-tune results. For instance, in the sentence:
Alexandria , Virginia
We get that Alexandria is a City in Egypt, but the context shows that in this case, it refers to a city in the USA.
To fix it, we can use the following rule:
rule:
{
{
City
} = wow::filter@(concept="City",country=/(?!USA).+/)
<'\,'>
USState
};
Because of the context (we have a USState), we want to get rid of all countries that are not USA, to do that we use the regular expression: /(?!USA).+/
City -> Alexandria @ country=USA;