LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
TextWriterBoWDocumentHandler.cpp
Go to the documentation of this file.
1// Copyright 2002-2020 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 *
8 * @file TextWriterBoWDocumentHandler.cpp
9 * @author Besancon Romaric (romaric.besancon@cea.fr)
10 * @date Tue Mar 7 2006
11 * copyright Copyright (C) 2006-2020 by CEA LIST
12 *
13 ***********************************************************************/
14
16#include "bowTokenIterator.h"
17#include "bowToken.h"
18#include "bowText.h"
20#include "indexElement.h"
21
23
24namespace Lima {
25namespace Common {
26namespace BagOfWords {
27
29{
31
34
35 void writeIndexElement(const IndexElement& element);
36
37 std::ostream& m_outputStream;
38
39};
40
41TextWriterBoWDocumentHandlerPrivate::TextWriterBoWDocumentHandlerPrivate(std::ostream& os):
42m_outputStream(os)
43{
44}
45
46TextWriterBoWDocumentHandlerPrivate::~TextWriterBoWDocumentHandlerPrivate() {
47}
48
49//***********************************************************************
50// constructors and destructors
55
60
61//***********************************************************************
64 const std::string& /*elementName*/)
65{
66 //os << *properties;
67}
68
71 const std::string& /*elementName*/)
72{
73 m_d->m_outputStream << *properties << std::endl;
74}
75
77processSBoWText(const BoWText* boWText,
78 bool useIterators, bool useIndexIterator)
79{
80 if (useIterators) {
81 BoWTokenIterator it(*boWText);
82 while (! it.isAtEnd()) {
83 m_d->m_outputStream << it.getElement();
84 it++;
85 }
86 }
87 else if (useIndexIterator) {
88 IndexElementIterator it(*boWText);
89 while (! it.isAtEnd())
90 {
91 m_d->writeIndexElement(it.getElement());
92 it++;
93 }
94 }
95 else {
96 m_d->m_outputStream << *boWText;
97 }
98}
99
102 bool /*useIterators*/, bool /*useIndexIterator*/)
103{
104 //os << *properties;
105}
106
111
112void TextWriterBoWDocumentHandlerPrivate::writeIndexElement(
113 const IndexElement& element) {
114 LIMA_UNUSED(element)
115// m_outputStream << "<term "
116// << "id=\"" << element.getId() << "\"";
117// if (element.empty()) {
118// m_outputStream << "/>" << endl;
119// return;
120// }
121// if (element.isSimpleTerm()) {
122// std::string cat = static_cast<const MediaticData::LanguageData&>(MediaticData::MediaticData::single().mediaData(m_language)).getPropertyCodeManager().getPropertyManager("MACRO").getPropertySymbolicValue(element.getCategory());
123//
124// m_outputStream << " lemma=\"" << xmlString(Common::Misc::limastring2utf8stdstring(element.getSimpleTerm()))
125// << "\" category=\"" << cat
126// << "\" position=\"" << element.getPosition()
127// << "\" length=\"" << element.getLength() << "\"";
128// if (element.isNamedEntity()) {
129// m_outputStream << " neType=\"" << element.getNamedEntityType() << "\"";
130// m_outputStream << " type=\"" << BOW_NAMEDENTITY << "\"";
131// }
132// else {
133// m_outputStream << " type=\"" << BOW_TOKEN << "\"";
134// }
135// m_outputStream << "/>" << endl;
136// return;
137// }
138//
139// // compound
140// if (element.isNamedEntity()) {
141// m_outputStream << " neType=\"" << element.getNamedEntityType() << "\"";
142// m_outputStream << " type=\"" << BOW_NAMEDENTITY << "\"";
143// }
144// else {
145// m_outputStream << " type=\"" << BOW_TERM << "\"";
146// }
147// m_outputStream << ">" << endl
148// << " <structure>" << endl;
149//
150// for (uint64_t i(0),size=element.getStructure().size(); i<size; i++) {
151// m_outputStream << " <termRef id=\""
152// << element.getStructure()[i]
153// << "\" rel=\"" << element.getRelations()[i]
154// << "\"/>" << endl;
155//
156// }
157// m_outputStream << " </structure>" << endl
158// << "</term>" << endl;
159}
160
161
162} // end namespace
163} // end namespace
164} // end namespace
#define LIMA_UNUSED(x)
Definition LimaCommon.h:224
This class represents a list of elements, that are pointers on polymmorphic tokens that can be simple...
Definition bowText.h:48
boost::shared_ptr< Lima::Common::BagOfWords::AbstractBoWElement > getElement()
An iterator on the bowText that returns IndexElements.
const IndexElement & getElement() const
Represent an element of an index If it is a predicate, its simple term is "PredicateElement" and its ...
void openSBoWNode(const Misc::GenericDocumentProperties *properties, const std::string &elementName) override
void processProperties(const Misc::GenericDocumentProperties *properties, bool useIterators, bool useIndexIterator) override
void processSBoWText(const BoWText *boWText, bool useIterators, bool useIndexIterator) override
void openSBoWIndexingNode(const Misc::GenericDocumentProperties *properties, const std::string &elementName) override
NAUTITIA.