LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
XmlIEDumper.cpp
Go to the documentation of this file.
1// Copyright (C) 2004-2012 by CEA LIST *
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#include "XmlIEDumper.h"
8
21
22#include <fstream>
23#include <queue>
24#include <tuple>
25
26using namespace std;
27using namespace Lima::Common::AnnotationGraphs;
32using namespace boost;
33
34namespace Lima {
35namespace LinguisticProcessing {
36namespace AnalysisDumpers {
37
39
42
45
48 Manager* manager)
49
50{
51 AbstractIEDumper::init(unitConfiguration,manager);
52 // other specific parameters
53 //...
54}
55
56void XmlIEDumper::outputGlobalHeader(std::ostream& out, const std::string& sourceFile,
57 const LimaStringText& /*originalText*/) const
58{
59 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
60 out << "<Doc>" << endl;
61 if (!sourceFile.empty())
62 {
63 out << "<sourceFile>" << sourceFile << "</sourceFile>" << endl;
64 }
65}
66void XmlIEDumper::outputGlobalFooter(std::ostream& out) const
67{
68 out << "</Doc>" << endl;
69}
70void XmlIEDumper::outputEntitiesHeader(std::ostream& out) const
71{
72 out << "<specific_entities>" << endl;
73}
74void XmlIEDumper::outputEntitiesFooter(std::ostream& out) const
75{
76 out << "</specific_entities>" << endl;
77}
78void XmlIEDumper::outputRelationsHeader(std::ostream& out) const
79{
80 out << "<relations>" << endl;
81}
82void XmlIEDumper::outputRelationsFooter(std::ostream& out) const
83{
84 out << "</relations>" << endl;
85}
86void XmlIEDumper::outputEventsHeader(std::ostream& out) const
87{
88 out << "<events>" << endl;
89}
90void XmlIEDumper::outputEventsFooter(std::ostream& out) const
91{
92 out << "</events>" << endl;
93}
94
96outputEntityString(std::ostream& out,
97 unsigned int entityId,
98 const std::string& entityType,
99 const std::string& entityString,
100 const std::vector<std::pair<uint64_t,uint64_t> >& positions,
101 const Automaton::EntityFeatures& entityFeatures, bool /*noNorm*/) const
102{
103 out << "<entity>"
104 << "<id>" << "T" << entityId << "</id>"
105 << "<type>" << entityType << "</type>";
106 // do not need all detailed positions (around carriage returns): get only global extent
107 if (positions.size()==0) {
108 LOGINIT("LP::AnalysisDumpers");
109 LERROR << "XmlIEDumper: missing position for entity" << entityString;
110 }
111 else {
112 out << "<posD>" << positions.front().first << "</posD>";
113 out << "<posF>" << positions.back().second << "</posF>";
114 }
115 // replace multiple spaces with only one space : from http://stackoverflow.com/questions/8362094/replace-multiple-spaces-with-one-space-in-a-string
116 string str(entityString);
117 std::string::iterator new_end =
118 std::unique(str.begin(), str.end(), [=](char lhs, char rhs){ return (lhs == rhs) && (lhs == ' '); } );
119 str.erase(new_end, str.end());
120 out << "<string>"
121 << Common::Misc::transcodeToXmlEntities(QString::fromStdString(str)).toStdString()
122 << "</string>";
123 out << "<norm>";
124
125 for (Automaton::EntityFeatures::const_iterator
126 featureItr=entityFeatures.begin(),features_end=entityFeatures.end();
127 featureItr!=features_end; featureItr++)
128 {
129 out << "<" << featureItr->getName() << ">"
130 << Common::Misc::transcodeToXmlEntities(QString::fromStdString(featureItr->getValueString())).toStdString()
131 << "</" << featureItr->getName() << ">";
132 }
133 out << "</norm>";
134 out << "</entity>\n";
135}
136
138outputEntityNorm([[maybe_unused]] std::ostream& out,
139 [[maybe_unused]] unsigned int entityId,
140 [[maybe_unused]] const std::string& entityNorm) const
141{
142}
143
145outputAttributesString(std::ostream& /*out*/,
146 unsigned int /*entityId*/,
147 std::map <std::tuple <std::size_t, std::string , std::string >, std::size_t >& /*mapAttributes*/) const
148{
149}
150
151unsigned int XmlIEDumper::
152outputRelationString(std::ostream& out,
153 unsigned int relationId,
154 const std::string& relationType,
155 const std::string& sourceArgString,
156 const std::string& targetArgString) const
157{
158 out << "<relation><id>R" << relationId << "</id><type>" << relationType <<"</type>";
159 out << "<source>T" << sourceArgString << "</source>";
160 out << "<target>T" << targetArgString << "</target>";
161 out << "</relation>" << endl;
162 return 1;
163}
164
166outputEventString(std::ostream& out,
167 unsigned int eventId,
168 unsigned int eventMentionId,
169 const std::string& eventMentionType,
170 const std::vector<unsigned int>& eventRoleId,
171 const std::vector<std::string>& eventRoleType) const
172{
173 out << "<event><id>E" << eventId << "</id>" << endl
174 << "<eventElements>" << endl;
175
176 out <<"<element><role>"<< eventMentionType <<"</role><id>T" << eventMentionId << "</id></element>" << endl;
177
178 for (unsigned int i(0), n=eventRoleId.size(); i<n; i++) {
179 out <<"<element><role>"<< eventRoleType[i] <<"</role><id>T" << eventRoleId[i] << "</id></element>" << endl;
180 }
181 out << "</eventElements>" << endl
182 << "</event>" << endl;
183}
184
185} // AnalysisDumpers
186} // LinguisticProcessing
187} // Lima
This file is the main header file for the data related to annotation graphs.
#define LOGINIT(X)
Definition LimaCommon.h:187
#define LERROR
Definition LimaCommon.h:161
Defines a Factory to create Object of type Base.
#define XmlIEDUMPER_CLASSID
Definition XmlIEDumper.h:15
Manage initialization of InitializableObjects using configuration module and parameters.
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
void outputGlobalFooter(std::ostream &os) const override
void outputEntitiesFooter(std::ostream &os) const override
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
void outputEntityString(std::ostream &out, unsigned int entityId, const std::string &entityType, const std::string &entityString, const std::vector< std::pair< uint64_t, uint64_t > > &positions, const Automaton::EntityFeatures &entityFeatures, bool noNorm=false) const override
void outputAttributesString(std::ostream &out, unsigned int entityId, std::map< std::tuple< std::size_t, std::string, std::string >, std::size_t > &mapAttributes) const override
void outputEventString(std::ostream &out, unsigned int eventId, unsigned int eventMentionId, const std::string &eventMentionType, const std::vector< unsigned int > &eventRoleId, const std::vector< std::string > &eventRoleType) const override
unsigned int outputRelationString(std::ostream &out, unsigned int relationId, const std::string &relationType, const std::string &sourceArgString, const std::string &targetArgString) const override
void outputEntityNorm(std::ostream &out, unsigned int entityId, const std::string &entityNorm) const override
void outputRelationsHeader(std::ostream &os) const override
void outputEventsFooter(std::ostream &os) const override
void outputEntitiesHeader(std::ostream &os) const override
void outputEventsHeader(std::ostream &os) const override
void outputRelationsFooter(std::ostream &os) const override
void outputGlobalHeader(std::ostream &os, const std::string &sourceFile="", const LimaStringText &=LimaStringText("")) const override
specific output functions to deal with actual output format these functions are called inside the pro...
a list of generic features: each feature is unique (only one feature for a name)
define the limaStringText resource which is the text in limaString formal
LimaString transcodeToXmlEntities(const LimaString &str)
SimpleFactory< MediaProcessUnit, XmlIEDumper > xmlieDumperFactory(XmlIEDUMPER_CLASSID)
NAUTITIA.
STL namespace.