LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
dotGraphWriter.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#include "dotGraphWriter.h"
7
9
17
18#include <iostream>
19
20using namespace std;
22using namespace Lima::Common::MediaticData;
24
25namespace Lima
26{
27namespace LinguisticProcessing
28{
29
31
33 m_trigramMatrix(nullptr),
34 m_bigramMatrix(nullptr)
35{}
36
39 Manager* manager)
40
41{
49 m_language=manager->getInitializationParameters().media;
50 try {
51 string trigrams=unitConfiguration.getParamsValueAtKey("trigramMatrix");
52 auto res = LinguisticResources::single().getResource(m_language,trigrams);
53 m_trigramMatrix = std::dynamic_pointer_cast<PosTagger::TrigramMatrix>(res);
54 } catch (NoSuchParam& ) {
55 LERROR << "No param 'trigramMatrix' in DotGraphWriter group for language " << (int)m_language;
57 }
58 try {
59 string bigrams=unitConfiguration.getParamsValueAtKey("bigramMatrix");
60 auto res = LinguisticResources::single().getResource(m_language, bigrams);
61 m_bigramMatrix = std::dynamic_pointer_cast<PosTagger::BigramMatrix>(res);
62 } catch (NoSuchParam& ) {
63 LDEBUG << "No param 'bigramMatrix' in DotGraphWriter group for language " << (int)m_language;
64 // throw InvalidConfiguration();
65 }
66 try
67 {
68 m_outputSuffix = unitConfiguration.getParamsValueAtKey("outputSuffix");
69 }
70 catch (NoSuchParam& )
71 {
72 LWARN << "No param 'outputSuffix' in DotGraphWriter group for language " << (int)m_language;
73 LWARN << "use .graph.dot";
74 m_outputSuffix=string(".graph.dot");
75 }
76 try
77 {
78 m_graphId=unitConfiguration.getParamsValueAtKey("graph");
79 }
80 catch (NoSuchParam& )
81 {
82 LWARN << "No param 'graph' in "<<unitConfiguration.getName() << " group for language " << (int)m_language;
83 LWARN << "use PosGraph";
84 m_graphId=string("PosGraph");
85 }
86 try
87 {
88 m_vertexDisplay=unitConfiguration.getListsValueAtKey("vertexDisplay");
89 }
90 catch (NoSuchList& )
91 {
92 // empty display
93 }
94 try
95 {
96 m_graphDotOptions = unitConfiguration.getMapAtKey("graphDotOptions");
97 }
98 catch (NoSuchMap& ) {}
99
100 try
101 {
102 m_nodeDotOptions = unitConfiguration.getMapAtKey("nodeDotOptions");
103 }
104 catch (NoSuchMap& ) {}
105
106 try
107 {
108 m_edgeDotOptions = unitConfiguration.getMapAtKey("edgeDotOptions");
109 }
110 catch (NoSuchMap& ) {}
111}
112
113
114// Each token of the specified path is
115// searched into the specified dictionary.
117{
119 auto anagraph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.getData(m_graphId));
120 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.getData("LinguisticMetaData"));
121 if (metadata == 0) {
122 PTLOGINIT;
123 LERROR << "no LinguisticMetaData ! abort";
124 return MISSING_DATA;
125 }
126 if (anagraph == 0) {
127 PTLOGINIT;
128 LERROR << "no AnalysisGraph named " << m_graphId << " ! ";
129 return MISSING_DATA;
130 }
131 string outputFileName=metadata->getMetaData("FileName") + m_outputSuffix;
133 anagraph->getGraph(),
135 m_trigramMatrix.get(),
136 m_bigramMatrix.get());
138 gw.writeToDotFile(outputFileName,m_vertexDisplay);
139
140 TimeUtils::logElapsedTime("DotGraphWriter");
141 return SUCCESS_ID;
142}
143
144} // LinguisticProcessing
145} // Lima
#define LWARN
Definition LimaCommon.h:160
#define LDEBUG
Definition LimaCommon.h:157
#define LERROR
Definition LimaCommon.h:161
#define PTLOGINIT
Defines a Factory to create Object of type Base.
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
std::deque< std::string > & getListsValueAtKey(const std::string &key)
std::map< std::string, std::string > & getMapAtKey(const std::string &key)
return a message when a 'param' was not found
Use this exception to signal an error in one of the configuration files.
Definition LimaCommon.h:345
std::shared_ptr< Lima::LinguisticProcessing::PosTagger::TrigramMatrix > m_trigramMatrix
std::map< std::string, std::string > m_nodeDotOptions
std::shared_ptr< Lima::LinguisticProcessing::PosTagger::BigramMatrix > m_bigramMatrix
std::map< std::string, std::string > m_edgeDotOptions
std::map< std::string, std::string > m_graphDotOptions
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
std::deque< std::string > m_vertexDisplay
void setOptions(const std::map< std::string, std::string > &graphDotOptions, const std::map< std::string, std::string > &nodeDotOptions, const std::map< std::string, std::string > &edgeDotOptions)
void writeToDotFile(const std::string &dotFileName, std::deque< std::string > vertexDisplay=std::deque< std::string >())
static const LinguisticResources & single()
const singleton accessor
Definition Singleton.h:51
static void logElapsedTime(const std::string &mess, const std::string &taskCategory=std::string(""))
log the number of microseconds since last UpdateCurrentTime
static void updateCurrentTime(const std::string &taskCategory=std::string(""))
store current time for new elapsed time computation
#define DOTGRAPHWRITER_CLASSID
SimpleFactory< MediaProcessUnit, DotGraphWriter > dotGraphWriterFactory(DOTGRAPHWRITER_CLASSID)
NAUTITIA.
LimaStatusCode
Definition LimaCommon.h:236
@ SUCCESS_ID
Definition LimaCommon.h:237
@ MISSING_DATA
Definition LimaCommon.h:243
STL namespace.
launch exception related to the configuration file parsing