21#include <boost/lexical_cast.hpp>
32namespace DocumentsReader {
38 unsigned int result = 0;
40 result = back()->getOffset();
43 LDEBUG <<
"ContentStructuredDocument::getOffset = " << result;
49 const unsigned int offset ) {
50 back()->addPart(text,offset);
57 LDEBUG <<
"ContentStructuredDocument::addPropertyChild" << elementName <<
"for property" << type.
getId();
66 const QString& elementName,
unsigned int parserOffset,
71 LDEBUG <<
"ContentStructuredDocument::pushHierarchyChild" << elementName << parserOffset;
77 LDEBUG <<
"and without property";
97 LDEBUG <<
"structuredElement:" << hierarchyElement;
99 if( hierarchyElement != 0 ) {
104 result->GenericDocumentProperties::setIntValue(
"offBegPrpty", parserOffset);
108 LWARN <<
"ContentStructuredDocument::pushHierarchyChild: result was not initialized";
113 LDEBUG <<
"ContentStructuredDocument::pushHierarchyChild: end";
119 const QString& elementName,
unsigned int parserOffset,
125 LDEBUG <<
"ContentStructuredDocument::pushIndexingChild" << elementName<< parserOffset;
131 LDEBUG <<
"and without property";
139 LDEBUG <<
"structuredElement:" << hierarchyElement;
141 if( hierarchyElement != 0 )
150 result->GenericDocumentProperties::setIntValue(
"offBegPrpty", parserOffset);
154 LDEBUG <<
"ContentStructuredDocument::pushIndexingChild: end";
165 LDEBUG <<
"ContentStructuredDocument::pushIgnoredChild" << elementName<< parserOffset;
171 LDEBUG <<
"and without property";
184 LDEBUG <<
"ContentStructuredDocument::pushIgnoredChild: end";
190 const QString& elementName,
unsigned int parserOffset )
194 LDEBUG <<
"ContentStructuredDocument::addDiscardableChild" << elementName << parserOffset;
203 const QString& elementName,
unsigned int parserOffset )
207 LDEBUG <<
"ContentStructuredDocument::pushPresentationChild" << elementName << parserOffset <<back()->
getOffset();
215 if( structuredElement != 0 )
232 for( deque<AbstractStructuredDocumentElement*>::iterator cIt = begin() ; cIt != end() ; cIt++ ) {
241 LDEBUG <<
"ContentStructuredDocument::popDiscardableElement" << parserOffset;
249 assert( size() != 0 );
258 delete currentElement;
265 LDEBUG <<
"ContentStructuredDocument::popPropertyElement" << parserOffset;
273 assert( size() != 0 );
278 delete currentElement;
284 LDEBUG <<
"ContentStructuredDocument::popPresentationElement" << parserOffset;
287 currentElement->back()->addText(QString(parserOffset-currentElement->
getOffset(),
' '));
289 assert( currentElement != 0 );
296 LDEBUG <<
"ContentStructuredDocument::popPresentationElement new current element is" <<newCurrent->
getElementName();
299 if (hierNewCurrent !=0)
306 newCurrent->back()->addText(currentElement->back()->getText());
309 delete currentElement;
316 LDEBUG <<
"ContentStructuredDocument::popIndexingElement" << parserOffset;
320 assert( currentElement != 0 );
325 currentElement->
addProperty(currentElement->
getPropType(), currentElement->back()->getText().toUtf8().constData());
331 LDEBUG <<
"ContentStructuredDocument::popIndexingElement new current element is" <<newCurrent->
getElementName();
334 if ( hierNewCurrent !=0)
344 delete currentElement;
354 assert( currentElement != 0 );
355 LDEBUG <<
"ContentStructuredDocument::popIgnoredElement poping" <<currentElement->
getElementName() <<
"at" << parserOffset;
362 LDEBUG <<
"ContentStructuredDocument::popIgnoredElement new current element is" <<newCurrent->
getElementName();
365 if ( hierNewCurrent !=0 )
374 delete currentElement;
382 LDEBUG <<
"ContentStructuredDocument::popHierarchyElement" << parserOffset;
386 assert( currentElement != 0 );
393 LDEBUG <<
"ContentStructuredDocument::popHierarchyElement new current element is" <<newCurrent->
getElementName();
396 if ( hierNewCurrent != 0 )
402 if(identPrpty.second && identPrpty.first!=
"")
405 LDEBUG <<
"ContentStructuredDocument::popHierarchyElement no dot propagate since current identPrpty is not empty:" << identPrpty.first;
415 delete currentElement;
422 ContentStructuredDocument::reverse_iterator rIt = rbegin();
429 LDEBUG <<
"ContentStructuredDocument::setDataToPreviousElement: set property "
430 << propType.
getId() <<
" to " << utf8text;
434 assert(rIt != rend());
452 <<
property.getId() <<
property.getStorageType() <<
property.getValueCardinality() <<
"'" << data <<
"'";
454 if(property.
getId().empty()) {
456 LWARN <<
"ContentStructuredDocument::setDataToElement: property id is empty. Do not use it" << absElement->
getElementName();
464 LWARN <<
"ContentStructuredDocument::setDataToElement: element is not a AbstractStructuredDocumentElementWithProperties" << absElement->
getElementName();
476 LDEBUG <<
"ContentStructuredDocument::setDataToElement setDateValue : " <<
property.getId() <<
" => "<< dateBegin;
478 if(dateBegin != dateEnd) {
482 LDEBUG <<
"ContentStructuredDocument::setDataToElement setDateIntervalValue : " <<
property.getId() <<
" => "<< dateBegin <<
"-" << dateEnd;
491 LDEBUG <<
"ContentStructuredDocument::setDataToElement addStringValue : " <<
property.getId() <<
" => "<< data;
496 LDEBUG <<
"ContentStructuredDocument::setDataToElement setStringValue : " <<
property.getId() <<
" => "<< data;
504 LDEBUG <<
"ContentStructuredDocument::setDataToElement setIntValue : " <<
property.getId() <<
" => "<< atoi(data.c_str());
514 LDEBUG <<
"ContentStructuredDocument::setDataToElement addWeightedPropValue : " <<
property.getId() <<
" => "<< val<<
"="<<score;
538 LDEBUG <<
"ContentStructuredDocument::parseWeightedValue" << weightedValueStr;
542 std::string::size_type firstSep;
545 if ( (firstSep=weightedValueStr.find(sep1)) != string::npos ) {
546 string val(weightedValueStr,0,firstSep);
547 string sco(weightedValueStr,firstSep+1);
551 score = atof(sco.c_str());
556 catch (std::exception& e) {
558 LWARN <<
"Warning: " << e.what();
561 LDEBUG <<
"ContentStructuredDocument::parseWeightedValue" << weightedValueStr <<
"=>" << value <<
"-" << score;
573 LDEBUG <<
"ContentStructuredDocument::parseDate" << dateStr;
583 std::string::size_type firstSep,secondSep;
585 if ( (firstSep=dateStr.find(sep1)) != string::npos ) {
586 if ( (secondSep=dateStr.find(sep1,firstSep+1)) != string::npos ) {
594 string day(dateStr,0,firstSep);
595 string month(dateStr,firstSep+1,secondSep-firstSep);
596 string year(dateStr,secondSep+1);
597 string newDateStr=year+
'/'+month+
'/'+day;
598 dateBegin=QDate::fromString(newDateStr.c_str());
599 dateEnd=QDate::fromString(newDateStr.c_str());
604 string month(dateStr,0,firstSep);
605 string year(dateStr,firstSep+1);
606 unsigned short monthNum=atoi(month.c_str());
607 unsigned short yearNum=atoi(year.c_str());
608 dateBegin=QDate(yearNum,monthNum,1);
609 dateEnd=dateBegin.addMonths(1).addDays(-1);
612 else if ( (firstSep=dateStr.find(sep2)) != string::npos ) {
613 if ( (secondSep=dateStr.find(sep2,firstSep+1)) != string::npos ) {
615 dateBegin=QDate::fromString(dateStr.c_str(), Qt::ISODate);
616 dateEnd=QDate::fromString(dateStr.c_str(), Qt::ISODate);
621 string year(dateStr,0,firstSep);
622 string month(dateStr,firstSep+1);
623 unsigned short monthNum=atoi(month.c_str());
624 unsigned short yearNum=atoi(year.c_str());
625 dateBegin=QDate(yearNum,monthNum,1);
626 dateEnd=dateBegin.addMonths(1).addDays(-1);
629 else if (! dateStr.empty()) {
631 unsigned short yearNum=atoi(dateStr.c_str());
632 dateBegin=QDate(yearNum,01,01);
633 dateEnd=QDate(yearNum,12,31);
637 catch (std::exception& e) {
639 LWARN <<
"Warning: " << e.what();
640 LWARN <<
"Failed parsing of date [" << dateStr <<
"]";
644 LDEBUG <<
"ContentStructuredDocument::parseDate" << dateStr <<
"=>" << dateBegin <<
"-" << dateEnd;
void addWeightedPropValue(const std::string &propName, const std::pair< std::string, float > &str)
std::pair< std::string, bool > getStringValue(std::string propName) const
void setStringValue(const std::string &propName, const std::string &val)
void addStringValue(const std::string &propName, const std::string &str)
void setDateIntervalValue(const std::string &propName, const std::pair< QDate, QDate > &val)
void setDateValue(const std::string &propName, const QDate &val)
void setIntValue(const std::string &propName, const uint64_t &val)
virtual FieldType nodeType()
void addProperty(const DocumentPropertyType &propType, const std::string &value)
void setPropagatedValue(const PropagatedProperties &toBePropagated)
const PropagatedProperties & getPropertyList() const
Element avec contenu texte.
unsigned long int getOffset()
virtual const QString & getElementName() const
virtual void addToCurrentOffset(const Lima::LimaString &value)
virtual const Lima::LimaString & getPropertyValue() const
void addSpaces(int nbSpaces)
virtual const DocumentPropertyType & getPropType()
void setOffset(unsigned long int offset)
void popDiscardableElement(unsigned int parserOffset)
void setDataToPreviousElement(StructuredXmlDocumentHandler *processor)
static void parseDate(const std::string &dateStr, QDate &dateBegin, QDate &dateEnd)
void addPart(const Lima::LimaString &text, const unsigned int offset)
Ajoute un couple (texte,offset) au dernier element.
IndexingDocumentElement * pushIndexingChild(const QString &elementName, unsigned int parserOffset, const DocumentPropertyType &propType)
void popIgnoredElement(unsigned int parserOffset)
void popIndexingElement(unsigned int parserOffset)
void setDataToElement(AbstractStructuredDocumentElement *absElement, const DocumentPropertyType &property, const std::string &data, StructuredXmlDocumentHandler *processor)
void popHierarchyElement(unsigned int parserOffset)
PresentationDocumentElement * pushPresentationChild(const QString &elementName, unsigned int parserOffset)
Ajoute un element a la pile de type presentation.
DocumentPropertyElement * addPropertyChild(const QString &elementName, unsigned int parserOffset, const DocumentPropertyType &type)
Ajoute un element a la pile de type propriete du noeud fils.
DiscardableDocumentElement * pushDiscardableChild(const QString &elementName, unsigned int parserOffset)
Ajoute un element a la pile de type noeud discardable.
static void parseWeightedValue(const std::string &weightedValueStr, std::string &value, float &score)
unsigned int getOffset()
retourne la position courante byte du dernier element, pour initialiser le suivant
IgnoredDocumentElement * pushIgnoredChild(const QString &elementName, unsigned int parserOffset, const DocumentPropertyType &propType)
void setDataToLastElement(const DocumentPropertyType &property, const std::string &data, StructuredXmlDocumentHandler *processor)
void popPresentationElement(unsigned int parserOffset)
HierarchyDocumentElement * pushHierarchyChild(const QString &elementName, unsigned int parserOffset, const DocumentPropertyType &propType)
Ajoute un element a la pile de type hierarchy.
~ContentStructuredDocument()
void popPropertyElement(unsigned int parserOffset)
Element d'un document Xml discardable Exemple <USELESS>private comment</USELESS> => " ...
Element d'un document XML definissant une propriete du noeud pere Exemple <filename>d1....
const StorageType & getStorageType() const
const CardinalityType & getValueCardinality() const
Element d'un document XML dont content est indexee Exemple <section lang="fre">yeah</section> Il peut...
bool hasPropType() override
Element d'un document XML de presentation Exemple <BOLD>important</BOLD> => " important " ...
const std::string & getId() const
get the object id
Handler pour les elements de parsing de document structure.
virtual void handleProperty(const DocumentsReader::DocumentPropertyType &property, const std::string &data)=0
std::string limastring2utf8stdstring(const Lima::LimaString &phrase, uint32_t size0)
Convert a wide string to a string , in dest up to size bytes.
StorageType
a type meaning the storage type of an attribute
@ STORAGE_WEIGHTED_PROPERTY
static const QString storageTypeTag[MAX_STORAGE_TYPE]
@ NODE_DISCARDABLE
root of XML file
@ NODE_PROPERTY
nodes which are not children of hierarchy nodes are ignored