167 auto tokenList = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(m_d->m_graph));
171 LERROR <<
"graph " << m_d->m_graph <<
" has not been produced: check pipeline" ;
174 auto annotationData = std::dynamic_pointer_cast<AnnotationData>(analysis.
getData(
"AnnotationData"));
175 auto limaConllMapping = std::dynamic_pointer_cast<LimaConllTokenIdMapping>(analysis.
getData(
"LimaConllTokenIdMapping"));
179 QFile file(fileName);
182 if (!file.open(QIODevice::ReadOnly))
185 LERROR <<
"SemanticRoleLabelingLoader::process: cannot open file" << fileName;
189 std::map <int, QString> sentences;
190 while (!file.atEnd())
192 QByteArray text=file.readLine();
193 QString textString = QString::fromUtf8(text.constData());
195 if (textString.size()<3)
201 QString becomingSentence=sentences[sentenceNb]+textString;
202 sentences[sentenceNb]= becomingSentence;
206 ConllHandler cHandler(m_d->m_language, analysis, tokenList.get());
207 for (std::map<int,QString>::iterator it=sentences.begin(); it!=sentences.end(); ++it)
209 int sentenceIndex=it->first;
210 QString sentence=it->second;
214 LDEBUG <<
"SemanticRoleLabelingLoader::process there is/are " << cHandler.
m_verbalClassNb <<
"verbal class(es) for this sentence " ;
216 for (
int vClassIndex=0;vClassIndex<cHandler.
m_verbalClassNb;vClassIndex++)
219 QStringList verbalClasses = cHandler.
m_verbalClasses[vClassIndex].second.split(
"|");
220 for (
auto verbalClass = verbalClasses.begin(); verbalClass != verbalClasses.end(); ++verbalClass)
222 *verbalClass = m_d->m_model +
"." + *verbalClass;
224 LimaString verbalClass= verbalClasses.join(
"|");
228 annotationData->addMatching(
"PosGraph", posGraphPredicateVertex,
"annot", annotPredicateVertex);
229 annotationData->annotate(annotPredicateVertex,
"Predicate", verbalClass);
233 LDEBUG <<
"SemanticRoleLabelingLoader::process: annotation vertex"<< annotPredicateVertex <<
"was created for the verbal class "<< annotationData->stringAnnotation(annotPredicateVertex,
"Predicate") <<
"and the PoS graph vertex"<<posGraphPredicateVertex;
235 std::vector <pair<LinguisticGraphVertex,QString>>::iterator semRoleIt;
238 QStringList semanticRoles = (*semRoleIt).second.split(
"|");
239 for (
auto semanticRole = semanticRoles.begin(); semanticRole != semanticRoles.end(); ++semanticRole)
241 if (!semanticRole->isEmpty())
242 *semanticRole = m_d->m_model +
"." + *semanticRole;
244 LimaString semanticRole= semanticRoles.join(
"|");
247 AnnotationGraphEdge roleEdge=annotationData->createAnnotationEdge(annotPredicateVertex, annotRoleVertex);
248 annotationData->annotate(roleEdge,
"SemanticRole", semanticRole);
249 annotationData->addMatching(
"PosGraph", posGraphRoleVertex,
"annot", annotRoleVertex);
253 LDEBUG <<
"SemanticRoleLabelingLoader::process: annotation edge" << roleEdge <<
"annotated " << annotationData->stringAnnotation(roleEdge,
"SemanticRole")<<
"was created for" << verbalClass <<
" and the PoS graph vertices " << posGraphPredicateVertex <<
"and" << posGraphRoleVertex ;
285 QString firstSentenceToken=(*sentenceTokens.constBegin());
292 LDEBUG <<
"ConllHandler::extractSemanticInformation" <<
m_verbalClassNb << sentenceI <<
" : \n" << sent ;
299 for (
auto it = sentenceTokens.begin(); it != sentenceTokens.end(); ++it)
305 int conllTokenId=descriptors[0].toInt();
306 QString conllToken=descriptors[1];
308 LDEBUG <<
"ConllHandler::extractSemanticInformation token " << conllTokenId << conllToken;
314 LDEBUG <<
"ConllHandler::extractSemanticInformation verbalClass" << verbalClass;
319 LERROR <<
"ConllHandler::extractSemanticInformation classIndex error" << classIndex;
326 for (
int roleTargetFieldIndex = 0; roleTargetFieldIndex<
m_verbalClassNb; ++roleTargetFieldIndex)
329 LDEBUG <<
"ConllHandler::extractSemanticInformation"<<
"nb descriptors and roleTargetFieldIndex" << descriptors.size() << roleTargetFieldIndex ;
333 LERROR <<
"ConllHandler::extractSemanticInformation roleTargetFieldIndex error" << roleTargetFieldIndex;
344 LDEBUG <<
"ConllHandler::extractSemanticInformation argument "<<semanticRoleLabel<<
": The PoS graph token id matching the conll token id " << conllTokenId <<
" is " << limaTokenId;
346 std::vector<std::pair<LinguisticGraphVertex,QString>> sRoles;
349 LERROR <<
"ConllHandler::extractSemanticInformation roleTargetFieldIndex error 2" << roleTargetFieldIndex;
352 m_semanticRoles[roleTargetFieldIndex].push_back(make_pair(limaTokenId,semanticRoleLabel));
379 std::map< int,std::map< int,LinguisticGraphVertex>>::iterator limaConllMappingIt;
380 limaConllMappingIt=limaConllMapping->find(sentenceI);
381 if (limaConllMappingIt == limaConllMapping->end())
383 LERROR <<
"Sentence " << sentenceI <<
" not found";
386 std::map< int,LinguisticGraphVertex> limaConllId=(*limaConllMappingIt).second;
387 std::map< int,LinguisticGraphVertex>::iterator limaConllIdIt=limaConllId.find(conllTokenId);
388 if (limaConllIdIt==limaConllId.end())
390 LERROR <<
"Conll token id " << conllTokenId <<
" not found";
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id