LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
BoWPredicate.cpp
Go to the documentation of this file.
1// Copyright 2014 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 * @file BoWPredicate.cpp
8 * @author Besancon Romaric
9 * @date Tue Oct 7 2003
10 * copyright Copyright (C) 2003 by CEA LIST
11 *
12 ***********************************************************************/
13
14#include "BoWPredicate.h"
17
18namespace Lima {
19namespace Common {
20namespace BagOfWords {
21
23{
24public:
25 friend class BoWPredicate;
26
28
30
35 std::string getRolesUtf8String(void) const;
36
37 void setRoles(QMultiMap<Common::MediaticData::EntityType, boost::shared_ptr< AbstractBoWElement > > pRoles);
38
39
41 uint64_t m_position;
42 uint64_t m_length;
43 QMultiMap<Common::MediaticData::EntityType, boost::shared_ptr< AbstractBoWElement > > m_roles;
44};
45
47m_predicateType(),
48m_position(0),
49m_length(0),
50m_roles()
51{
52}
53
55m_predicateType(bnep.m_predicateType),
56m_position(bnep.m_position),
57m_length(bnep.m_length),
58m_roles(bnep.m_roles)
59{
60}
61
62//**********************************************************************
63// constructors
64
69
75
76
77BoWPredicate::BoWPredicate(const Common::MediaticData::EntityType theType, QMultiMap<Common::MediaticData::EntityType, boost::shared_ptr< AbstractBoWElement > > pRoles) :
78 m_d(new BoWPredicatePrivate())
79{
80 m_d->m_predicateType = theType;
81 m_d->m_roles = pRoles;
82}
83
85m_d(new BoWPredicatePrivate(*ne.m_d))
86{
87}
88
93
94
96{
97 delete m_d;
98}
99
101{
102 if (&t != this) {
104 m_d->m_roles=t.m_d->m_roles;
105 m_d->m_position = t.m_d->m_position;
106 m_d->m_length = t.m_d->m_length;
107 }
108 return *this;
109}
110
112{
113 return( m_d->m_predicateType == t.m_d->m_predicateType
114 && m_d->m_roles == t.m_d->m_roles
115 && m_d->m_position == t.m_d->m_position
116 && m_d->m_length == t.m_d->m_length);
117}
118
123
125{
126 m_d->m_predicateType = predicateType;
127}
128
129const QMultiMap<Common::MediaticData::EntityType, boost::shared_ptr< AbstractBoWElement > >& BoWPredicate::roles() const
130{
131 return m_d->m_roles;
132}
133
134QMultiMap<Common::MediaticData::EntityType, boost::shared_ptr< AbstractBoWElement > >& BoWPredicate::roles()
135{
136 return m_d->m_roles;
137}
138
139void BoWPredicate::setRoles(QMultiMap< Lima::Common::MediaticData::EntityType, boost::shared_ptr< Lima::Common::BagOfWords::AbstractBoWElement > >& pRoles){
140 m_d->m_roles=pRoles;
141}
142
143
145{
146 return new BoWPredicate(*(new BoWPredicatePrivate(*(this->m_d))));
147}
148
149std::set< uint64_t > BoWPredicate::getVertices() const
150{
152 std::set< uint64_t > result;
153 for (auto it = m_d->m_roles.begin(); it != m_d->m_roles.end(); it++)
154 {
155 std::set< uint64_t > vertices = (*it)->getVertices();
156 for (std::set< uint64_t >::const_iterator it2 = vertices.begin(); it2 != vertices.end(); it2++)
157 {
158 result.insert(*it2);
159 }
160 }
161 return result;
162}
163
164uint64_t BoWPredicate::getPosition(void) const {return m_d->m_position;};
165uint64_t BoWPredicate::getLength(void) const {return m_d->m_length;};
166void BoWPredicate::setPosition(const uint64_t pos){m_d->m_position = pos;};
167void BoWPredicate::setLength(const uint64_t len) {m_d->m_length = len;};
168
169//**********************************************************************
170// input/output functions
171//**********************************************************************
173{
174 return MediaticData::MediaticData::single().getEntityName(static_cast<BoWPredicatePrivate*>(m_d)->m_predicateType);
175}
176
178{
179 LIMA_UNUSED(macroManager);
180 std::ostringstream oss;
181 oss << Misc::limastring2utf8stdstring(MediaticData::MediaticData::single().getEntityName(static_cast<BoWPredicatePrivate*>(m_d)->m_predicateType)) << ":" << m_d->getRolesUtf8String();
182 return oss.str();
183}
184
186{
187 std::ostringstream oss;
188 oss << getOutputUTF8String();
189 return oss.str();
190}
191
193{
194 std::ostringstream oss;
195 if (! m_roles.empty())
196 {
197 auto it = m_roles.begin();
198 oss << Misc::limastring2utf8stdstring(MediaticData::MediaticData::single().getEntityName(it.key())) << "="
199 << it.value()->getOutputUTF8String();
200 it++;
201 while (it != m_roles.end())
202 {
203 oss << ";"
204 << Misc::limastring2utf8stdstring(MediaticData::MediaticData::single().getEntityName(it.key())) << "="
205 << it.value()->getOutputUTF8String();
206 it++;
207 }
208 }
209 return oss.str();
210}
211
212// void BoWPredicatePrivate::setRoles(QMultiMap<Common::MediaticData::EntityType, AbstractBoWElement*> pRoles){
213// QMultiMap<Common::MediaticData::EntityType, AbstractBoWElement*>::const_iterator it=pRoles.begin();
214// while (it != pRoles.end())
215// {
216// m_roles.insert(it.key(),it.value());
217// }
218// }
219
220
221} // namespace BagOfWords
222} // namespace Common
223} // namespace Lima
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
void setRoles(QMultiMap< Common::MediaticData::EntityType, boost::shared_ptr< AbstractBoWElement > > pRoles)
QMultiMap< Common::MediaticData::EntityType, boost::shared_ptr< AbstractBoWElement > > m_roles
std::string getRolesUtf8String(void) const
get a string of the roles, of the kind : role1=value1;role2=value2
This is a BoW element used to represent a predicate (n-ary relation, template or semantic frame).
virtual std::string getIdUTF8String(void) const override
function used to identify a bowtoken in a text (used in BowDumper)
MediaticData::EntityType getPredicateType(void) const
virtual BoWPredicate * clone() const override
virtual uint64_t getPosition(void) const override
virtual void setPosition(const uint64_t pos) override
void setRoles(QMultiMap< Common::MediaticData::EntityType, boost::shared_ptr< Common::BagOfWords::AbstractBoWElement > > &pRoles)
virtual uint64_t getLength(void) const override
virtual std::string getOutputUTF8String(const Common::PropertyCode::PropertyManager *macroManager=0) const override
get a string of the predicate for output function
bool operator==(const BoWPredicate &)
BoWPredicate & operator=(const BoWPredicate &)
virtual void setLength(const uint64_t len) override
virtual Lima::LimaString getString(void) const override
virtual std::set< uint64_t > getVertices() const override
returns the vertices of the predicate and the roles
void setPredicateType(const MediaticData::EntityType &)
const QMultiMap< Common::MediaticData::EntityType, boost::shared_ptr< AbstractBoWElement > > & roles() const
LimaString getEntityName(const EntityType &type) const
Provide tools to manage a specific property.
static const MediaticData & single()
const singleton accessor
Definition Singleton.h:51
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
NAUTITIA.
QString LimaString
Definition LimaString.h:33