21#include <QXmlStreamReader>
27namespace LinguisticProcessing {
28namespace SpecificEntities {
39 bool parse(QIODevice *device);
56 std::string
toString(
const QString& xercesString);
60 const std::string& str,
61 const std::string& type,
75 m_graphName(
"AnalysisGraph")
84 LOGINIT(
"LP::SpecificEntities");
97 for (
const auto& modex: modexes)
99 LDEBUG <<
"loader: initialize modex " << modex;
102 QString::fromStdString(modex));
108 LWARN <<
"loader: no modex specified in parameter: types in file loaded may not be known";
115 auto graph = std::dynamic_pointer_cast<AnalysisGraph>(analysis.
getData(m_d->
m_graphName.toStdString()));
116 if (graph ==
nullptr)
118 LOGINIT(
"LP::SpecificEntities");
126 analysis.
setData(
"RecognizerData", recoData);
128 recoData->setResultData(resultData);
133 QFile file(filename);
134 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
136 "Cannot open file" << filename,
138 if (!m_d->
parse(&file))
141 "Error: failed to parse XML input file" << filename << m_d->
m_reader.errorString(),
150 recoData->deleteResultData();
159 LOGINIT(
"LP::SpecificEntities");
162 while (
m_reader.readNextStartElement())
165 if (
m_reader.name() == QLatin1String(
"specific_entity"))
177 else if (
m_reader.name() == QLatin1String(
"position"))
182 m_reader.raiseError(QObject::tr(
"Cannot convert position value %1 to integer.").arg(
m_reader.text()));
185 else if (
m_reader.name() == QLatin1String(
"length"))
190 m_reader.raiseError(QObject::tr(
"Cannot convert position value %1 to integer.").arg(
m_reader.text()));
193 else if (
m_reader.name() == QLatin1String(
"type"))
197 else if (
m_reader.name() == QLatin1String(
"string"))
214 const std::string& str,
215 const std::string& type,
219 LOGINIT(
"LP::SpecificEntities");
220 LDEBUG <<
"loader: add entity " << str <<
"," << type <<
",[" << position <<
"," << length <<
"]";
224 uint64_t posBegin=position;
225 uint64_t posEnd=posBegin+length;
229 std::queue<LinguisticGraphVertex> toVisit;
230 std::set<LinguisticGraphVertex> visited;
238 while (!toVisit.empty()) {
270 for (boost::tie(outItr,outItrEnd)=out_edges(v,*graph); outItr!=outItrEnd; outItr++)
273 if (visited.find(next)==visited.end())
275 visited.insert(next);
281 if (match.size()==0) {
282 LWARN <<
"Warning: no matching vertices for given position/length";
298 createEntity(match,analysis);
303 LOGINIT(
"LP::SpecificEntities");
304 auto errorStr = QObject::tr(
"%1, Line %2, column %3")
#define DEFAULT_ATTRIBUTE
#define LIMA_EXCEPTION_SELECT_LOGINIT(X, Y, Z)
This macro writes the message Y to the error stream configured by its first parameter X,...
#define LIMA_EXCEPTION(X)
This macro writes the message X to a previously configured error stream before throwing a LimaExcepti...
LinguisticGraph::vertex_descriptor LinguisticGraphVertex
LinguisticGraph::out_edge_iterator LinguisticGraphOutEdgeIt
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, LinguisticVertexProperties > LinguisticGraph
Property to identify the chains in the graph.
Defines a Factory to create Object of type Base.
#define SPECIFICENTITIESLOADER_CLASSID
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
void removeData(const QString &id)
remove the analysisData with the given id
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id
void setData(const QString &id, std::shared_ptr< AnalysisData > data)
set an analysisData with the given id.
std::string & getParamsValueAtKey(const std::string &key)
std::deque< std::string > & getListsValueAtKey(const std::string &key)
return a message when a 'list' was not found
return a message when a 'param' was not found
Parser class for the lima's xml configuration files.
Manage initialization of InitializableObjects using configuration module and parameters.
const InitializationParameters & getInitializationParameters() const
get Initialization Parameters
The main LIMA exception class.
virtual const char * what() const override
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
QString getInputFile(AnalysisContent &analysis) const
void setFeature(const std::string &name, const ValueType &value)
const EntityFeatures & features() const
void setType(const Common::MediaticData::EntityType &t)
void addBackVertex(const LinguisticGraphVertex &, bool isKept=true, const LimaString &ruleElementId="")
An AnalysisData containing a LinguisticGraph with a language and an id.
const LinguisticGraphVertex & lastVertex(void) const
Returns the last vertex of the graph.
const LinguisticGraph * getGraph(void) const
Returns the underlying graph structure.
const LinguisticGraphVertex & firstVertex(void) const
Returns the first vertex of the graph.
holds surface data of a token
uint64_t position() const
This action creates a new vertex for given match containing a specific entity's data.
LinguisticAnalysisStructure::AnalysisGraph * m_graph
SpecificEntitiesLoaderPrivate()
std::string toString(const QString &xercesString)
QString errorString() const
std::string m_currentElement
bool parse(QIODevice *device)
void addSpecificEntity(AnalysisContent &analysis, LinguisticAnalysisStructure::AnalysisGraph *graph, const std::string &str, const std::string &type, uint64_t position, uint64_t length)
~SpecificEntitiesLoaderPrivate()=default
QXmlStreamReader m_reader
A Loader class to load external entity annotations.
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.
static const MediaticData & single()
const singleton accessor
static MediaticData & changeable()
singleton accessor
Throw this exception when encountering problems with XML files opening or parsing.
QString findFileInPaths(const QString &paths, const QString &fileName, const QChar &separator)
Find the given file in the given paths.
LimaString utf8stdstring2limastring(const std::string &src)
SimpleFactory< MediaProcessUnit, SpecificEntitiesLoader > SpecificEntitiesLoaderFactory(SPECIFICENTITIESLOADER_CLASSID)