22#include <boost/algorithm/string.hpp>
36namespace LinguisticProcessing {
37namespace AnalysisDumpers {
43m_useNormalizedForms(false)
46 LDEBUG <<
"BratDumper::BratDumper()";
59 LDEBUG <<
"BratDumper::init";
65 if (str==
"yes" || str==
"1" || str==
"true") {
66 m_useNormalizedForms=
true;
75 unsigned int entityId,
76 const std::string& entityType,
77 const std::string& entityString,
78 const vector<pair<uint64_t,uint64_t> >& positions,
81 out <<
"T" << entityId <<
"\t" << entityType <<
" ";
82 if (positions.size()==0) {
85 LERROR <<
"BratDumper: no positions given for entity" << entityString;
89 vector<pair<uint64_t,uint64_t> >::const_iterator posIt=positions.begin();
90 out << (*posIt).first <<
" " << (*posIt).second;
91 for (posIt++; posIt!=positions.end(); posIt++) {
92 out <<
";" << (*posIt).first <<
" " << (*posIt).second;
95 out <<
"\t" << entityString <<
"\n";
96 if (m_useNormalizedForms && !noNorm) {
98 for (Automaton::EntityFeatures::const_iterator
99 featureItr=entityFeatures.begin(),features_end=entityFeatures.end();
100 featureItr!=features_end; featureItr++)
102 if (featureItr->getName()==
"value") {
103 string valuestr=featureItr->getValueString();
105 if (valuestr.find_first_not_of(
' ') != std::string::npos) {
106 out <<
"N" << entityId <<
"\tReference T" << entityId <<
" LIMA:1\t" << valuestr <<
"\n";
113 out <<
"N" << entityId <<
"\tReference T" << entityId <<
" LIMA:1\t" << entityString <<
"\n";
120 unsigned int entityId,
121 std::map <std::tuple <std::size_t, std::string , std::string >, std::size_t >& mapAttributes)
const
123 for(
auto iterAttribute = mapAttributes.begin();
124 iterAttribute!=mapAttributes.end();
127 auto feature = iterAttribute->first;
128 std::size_t eId = std::get<0>(feature);
129 if( eId == entityId )
131 std::size_t attributeId = iterAttribute->second;
132 std::string featName = std::get<1>(feature);
133 std::string featValue = std::get<2>(feature);
134 out <<
"A" << attributeId <<
"\t" << featName <<
" T" << entityId;
136 out <<
" " << featValue;
145 unsigned int entityId,
146 const std::string& entityNorm)
const
148 out <<
"N" << entityId <<
"\tReference T" << entityId <<
" X:Y\t"
149 << entityNorm <<
"\n";
154 unsigned int relationId,
155 const std::string& relationType,
156 const std::string& sourceArgString,
157 const std::string& targetArgString)
const
159 QString relation = QString::fromUtf8(relationType.c_str());
160 QStringList relations = relation.split(
',');
162 for (
auto& rel : relations)
167 LERROR <<
"BratDumper::outputRelationString Ignoring relation with empty type:"
168 << relationId << relationType << sourceArgString
172 if (sourceArgString.empty())
175 LERROR <<
"BratDumper::outputRelationString Ignoring relation with empty source:"
176 << relationId << relationType << sourceArgString
180 if (targetArgString.empty())
183 LERROR <<
"BratDumper::outputRelationString Ignoring relation with empty target:"
184 << relationId << relationType << sourceArgString
189 string relstr=rel.toUtf8().constData();
190 if (relstr.find(
".")!=string::npos) {
191 relstr=relstr.substr(relstr.find(
"."));
193 out <<
"R" << (relationId+i) <<
"\t" << relstr <<
" "
194 <<
"Arg1:T" << sourceArgString
195 <<
" Arg2:T" << targetArgString << endl;
203 unsigned int eventId,
204 unsigned int eventMentionId,
205 const std::string& eventMentionType,
206 const std::vector<unsigned int>& eventRoleId,
207 const std::vector<std::string>& eventRoleType)
const
209 out <<
"E" << eventId <<
"\t";
211 if (eventMentionId!=0) {
212 out << eventMentionType <<
":T" << eventMentionId;
213 for (
unsigned int i(0), n=eventRoleId.size(); i<n; i++) {
214 out <<
" " << eventRoleType[i] <<
":T" << eventRoleId[i];
219 if (eventRoleId.size()==0) {out << endl;
return; }
220 out << eventRoleType[0] <<
":T" << eventRoleId[0];
221 for (
unsigned int i(1), n=eventRoleId.size(); i<n; i++) {
222 out <<
" " << eventRoleType[i] <<
":T" << eventRoleId[i];
This file is the main header file for the data related to annotation graphs.
#define BRATDUMPER_CLASSID
Defines a Factory to create Object of type Base.
std::string & getParamsValueAtKey(const std::string &key)
return a message when a 'param' was not found
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 outputEntityNorm(std::ostream &out, unsigned int entityId, const std::string &entityNorm) const override
void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
unsigned int outputRelationString(std::ostream &out, unsigned int relationId, const std::string &relationType, const std::string &sourceArgString, const std::string &targetArgString) 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
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
a list of generic features: each feature is unique (only one feature for a name)
SimpleFactory< MediaProcessUnit, BratDumper > bratDumperFactory(BRATDUMPER_CLASSID)