LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
CoreferenceEngine.cpp
Go to the documentation of this file.
1// Copyright 2002-2019 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#include "CoreferenceEngine.h"
7
8#include <fstream>
9#include <queue>
10
11using namespace std;
13
14using namespace Lima::Common::Misc;
16
17namespace Lima
18{
19namespace LinguisticProcessing
20{
21namespace EntityTracking
22{
23
24bool CoreferenceEngine::isEqual(const QString& a,
25 const QString& b) const
26{
27 return (a == b);
28}
29
32bool CoreferenceEngine::isInclude(const QString& original,
33 const QString& currentWord) const
34{
35 if ((currentWord.size() > original.size()) ||(currentWord[0].isUpper()))
36 return false;
37
38 if ((currentWord == "is") ||
39 (currentWord == "as") ||
40 (currentWord == "a") ||
41 (currentWord == "to") ||
42 (currentWord == "and"))
43 {
44 return false;
45 }
46 int comptCurrent = 0;
47
48 for (int i = 0; i < original.length(); i++)
49 {
50 if (original[i] == currentWord[comptCurrent])
51 {
52 comptCurrent++;
53 }
54 }
55
56 return (comptCurrent == currentWord.length());
57}
58
61bool CoreferenceEngine::isAcronym(const QString& original,
62 const QString& currentWord) const
63{
64 for (const auto& acronym : m_acronyms)
65 {
66 if (*acronym.begin() == original)
67 {
68 for (const auto& initial : acronym)
69 {
70 if ( (initial == currentWord) ||
71 (isInclude(initial, currentWord)))
72 return true;
73 }
74 }
75 }
76 return false;
77}
78
81void CoreferenceEngine::addNewForm(const QString& original,
82 const QString& currentWord)
83{
84 for (auto& acronym : m_acronyms)
85 {
86 if (*acronym.begin() == original)
87 {
88 acronym.push_back(currentWord);
89 return;
90 }
91 }
92}
93
96bool CoreferenceEngine::exist(const QString& mot) const
97{
98 for (const auto& acronym : m_acronyms)
99 {
100 for (const auto& initial : acronym)
101 {
102 if (mot == initial)
103 {
104 return true;
105 }
106 }
107 }
108 return false;
109}
110
114{
115 std::vector<Token> newToken;
116 //newToken.push_back(tok);
117 /* Si le mot existe dans le vecteur des acronyms, ça ne sert à rien chercher
118 * ses acronyms parce qu'ils
119 * sont recherchés */
120 std::vector<QString> tempAcronyms;
121 if (!exist(tok.stringForm()))
122 {
123 /* parcourir tous les noeuds */
124 for(const auto& token : allTokens)
125 {
126 //string mot;
127 /* Recherche dans le texte de toutes les formes de mot précédent dans tout le text */
128 if ( ( isEqual(tok.stringForm(), token.stringForm())) ||
129 ( isInclude(tok.stringForm(), token.stringForm()))/* ||
130 (isAcronym(tok.stringForm(), token.stringForm()))*/)
131 {
132 tempAcronyms.push_back(token.stringForm());
133 newToken.push_back(token);
134 }
135 }
136 }
137 m_acronyms.push_back(tempAcronyms);
138
139 return newToken;
140}
141
142std::vector<LinguisticAnalysisStructure::Token>& CoreferenceEngine::getToken()
143{
144 return allTokens;
145}
146
147std::vector<LinguisticAnalysisStructure::Token>& CoreferenceEngine::getAnnotations()
148{
149 return storedAnnotation;
150}
151
152std::vector< std::vector<QString> >& CoreferenceEngine::getAcronym()
153{
154 return m_acronyms;
155}
156
158{
159 allTokens.push_back(tok);
160}
161
163{
164 storedAnnotation.push_back(tok);
165}
166
167}
168}
169}
void storeAnnot(const LinguisticAnalysisStructure::Token &token)
std::vector< LinguisticAnalysisStructure::Token > & getAnnotations()
std::vector< LinguisticAnalysisStructure::Token > searchCoreference(const LinguisticAnalysisStructure::Token &tok)
bool isInclude(const QString &original, const QString &currentWord) const
std::vector< LinguisticAnalysisStructure::Token > & getToken()
bool isAcronym(const QString &original, const QString &currentWord) const
void storeAllToken(const LinguisticAnalysisStructure::Token &token)
bool isEqual(const QString &a, const QString &b) const
void addNewForm(const QString &original, const QString &currentWord)
NAUTITIA.
STL namespace.