127 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph"));
128 if (anagraph ==
nullptr)
131 LERROR <<
"Can't Process RnnNER: missing data 'AnalysisGraph'";
134 auto srcgraph = anagraph->getGraph();
135 auto endVx = anagraph->lastVertex();
140 auto posgraph = std::make_shared<LinguisticAnalysisStructure::AnalysisGraph>(
142 analysis.
setData(
"PosGraph", posgraph);
145 auto annotationData = std::dynamic_pointer_cast< AnnotationData >(analysis.
getData(
"AnnotationData"));
146 if (annotationData==
nullptr)
148 annotationData = std::make_shared<AnnotationData>();
152 if (std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(
"AnalysisGraph")) !=
nullptr)
154 std::dynamic_pointer_cast<AnalysisGraph>(
155 analysis.
getData(
"AnalysisGraph"))->populateAnnotationGraph(
156 annotationData.get(),
159 analysis.
setData(
"AnnotationData", annotationData);
161 if (num_vertices(*srcgraph)<=2)
167 auto currentVx = anagraph->firstVertex();
168 auto resultgraph = posgraph->getGraph();
169 remove_edge(posgraph->firstVertex(), posgraph->lastVertex(), *resultgraph);
171 std::vector<segmentation::token_pos> buffer;
172 std::vector< LinguisticGraphVertex > anaVertices;
173 std::vector<std::string> v;
175 while(currentVx != endVx)
177 if (currentVx != 0 && vTokens[currentVx] !=
nullptr)
179 const auto& src = vTokens[currentVx];
180 v.push_back(src->stringForm().toStdString());
181 buffer.emplace_back();
182 anaVertices.push_back(currentVx);
185 boost::tie(it, it_end) = boost::out_edges(currentVx, *srcgraph);
188 currentVx = boost::target(*it, *srcgraph);
198 for(
unsigned long k = 0; k < anaVertices.size(); k++)
200 currentVx = anaVertices[k];
201 if (currentVx != 0 && vTokens[currentVx] !=
nullptr)
203 const auto& src = vTokens[currentVx];
204 auto& token = buffer[k];
205 token.m_offset = src->position();
206 token.m_len = src->length();
207 token.m_pch = v[k].c_str();
209 & StatusType::T_SENTENCE_BRK);
214 std::vector<LinguisticGraphVertex>::size_type anaVerticesIndex = 0;
220 std::shared_ptr<Automaton::RecognizerMatch> entityFound;
221 QString prev_tag =
"O";
222 bool isTagged =
false;
223 while (anaVerticesIndex < anaVertices.size())
225 auto anaVertex = anaVertices[anaVerticesIndex];
231 auto morphoData = get(
vertex_data,*srcgraph,anaVertex);
234 if (morphoData !=
nullptr)
236 auto entityTag = QString::fromUtf8(m_d->
m_tags[anaVerticesIndex].c_str());
237 if((anaVerticesIndex>0 && entityTag != prev_tag)
238 || (entityTag[0] !=
'B' && prev_tag !=
"O") )
241 if (entityFound->size() == 1)
243 auto matches = annotationData->matches(anagraph->getGraphId(),
244 entityFound->getBegin(),
"annot");
245 for (
auto it = matches.cbegin(); it != matches.cend(); it++)
247 if (annotationData->hasAnnotation(*it, QString::fromUtf8(
"SpecificEntity"))
248 && annotationData->annotation(*it, QString::fromUtf8(
"SpecificEntity"))
251 entityFound =
nullptr;
258 if (annotationData->dumpFunction(
"SpecificEntity") ==
nullptr)
260 annotationData->dumpFunction(
"SpecificEntity",
270 auto dataHead = dataMap[head];
284 elem.
lemma = seLemma;
288 auto seType = entityFound->getType();
291 resourceName.toStdString());
294 auto entityMicros = std::dynamic_pointer_cast<SpecificEntities::SpecificEntitiesMicros>(res);
295 auto micros = entityMicros->getMicros(seType);
302 auto newToken =
new Token(
305 entityFound->positionBegin(),
306 entityFound->length());
307 auto tStatus = tokenMap[head]->status();
309 auto syntacticData = std::dynamic_pointer_cast<SyntacticAnalysis::SyntacticData>(analysis.
getData(
"SyntacticData"));
312 if (syntacticData !=
nullptr)
314 boost::tie (newVertex, newDepVertex) = syntacticData->addVertex();
318 newVertex = add_vertex(*lingGraph);
322 auto agv = annotationData->createAnnotationVertex();
323 annotationData->addMatching(anagraph->getGraphId(), newVertex,
"annot", agv);
324 annotationData->annotate(agv, QString::fromStdString(anagraph->getGraphId()), newVertex);
325 tokenMap[newVertex] = newToken;
326 dataMap[newVertex] = newMorphData;
328 annotationData->annotate(agv, QString::fromUtf8(
"SpecificEntity"), ga);
331 boost::tie(inEdgeIt,inEdgeItEnd) = boost::in_edges(head, *lingGraph);
334 if(inEdgeIt != inEdgeItEnd)
336 auto previous = boost::source(*inEdgeIt, *lingGraph);
337 boost::remove_edge(head, previous, *lingGraph);
338 boost::tie(e, success) = boost::add_edge(previous, newVertex, *lingGraph);
346 if(inEdgeIt != inEdgeItEnd)
352 boost::tie(outEdgeIt, outEdgeItEnd) = boost::out_edges(entityFound->getEnd(), *lingGraph);
353 if(outEdgeIt != outEdgeItEnd)
355 auto next = boost::target(*outEdgeIt, *lingGraph);
356 boost::remove_edge(entityFound->getEnd(), next, *lingGraph);
357 boost::tie(e, success) = boost::add_edge(newVertex, next, *lingGraph);
365 if(outEdgeIt != outEdgeItEnd)
372 auto entityFoundIt = entityFound->cbegin();
373 auto entityFoundItEnd = entityFound->cend();
374 for (; entityFoundIt != entityFoundItEnd; entityFoundIt++)
386 if(entityFound ==
nullptr)
388 entityFound = std::make_shared<Automaton::RecognizerMatch>(anagraph.get(), anaVertex,
true);
389 auto entityModex = m_d->
m_typeMap[entityTag];
390 entityModex.remove(QRegularExpression(
"^[BI]-"));
400 << entityModex <<
": " << e.
what());
402 entityFound->setType(seType);
406 entityFound->addFrontVertex(anaVertex);
408 prev_tag = QString::fromUtf8(m_d->
m_tags[anaVerticesIndex].c_str());