![]() |
LIMA
Libre Multilingual Analyzer — C++ API
|
Entities normalization by assigning different attributes or features (eg name / surname for people) is done heuristically in functions (NormalizePersonName in the people example) which are applied to the result of a rule. Normalization could also be done during the application of rules by exploiting some elements that are known (for example, for the recognition of people names, we use a list of known surnames).
A first implementation of this functionality is implemented with ConstraintFunction functions that are called during the application of the rules.
The following functions were defined:
An example of a rule:
@Firstname:[(@Title|@FunctionTitle)?]:(@Initial .?)? (T_A1|T_Amh|$NP){1-2}:PERSON:
+AddEntityFeature(trigger.1,"firstname")
+AddEntityFeature(left.1,"title")
+AddEntityFeature(right.2,"lastname")
=>NormalizeEntity()
=<ClearEntityFeatures()
In this rule, it is indicated that the trigger will be used as attribute "firstname". The previous word, if it is in a list of titles or known functions will be used as the "title" attribute. Following words, after an potential initial for the middle name will be associated with the attribute "lastname". The NormalizeEntity action is performed if the rule applies entirely.: This action assigns the retrieved attributes to the created entity. The ClearEntityFeatures action is performed if the rule fails. It deletes the stored attributes (if we do not do this action, the attributes will be kept for the next recognized entity).
The three functions are defined in the SpecificEntityConstraints.[h/cpp] file.
These functions are called during the application of the rules: at this time, the recognized entity (RecognizerMatch) is not available and we therefore can not directly associate attributes to it. The attributes are stored in a side structure and will be associated with the entity created when the rule application is over (and successful).
For temporary storage of attributes, you must put them in an AnalysisData: We use the RecognizerData, which already exists and is used to store temporary information on the application of the rules (manages the changes of the graph). It is added to an additional structure containing the attributes. The RecognizerData is a structure that is used temporarily while the rules: it is created at the beginning of the execution of an ApplyRecognizer process unit and removed at the end (so its lifetime is the application of a rules file).
The process is thus relatively simple:
This is a first implementation. Suppose we wants to apply the following rule:
@Firstname:[(@Title|@FunctionTitle)?]:(@Initial .?)? (T_A1|T_Amh|$NP){1-2}:PERSON:
+AddEntityFeature(trigger.1,"firstname")
+AddEntityFeature(left.1,"title")
+AddEntityFeature(right.1.1, right.1.2,"firstname")
+AddEntityFeature(right.2,"lastname")
=>NormalizeEntity()
=<ClearEntityFeatures()
There are still things to do:
As explained in the description of the process, the function AddEntityFeature is called during the application of the rules. When there is optional premise in the rule (a? or b*), the case exist where there is more than one possible match.
for example:
Gaspard P Monge can match P as initial and Monge as lastname or P as lastname and Monge as lastname.
The rule is applied to the longuest match (specification). But during the triggering, the function adEntityFeature is called more than one time.
During the triggering, function adEntityFeature is called more than one time. Once with the parameter P as firstname and a second one with the parameter P as lastname.
The better is to be able to call function addEntityFeature as a side effect of applying the rule, only for the node actuallly matching the rule as in the following example:
@Firstname:[(@Title|@FunctionTitle)?]:(@Initial .?)? (T_A1|T_Amh|$NP){1-2}:PERSON:
=>AddEntityFeature(trigger.1,"firstname")
=>AddEntityFeature(left.1,"title")
=>AddEntityFeature(right.1.1, right.1.2,"firstname")
=>AddEntityFeature(right.2,"lastname")
=>NormalizeEntity()
=<ClearEntityFeatures()