LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
Lima::LinguisticProcessing::Automaton::Recognizer Class Reference

␈rief a class for the definition of a complete recognizer More...

#include <linguisticProcessing/core/Automaton/recognizer.h>

Inheritance diagram for Lima::LinguisticProcessing::Automaton::Recognizer:
Lima::LinguisticProcessing::AbstractResource Lima::LinguisticProcessing::AbstractResourceBase Lima::InitializableObject< AbstractResource, ResourceInitializationParameters >

Classes

class  CompareTriggerRule
 
class  TriggerRule
 

Public Member Functions

 Recognizer ()
 
 Recognizer (const Recognizer &)
 
virtual ~Recognizer ()
 
Recognizer & operator= (const Recognizer &)
 
void init (Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
 initialize with parameters from configuration file.
 
uint64_t numberOfRules () const
 
uint64_t addRuleInStorage (Rule *rule)
 add a rule in the storage zone
 
uint64_t addRule (TransitionUnit *trigger, Rule *rule)
 add a rule in the recognizer : add the rule in the storage zone, and associate the trigger to the rule find if the trigger already exists in the trigger list : if it is the case, add the rule in rules associated to this trigger, else add a new trigger (copy of the one in argument) and associate the rule to it.
 
void addRule (TransitionUnit *trigger, const uint64_t index)
 associate a known rule to a trigger (the rule is identified by its index in the storage zone)
 
uint64_t apply (const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &begin, const LinguisticGraphVertex &end, AnalysisContent &analysis, std::vector< RecognizerMatch > &result, bool testAllVertices=false, bool stopAtFirstSuccess=true, bool onlyOneSuccessPerType=false, bool returnAtFirstSuccess=false, bool applySameRuleWhileSuccess=false) const
 apply the recognizer on a graph
 
uint64_t apply (const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &begin, const LinguisticGraphVertex &end, const LinguisticGraphVertex &upstreamBound, const LinguisticGraphVertex &downstreamBound, AnalysisContent &analysis, std::vector< RecognizerMatch > &result, bool testAllVertices, bool stopAtFirstSuccess, bool onlyOneSuccessPerType, bool returnAtFirstSuccess, bool applySameRuleWhileSuccess) const
 apply the recognizer on a graph between two nodes and search between two others.
 
uint64_t testOnVertex (const LinguisticAnalysisStructure::AnalysisGraph &graph, LinguisticGraphVertex &current, const LinguisticGraphVertex &begin, const LinguisticGraphVertex &end, AnalysisContent &analysis, std::vector< RecognizerMatch > &result, bool stopAtFirstSuccess=true, bool onlyOneSuccessPerType=false, bool applySameRuleWhileSuccess=false) const
 test the recognizer on a given vertex : check if this vertex is a trigger and if a rule applies, add the result to the vector given as parameter (takes the first rule which gives a match)
 
uint64_t resolveOverlappingEntities (std::vector< RecognizerMatch > &listEntities, const OverlapResolutionStrategy &strategy=DEFAULT_OVERLAP_STRATEGY) const
 resolve the problem of overlapping entities in the list of entities : when two entities are overlaping, only one is kept
 
uint64_t testSetOfRules (const TransitionUnit &trigger, const SetOfRules &rules, const LinguisticAnalysisStructure::AnalysisGraph &graph, const LinguisticGraphVertex &position, const LinguisticGraphVertex &begin, const LinguisticGraphVertex &end, AnalysisContent &analysis, std::vector< RecognizerMatch > &match, std::set< Common::MediaticData::EntityType > *forbiddenTypes=0, bool stopAtFirstSuccess=true, bool onlyOneSuccessPerType=false, bool applySameRuleWhileSuccess=false) const
 TODO: toBeDeleted Parse tokens paths from the trigger point.
 
void listTriggers () const
 
void initializeSearchStructure ()
 
- Public Member Functions inherited from Lima::LinguisticProcessing::AbstractResource
 AbstractResource (QObject *parent=0)
 
virtual ~AbstractResource ()
 
 AbstractResource (const AbstractResource &)
 
- Public Member Functions inherited from Lima::LinguisticProcessing::AbstractResourceBase
 AbstractResourceBase (QObject *parent=0)
 
virtual ~AbstractResourceBase ()
 
 AbstractResourceBase (const AbstractResourceBase &)
 
QString getResourceFileName (const QString &paramName)
 
- Public Member Functions inherited from Lima::InitializableObject< AbstractResource, ResourceInitializationParameters >
 InitializableObject ()
 
 InitializableObject (const InitializableObject &object)
 
InitializableObject & operator= (const InitializableObject &object)
 
virtual ~InitializableObject ()
 
const std::string & getId () const
 get the object id
 
void setId (const std::string &id)
 set the object id
 

Protected Member Functions

void clearSearchStructure ()
 
void findNextSetOfRules (const LinguisticAnalysisStructure::AnalysisGraph &graph, LinguisticGraphVertex &vertex, AnalysisContent &analysis, const LinguisticAnalysisStructure::Token *token, const LinguisticAnalysisStructure::MorphoSyntacticData *data, std::vector< TriggerRule * > &matchingSetOfRules) const
 
void init ()
 
void copy (const Recognizer &a)
 
void freeMem ()
 
void setNormalizedForm (const LimaString &norm, RecognizerMatch &match) const
 
uint64_t findRuleIndex (Rule *) const
 
- Protected Member Functions inherited from Lima::LinguisticProcessing::AbstractResourceBase
LimaFileSystemWatcher & resourceFileWatcher ()
 Accessor to the file watcher used to register resource files to be watched for changes.
 

Protected Attributes

std::vector< TriggerRule > m_rules
 
SetOfRules m_ruleStorage
 
MediaId m_language
 
AutomatonControlParams m_automatonControlParams
 parameters to control the search of the automaton
 
std::string m_filename
 
TransitionSearchStructure< TriggerRule > m_searchStructure
 
- Protected Attributes inherited from Lima::LinguisticProcessing::AbstractResourceBase
AbstractResourceBasePrivate * m_d
 
- Protected Attributes inherited from Lima::InitializableObject< AbstractResource, ResourceInitializationParameters >
std::string m_id
 

Friends

class AutomatonReader
 
class AutomatonWriter
 
LIMA_AUTOMATON_EXPORT std::ostream & operator<< (std::ostream &, const Recognizer &)
 

Additional Inherited Members

- Public Types inherited from Lima::InitializableObject< AbstractResource, ResourceInitializationParameters >
typedef InitializableObjectManager< AbstractResource, ResourceInitializationParameters > Manager
 Manager is the type of the Manager associated to the initializableObject.
 
typedef InitializableObjectFactory< AbstractResource > Factory
 Factory is the type of the Factory associated to the initializableObject.
 
- Signals inherited from Lima::LinguisticProcessing::AbstractResourceBase
void resourceFileChanged (const QString &path)
 Signal triggered whenever one of the registered files changes on disk.
 

Detailed Description

␈rief a class for the definition of a complete recognizer

this class is used for the description of a complete recognizer, i.e. a set of rules

Definition at line 77 of file recognizer.h.

Constructor & Destructor Documentation

◆ Recognizer() [1/2]

Lima::LinguisticProcessing::Automaton::Recognizer::Recognizer ( )

Definition at line 71 of file recognizer.cpp.

◆ Recognizer() [2/2]

Lima::LinguisticProcessing::Automaton::Recognizer::Recognizer ( const Recognizer &  r)

Definition at line 82 of file recognizer.cpp.

◆ ~Recognizer()

Lima::LinguisticProcessing::Automaton::Recognizer::~Recognizer ( )
virtual

Definition at line 99 of file recognizer.cpp.

Member Function Documentation

◆ addRule() [1/2]

void Lima::LinguisticProcessing::Automaton::Recognizer::addRule ( TransitionUnit *  trigger,
const uint64_t  index 
)

associate a known rule to a trigger (the rule is identified by its index in the storage zone)

Parameters
triggerthe trigger
indexthe index of the rule in the storage zone

Definition at line 1062 of file recognizer.cpp.

◆ addRule() [2/2]

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::addRule ( TransitionUnit *  trigger,
Rule *  rule 
)

add a rule in the recognizer : add the rule in the storage zone, and associate the trigger to the rule find if the trigger already exists in the trigger list : if it is the case, add the rule in rules associated to this trigger, else add a new trigger (copy of the one in argument) and associate the rule to it.

Parameters
triggerthe trigger of the rule
rulethe rule
Returns
the index of the rule in the storage zone

Definition at line 1043 of file recognizer.cpp.

◆ addRuleInStorage()

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::addRuleInStorage ( Rule *  rule)

add a rule in the storage zone

Parameters
rulethe rule to add
Returns
the index of the rule in the storage zone

Definition at line 1035 of file recognizer.cpp.

◆ apply() [1/2]

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::apply ( const LinguisticAnalysisStructure::AnalysisGraph &  graph,
const LinguisticGraphVertex &  begin,
const LinguisticGraphVertex &  end,
AnalysisContent &  analysis,
std::vector< RecognizerMatch > &  result,
bool  testAllVertices = false,
bool  stopAtFirstSuccess = true,
bool  onlyOneSuccessPerType = false,
bool  returnAtFirstSuccess = false,
bool  applySameRuleWhileSuccess = false 
) const

apply the recognizer on a graph

Parameters
graphthe graph
beginthe first node to test (is also limit of the left context)
endthe last node to test (is also limit of the right context)
analysisthe content of the analysis (may be modified)
resultthe results
testAllVerticesif true, test all vertices, otherwise, skip recognized expressions
stopAtFirstSuccessif true, stop testing rules on the current node after one rule succeeded
onlyOneSuccessPerTypeif true, stop testing rules with same type as a previously successful rule (only used if stopAtFirstSuccess is false)
returnAtFirstSuccessif true, abort the search as soon a rule is successful (if true, stopAtFirstSuccess will be set to true)
applySameRuleWhileSuccessif true, when a rule succeeds, retry to apply it on same vertex until the rule does not apply (use with care: setting this argument to true may cause loops if* rules are not well written). Will not apply if stopAtFirstSuccess.
Returns
number of rules successfuly applied

Definition at line 615 of file recognizer.cpp.

◆ apply() [2/2]

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::apply ( const LinguisticAnalysisStructure::AnalysisGraph &  graph,
const LinguisticGraphVertex &  begin,
const LinguisticGraphVertex &  end,
const LinguisticGraphVertex &  upstreamBound,
const LinguisticGraphVertex &  downstreamBound,
AnalysisContent &  analysis,
std::vector< RecognizerMatch > &  result,
bool  testAllVertices,
bool  stopAtFirstSuccess,
bool  onlyOneSuccessPerType,
bool  returnAtFirstSuccess,
bool  applySameRuleWhileSuccess 
) const

apply the recognizer on a graph between two nodes and search between two others.

precondition: [begin, end] included in [upstreamBound,downstreamBound]

Parameters
graphthe graph
beginthe first node to test (is not the limit of the left context)
endthe last node to test (is not the limit of the right context)
upstreamBoundthe limit of the left context)
downstreamBoundthe limit of the right context)
analysisthe content of the analysis (may be modified)
resultthe results
testAllVerticesif true, test all vertices, otherwise, skip recognized expressions
stopAtFirstSuccessif true, stop testing rules after one rule succeeded
onlyOneSuccessPerTypeif true, stop testing rules with same type as a previously successful rule (only used if stopAtFirstSuccess is false)
returnAtFirstSuccessif true, abort the search as soon a rule is successful (if true, stopAtFirstSuccess will be set to true)
applySameRuleWhileSuccessif true, when a rule succeeds, retry to apply it on same vertex until the rule does not apply (use with care: setting this argument to true may cause loops if* rules are not well written). Will not apply if stopAtFirstSuccess.
Returns
number of rules successfuly applied

Definition at line 643 of file recognizer.cpp.

◆ clearSearchStructure()

void Lima::LinguisticProcessing::Automaton::Recognizer::clearSearchStructure ( )
protected

Definition at line 1028 of file recognizer.cpp.

◆ copy()

void Lima::LinguisticProcessing::Automaton::Recognizer::copy ( const Recognizer &  a)
protected

Definition at line 250 of file recognizer.cpp.

◆ findNextSetOfRules()

void Lima::LinguisticProcessing::Automaton::Recognizer::findNextSetOfRules ( const LinguisticAnalysisStructure::AnalysisGraph &  graph,
LinguisticGraphVertex &  vertex,
AnalysisContent &  analysis,
const LinguisticAnalysisStructure::Token *  token,
const LinguisticAnalysisStructure::MorphoSyntacticData *  data,
std::vector< TriggerRule * > &  matchingSetOfRules 
) const
protected

Definition at line 972 of file recognizer.cpp.

◆ findRuleIndex()

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::findRuleIndex ( Rule *  r) const
protected

Definition at line 1086 of file recognizer.cpp.

◆ freeMem()

void Lima::LinguisticProcessing::Automaton::Recognizer::freeMem ( )
protected

Definition at line 276 of file recognizer.cpp.

◆ init() [1/2]

void Lima::LinguisticProcessing::Automaton::Recognizer::init ( )
protected

Definition at line 242 of file recognizer.cpp.

◆ init() [2/2]

void Lima::LinguisticProcessing::Automaton::Recognizer::init ( Common::XMLConfigurationFiles::GroupConfigurationStructure &  unitConfiguration,
Manager *  manager 
)
overridevirtual

initialize with parameters from configuration file.

Parameters
unitConfiguration@IN : <group> tag in xml configuration file that contains parameters to initialize the object.
manager@IN : manager that asked for initialization and carries parameters.
Exceptions
InvalidConfigurationwhen parameters are invalids.

Implements Lima::LinguisticProcessing::AbstractResource.

◆ initializeSearchStructure()

void Lima::LinguisticProcessing::Automaton::Recognizer::initializeSearchStructure ( )

Definition at line 1018 of file recognizer.cpp.

◆ listTriggers()

void Lima::LinguisticProcessing::Automaton::Recognizer::listTriggers ( ) const

Definition at line 1101 of file recognizer.cpp.

◆ numberOfRules()

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::numberOfRules ( ) const
inline

Definition at line 373 of file recognizer.h.

◆ operator=()

Recognizer & Lima::LinguisticProcessing::Automaton::Recognizer::operator= ( const Recognizer &  r)

Definition at line 108 of file recognizer.cpp.

◆ resolveOverlappingEntities()

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::resolveOverlappingEntities ( std::vector< RecognizerMatch > &  listEntities,
const OverlapResolutionStrategy &  strategy = DEFAULT_OVERLAP_STRATEGY 
) const

resolve the problem of overlapping entities in the list of entities : when two entities are overlaping, only one is kept

Parameters
strategythe strategy to use : IGNORE_FIRST will simply ignore the first entity IGNORE_SECOND will simply ignore the second entity IGNORE_SMALLEST will ignore the entity that covers the less words
Returns
the number of overlapping entities removed

Definition at line 890 of file recognizer.cpp.

◆ setNormalizedForm()

void Lima::LinguisticProcessing::Automaton::Recognizer::setNormalizedForm ( const LimaString &  norm,
RecognizerMatch &  match 
) const
protected

Definition at line 594 of file recognizer.cpp.

◆ testOnVertex()

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::testOnVertex ( const LinguisticAnalysisStructure::AnalysisGraph &  graph,
LinguisticGraphVertex &  current,
const LinguisticGraphVertex &  begin,
const LinguisticGraphVertex &  end,
AnalysisContent &  analysis,
std::vector< RecognizerMatch > &  result,
bool  stopAtFirstSuccess = true,
bool  onlyOneSuccessPerType = false,
bool  applySameRuleWhileSuccess = false 
) const

test the recognizer on a given vertex : check if this vertex is a trigger and if a rule applies, add the result to the vector given as parameter (takes the first rule which gives a match)

Parameters
graphthe graph
currentthe current vertex to test
beginthe limit on the left of the current vertex
endthe limit on the right of the current vertex
resultthe vector in which the result is stored
Returns
true if a match was found, false otherwise

Definition at line 814 of file recognizer.cpp.

◆ testSetOfRules()

uint64_t Lima::LinguisticProcessing::Automaton::Recognizer::testSetOfRules ( const TransitionUnit &  trigger,
const SetOfRules &  rules,
const LinguisticAnalysisStructure::AnalysisGraph &  graph,
const LinguisticGraphVertex &  position,
const LinguisticGraphVertex &  begin,
const LinguisticGraphVertex &  end,
AnalysisContent &  analysis,
std::vector< RecognizerMatch > &  match,
std::set< Common::MediaticData::EntityType > *  forbiddenTypes = 0,
bool  stopAtFirstSuccess = true,
bool  onlyOneSuccessPerType = false,
bool  applySameRuleWhileSuccess = false 
) const

TODO: toBeDeleted Parse tokens paths from the trigger point.

Parameters
triggerToken: the token that triggered the rules
graph: the graph of the analysis
current: the vertex in the graph corresponding to the trigger
offset: the offset of the set of rules to test
results: the output
Returns
true if match, false otherwise bool parse(const LinguisticAnalysisStructure::Token& triggerToken, const LinguisticAnalysisStructure::AnalysisGraph& graph, const LinguisticGraphVertex& current, uint64_t offset, AnalysisContent& analysis, RecognizerMatch& result) const; test a given set of rules of the recognizer on a text, at a position given by a LinguisticAnalysisStructure::AnalysisGraph
Parameters
triggerthe TransitionUnit corresponding to the trigger
rulesthe set of rules to test
positionthe position in the text from with to test
matchthe resulting match (if success)
forbiddenTypesif not 0, contains the types currently not permitted for the current trigger (in case of negative rules); updated when leaving the function
stopAtFirstSuccessif true, stop testing rules after one rule succeeded
applySameRuleWhileSuccessif true, when a rule succeeds, retry to apply it on same vertex until the rule does not apply (use with care: setting this argument to true may cause loops if* rules are not well written). Will not apply if stopAtFirstSuccess.
Returns
true if there is a match : the reference arguments match and rule contain in this case the resulting match and the rule for wich the test has succeeded the match can be a MultipleMatch or a PIMultipleMatch

Definition at line 325 of file recognizer.cpp.

Friends And Related Symbol Documentation

◆ AutomatonReader

friend class AutomatonReader
friend

Definition at line 81 of file recognizer.h.

◆ AutomatonWriter

friend class AutomatonWriter
friend

Definition at line 82 of file recognizer.h.

◆ operator<<

LIMA_AUTOMATON_EXPORT std::ostream & operator<< ( std::ostream &  os,
const Recognizer &  r 
)
friend

Definition at line 1113 of file recognizer.cpp.

Member Data Documentation

◆ m_automatonControlParams

AutomatonControlParams Lima::LinguisticProcessing::Automaton::Recognizer::m_automatonControlParams
protected

parameters to control the search of the automaton

Definition at line 337 of file recognizer.h.

◆ m_filename

std::string Lima::LinguisticProcessing::Automaton::Recognizer::m_filename
protected

Definition at line 340 of file recognizer.h.

◆ m_language

MediaId Lima::LinguisticProcessing::Automaton::Recognizer::m_language
protected

Definition at line 334 of file recognizer.h.

◆ m_rules

std::vector<TriggerRule> Lima::LinguisticProcessing::Automaton::Recognizer::m_rules
protected

Definition at line 330 of file recognizer.h.

◆ m_ruleStorage

SetOfRules Lima::LinguisticProcessing::Automaton::Recognizer::m_ruleStorage
protected

Definition at line 331 of file recognizer.h.

◆ m_searchStructure

TransitionSearchStructure<TriggerRule> Lima::LinguisticProcessing::Automaton::Recognizer::m_searchStructure
protected

Definition at line 344 of file recognizer.h.


The documentation for this class was generated from the following files: