[Opentrep-svn] SF.net SVN: opentrep:[137] trunk/opentrep/opentrep
Status: Beta
Brought to you by:
denis_arnaud
From: <den...@us...> - 2009-07-18 15:15:47
|
Revision: 137 http://opentrep.svn.sourceforge.net/opentrep/?rev=137&view=rev Author: denis_arnaud Date: 2009-07-18 15:15:40 +0000 (Sat, 18 Jul 2009) Log Message: ----------- [Dev] Better debugging logs. Modified Paths: -------------- trunk/opentrep/opentrep/bom/DocumentList.hpp trunk/opentrep/opentrep/bom/PlaceList.hpp trunk/opentrep/opentrep/bom/Result.cpp trunk/opentrep/opentrep/bom/Result.hpp trunk/opentrep/opentrep/bom/ResultHolder.cpp trunk/opentrep/opentrep/bom/ResultHolder.hpp trunk/opentrep/opentrep/bom/StringMatcher.cpp trunk/opentrep/opentrep/bom/StringMatcher.hpp trunk/opentrep/opentrep/bom/sources.mk trunk/opentrep/opentrep/command/RequestInterpreter.cpp trunk/opentrep/opentrep/factory/FacPlaceHolder.cpp Added Paths: ----------- trunk/opentrep/opentrep/bom/Document.cpp trunk/opentrep/opentrep/bom/Document.hpp Added: trunk/opentrep/opentrep/bom/Document.cpp =================================================================== --- trunk/opentrep/opentrep/bom/Document.cpp (rev 0) +++ trunk/opentrep/opentrep/bom/Document.cpp 2009-07-18 15:15:40 UTC (rev 137) @@ -0,0 +1,59 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// C +#include <cassert> +// OpenTREP +#include <opentrep/bom/Document.hpp> + +namespace OPENTREP { + + // ////////////////////////////////////////////////////////////////////// + Document::Document () { + } + + // ////////////////////////////////////////////////////////////////////// + Document::Document (const Document& iDocument) + : _queryString (iDocument._queryString), + _document (iDocument._document), + _documentList (iDocument._documentList) { + } + + // ////////////////////////////////////////////////////////////////////// + Document::~Document () { + } + + // ////////////////////////////////////////////////////////////////////// + const std::string Document::describeShortKey() const { + std::ostringstream oStr; + oStr << _queryString; + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + const std::string Document::describeKey() const { + return describeShortKey(); + } + + // ////////////////////////////////////////////////////////////////////// + std::string Document::toString() const { + std::ostringstream oStr; + oStr << describeShortKey() << std::endl; + + const Xapian::docid& lDocID = _document.get_docid(); + oStr << "Document ID " << lDocID << "\t" << _percentage + << "% [" << _document.get_data() << "]"; + + return oStr.str(); + } + + // ////////////////////////////////////////////////////////////////////// + void Document::toStream (std::ostream& ioOut) const { + ioOut << toString(); + } + + // ////////////////////////////////////////////////////////////////////// + void Document::fromStream (std::istream& ioIn) { + } + +} Added: trunk/opentrep/opentrep/bom/Document.hpp =================================================================== --- trunk/opentrep/opentrep/bom/Document.hpp (rev 0) +++ trunk/opentrep/opentrep/bom/Document.hpp 2009-07-18 15:15:40 UTC (rev 137) @@ -0,0 +1,123 @@ +#ifndef __OPENTREP_BOM_DOCUMENT_HPP +#define __OPENTREP_BOM_DOCUMENT_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <list> +// OpenTREP +#include <opentrep/OPENTREP_Types.hpp> +#include <opentrep/bom/BomAbstract.hpp> +// Xapian +#include <xapian.h> + +namespace OPENTREP { + + // //////////////// Type definitions ///////////////// + /** List of Xapian documents. */ + typedef std::list<Xapian::Document> XapianDocumentList_T; + + + // //////////////// Main Class ///////////////// + /** Structure wrapping a Xapian document having matched part of a + given query string. + <br>It is a structure, as it is aimed to be temporary, the time + a Result object be created with the corresponding content. */ + struct Document : public BomAbstract { + public: + // ////////////////// Getters //////////////// + /** Get the query string. */ + const TravelQuery_T& getTravelQuery() { + return _queryString; + } + + /** Get the matching Xapian document. */ + const Xapian::Document& getXapianDocument() const { + return _document; + } + + /** Get the matching percentage associated to the Xapian document. */ + const Xapian::percent& getXapianPercentage() const { + return _percentage; + } + + /** Get the extra list of matching Xapian documents. */ + const XapianDocumentList_T& getExtraDocumentList() const { + return _documentList; + } + + + // ////////////////// Setters //////////////// + void setQueryString (const TravelQuery_T& iQueryString) { + _queryString = iQueryString; + } + + /** Set the matching Xapian document. */ + void setXapianDocument (const Xapian::Document& iMatchingDocument) { + _document = iMatchingDocument; + } + + /** Set the matching percentage associated to the Xapian document. */ + void setXapianPercentage (const Xapian::percent& iPercentage) { + _percentage = iPercentage; + } + + /** Add a matching Xapian document (having the same matching percentage). */ + void addExtraDocument (const Xapian::Document& iMatchingDocument) { + _documentList.push_back (iMatchingDocument); + } + + + public: + // /////////// Display support methods ///////// + /** Dump a Business Object into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream& ioOut) const; + + /** Read a Business Object from an input stream. + @param istream& the input stream. */ + void fromStream (std::istream& ioIn); + + /** Get the serialised version of the Business Object. */ + std::string toString() const; + + /** Get a string describing the whole key (differentiating two objects + at any level). */ + const std::string describeKey() const; + + /** Get a string describing the short key (differentiating two objects + at the same level). */ + const std::string describeShortKey() const; + + + public: + // //////////////// Constructors and Destructors ///////////// + /** Default constructor. */ + Document (); + /** Default copy constructor. */ + Document (const Document&); + /** Default destructor. */ + ~Document (); + + + private: + // ///////////////// Attributes ////////////////// + /** Query string with which a Xapian full text search is done. */ + TravelQuery_T _queryString; + + /** Matching percentage, as returned by the Xapian full text search. + <br>Generally, that percentage is equal to, or close to, 100%. */ + Xapian::percent _percentage; + + /** Matching document, as returned by the Xapian full text search. */ + Xapian::Document _document; + + /** List of Xapian documents having the same matching percentage. + <br>Hence, any of those other Xapian documents could have been + chosen, instead of the main one. */ + XapianDocumentList_T _documentList; + }; + +} +#endif // __OPENTREP_BOM_DOCUMENT_HPP Modified: trunk/opentrep/opentrep/bom/DocumentList.hpp =================================================================== --- trunk/opentrep/opentrep/bom/DocumentList.hpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/DocumentList.hpp 2009-07-18 15:15:40 UTC (rev 137) @@ -8,20 +8,14 @@ #include <list> // OpenTREP #include <opentrep/OPENTREP_Types.hpp> +#include <opentrep/bom/Document.hpp> // Xapian #include <xapian.h> namespace OPENTREP { - /** Xapian document and its associated matching percentage. */ - typedef std::pair<Xapian::percent, Xapian::Document> MatchingDocument_T; - - /** A matching Xapian document, along with the query string which it - matches. */ - typedef std::pair<TravelQuery_T, MatchingDocument_T> QueryAndDocument_T; - /** List of matching Xapian documents. */ - typedef std::list<QueryAndDocument_T> DocumentList_T; + typedef std::list<Document> DocumentList_T; } #endif // __OPENTREP_BOM_DOCUMENTLIST_HPP Modified: trunk/opentrep/opentrep/bom/PlaceList.hpp =================================================================== --- trunk/opentrep/opentrep/bom/PlaceList.hpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/PlaceList.hpp 2009-07-18 15:15:40 UTC (rev 137) @@ -14,9 +14,10 @@ class Place; // ///////////// Type definitions //////////////////// - typedef std::size_t PlaceID_T; + // typedef std::size_t PlaceID_T; // typedef std::map<PlaceID_T, Place*> PlaceDirectList_T; - typedef std::map<std::string, Place*> PlaceList_T; + + typedef std::multimap<std::string, Place*> PlaceList_T; typedef std::list<Place*> PlaceOrderedList_T; } Modified: trunk/opentrep/opentrep/bom/Result.cpp =================================================================== --- trunk/opentrep/opentrep/bom/Result.cpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/Result.cpp 2009-07-18 15:15:40 UTC (rev 137) @@ -41,14 +41,7 @@ // ////////////////////////////////////////////////////////////////////// std::string Result::toString() const { std::ostringstream oStr; - oStr << describeShortKey() << std::endl; - - const Xapian::percent& lPercentage = _matchingDocument.first; - const Xapian::Document& lDocument = _matchingDocument.second; - const Xapian::docid& lDocID = lDocument.get_docid(); - oStr << "Document ID " << lDocID << "\t" << lPercentage - << "% [" << lDocument.get_data() << "]" << std::endl; - + oStr << _matchingDocument.toString(); return oStr.str(); } Modified: trunk/opentrep/opentrep/bom/Result.hpp =================================================================== --- trunk/opentrep/opentrep/bom/Result.hpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/Result.hpp 2009-07-18 15:15:40 UTC (rev 137) @@ -7,7 +7,7 @@ // OpenTREP #include <opentrep/OPENTREP_Types.hpp> #include <opentrep/bom/BomAbstract.hpp> -#include <opentrep/bom/DocumentList.hpp> +#include <opentrep/bom/Document.hpp> namespace OPENTREP { @@ -27,19 +27,19 @@ /** Get the Matching Xapian document object, along with its corresponding matching percentage. */ - const MatchingDocument_T& getMatchingDocument() const { + const Document& getMatchingDocument() const { return _matchingDocument; } /** Retrieve the percentage corresponding to the matching Xapian document object. */ - const Xapian::percent& getPercentage() const { - return _matchingDocument.first; + const Xapian::percent& getXapianPercentage() const { + return _matchingDocument.getXapianPercentage(); } /** Retrieve the matching Xapian document object. */ - const Xapian::Document& getDocument() const { - return _matchingDocument.second; + const Xapian::Document& getXapianDocument() const { + return _matchingDocument.getXapianDocument(); } @@ -51,17 +51,10 @@ /** Set the matching Xapian document object and its corresponding matching percentage. */ - void setMatchingDocument (const MatchingDocument_T& iMatchingDocument) { + void setMatchingDocument (const Document& iMatchingDocument) { _matchingDocument = iMatchingDocument; } - /** Set the matching Xapian document object and its corresponding - matching percentage. */ - void setQueryAndDocument (const QueryAndDocument_T& iQueryAndDocument) { - _queryString = iQueryAndDocument.first; - _matchingDocument = iQueryAndDocument.second; - } - public: // /////////// Display support methods ///////// @@ -112,7 +105,7 @@ /** Matching Xapian document object, along with its corresponding matching percentage. */ - MatchingDocument_T _matchingDocument; + Document _matchingDocument; }; } Modified: trunk/opentrep/opentrep/bom/ResultHolder.cpp =================================================================== --- trunk/opentrep/opentrep/bom/ResultHolder.cpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/ResultHolder.cpp 2009-07-18 15:15:40 UTC (rev 137) @@ -69,7 +69,7 @@ // ////////////////////////////////////////////////////////////////////// bool ResultHolder::searchString (TravelQuery_T& ioPartialQueryString, - MatchingDocument_T& ioMatchingDocument) { + Document& ioMatchingDocument) { bool oFoundDocument = false; // Catch any Xapian::Error exceptions thrown @@ -78,11 +78,8 @@ bool shouldStop = false; while (shouldStop == false) { // DEBUG - /* - OPENTREP_LOG_DEBUG (std::endl << "--------------------------------" - << std::endl << "Current query string: `" << ioPartialQueryString - << "'"); - */ + OPENTREP_LOG_DEBUG ("Current query string: `" + << ioPartialQueryString << "'"); // Retrieve the list of documents matching the query string Xapian::MSet lMatchingSet; @@ -125,11 +122,10 @@ bool shouldStop = false; while (shouldStop == false) { // DEBUG - /* - OPENTREP_LOG_DEBUG (std::endl - << "================================" << std::endl - << "Current query string: `" << lRemainingQueryString << "'"); - */ + OPENTREP_LOG_DEBUG ("---------------------") + OPENTREP_LOG_DEBUG ("Remaining part of the query string: `" + << lRemainingQueryString << "'"); + /** Search with the initial full string, then by removing a word if there was no result, then by removing another word if there was @@ -143,14 +139,17 @@ furthest right words, so that the remaining left part be matched against the Xapian database). */ - MatchingDocument_T lMatchingDocument; + Document lMatchingDocument; const bool hasFoundDocument = searchString (lQueryString, lMatchingDocument); if (hasFoundDocument == true) { - const QueryAndDocument_T lQueryAndDocument (lQueryString, - lMatchingDocument); - ioDocumentList.push_back (lQueryAndDocument); + lMatchingDocument.setQueryString (lQueryString); + ioDocumentList.push_back (lMatchingDocument); + + // DEBUG + OPENTREP_LOG_DEBUG ("==> Matching of the query string: `" + << lQueryString << "'"); } /** Modified: trunk/opentrep/opentrep/bom/ResultHolder.hpp =================================================================== --- trunk/opentrep/opentrep/bom/ResultHolder.hpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/ResultHolder.hpp 2009-07-18 15:15:40 UTC (rev 137) @@ -47,7 +47,7 @@ @param TravelQuery_T& The partial query string. @param MatchingDocument_T& The best matching Xapian document (if found). @return bool Whether such a best matching document has been found. */ - bool searchString(TravelQuery_T& ioPartialQueryString, MatchingDocument_T&); + bool searchString (TravelQuery_T& ioPartialQueryString, Document&); public: Modified: trunk/opentrep/opentrep/bom/StringMatcher.cpp =================================================================== --- trunk/opentrep/opentrep/bom/StringMatcher.cpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/StringMatcher.cpp 2009-07-18 15:15:40 UTC (rev 137) @@ -4,7 +4,8 @@ // C #include <cassert> // STL -#include <iostream> +#include <istream> +#include <ostream> #include <sstream> #include <string> #include <list> @@ -73,7 +74,7 @@ } } catch (const Xapian::Error& error) { - std::cerr << "Exception: " << error.get_msg() << std::endl; + OPENTREP_LOG_ERROR ("Exception: " << error.get_msg()); } } @@ -267,14 +268,14 @@ */ } catch (const Xapian::Error& error) { - std::cerr << "Exception: " << error.get_msg() << std::endl; + OPENTREP_LOG_ERROR ("Exception: " << error.get_msg()); } } // ////////////////////////////////////////////////////////////////////// bool StringMatcher:: extractBestMatchingDocumentFromMSet (const Xapian::MSet& iMatchingSet, - MatchingDocument_T& ioMatchingDocument) { + Document& ioMatchingDocument) { bool oFoundDocument = false; if (iMatchingSet.empty() == true) { @@ -290,9 +291,23 @@ same: it appears random). */ Xapian::MSetIterator itDoc = iMatchingSet.begin(); - ioMatchingDocument.first = itDoc.get_percent(); - ioMatchingDocument.second = itDoc.get_document(); + const Xapian::percent& lBestPercentage = itDoc.get_percent(); + ioMatchingDocument.setXapianPercentage (lBestPercentage); + ioMatchingDocument.setXapianDocument (itDoc.get_document()); + /** Add all the Xapian documents having reached the same matching + percentage. */ + for ( ; itDoc != iMatchingSet.end(); ++itDoc) { + const Xapian::percent& lPercentage = itDoc.get_percent(); + + if (lPercentage == lBestPercentage) { + ioMatchingDocument.addExtraDocument (itDoc.get_document()); + + } else { + break; + } + } + return oFoundDocument; } Modified: trunk/opentrep/opentrep/bom/StringMatcher.hpp =================================================================== --- trunk/opentrep/opentrep/bom/StringMatcher.hpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/StringMatcher.hpp 2009-07-18 15:15:40 UTC (rev 137) @@ -9,7 +9,7 @@ // OpenTREP #include <opentrep/bom/BomAbstract.hpp> #include <opentrep/bom/WordList.hpp> -#include <opentrep/bom/DocumentList.hpp> +#include <opentrep/bom/Document.hpp> // Forward declarations namespace Xapian { @@ -38,8 +38,7 @@ @return bool Whether or not there was a matching document. */ static bool - extractBestMatchingDocumentFromMSet (const Xapian::MSet&, - MatchingDocument_T&); + extractBestMatchingDocumentFromMSet (const Xapian::MSet&, Document&); /** Remove the word furthest at right. */ static void removeOneWord (std::string& ioQueryString); Modified: trunk/opentrep/opentrep/bom/sources.mk =================================================================== --- trunk/opentrep/opentrep/bom/sources.mk 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/bom/sources.mk 2009-07-18 15:15:40 UTC (rev 137) @@ -9,6 +9,7 @@ $(top_srcdir)/opentrep/bom/Place.hpp \ $(top_srcdir)/opentrep/bom/PlaceList.hpp \ $(top_srcdir)/opentrep/bom/PlaceHolder.hpp \ + $(top_srcdir)/opentrep/bom/Document.hpp \ $(top_srcdir)/opentrep/bom/DocumentList.hpp \ $(top_srcdir)/opentrep/bom/Result.hpp \ $(top_srcdir)/opentrep/bom/ResultList.hpp \ @@ -22,6 +23,7 @@ $(top_srcdir)/opentrep/bom/Names.cpp \ $(top_srcdir)/opentrep/bom/Place.cpp \ $(top_srcdir)/opentrep/bom/PlaceHolder.cpp \ + $(top_srcdir)/opentrep/bom/Document.cpp \ $(top_srcdir)/opentrep/bom/Result.cpp \ $(top_srcdir)/opentrep/bom/ResultHolder.cpp \ $(top_srcdir)/opentrep/bom/StringMatcher.cpp Modified: trunk/opentrep/opentrep/command/RequestInterpreter.cpp =================================================================== --- trunk/opentrep/opentrep/command/RequestInterpreter.cpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/command/RequestInterpreter.cpp 2009-07-18 15:15:40 UTC (rev 137) @@ -39,6 +39,10 @@ ResultHolder& lResultHolder = FacResultHolder::instance().create (iTravelQuery, lXapianDatabase); + // DEBUG + OPENTREP_LOG_DEBUG (std::endl + << "========================================="); + // Main algorithm DocumentList_T lDocumentList; lResultHolder.searchString (lDocumentList); @@ -49,14 +53,14 @@ itDoc != lDocumentList.end(); ++itDoc) { // Retrieve both the Xapian document object and the corresponding // matching percentage (most of the time, it is 100%) - const QueryAndDocument_T& lQueryAndDocument = *itDoc; + const Document& lMatchingDocument = *itDoc; // Create a Result object Result& lResult = FacResult::instance().create (lXapianDatabase); // Fill the Result object with both the corresponding Document object // and its associated query string - lResult.setQueryAndDocument (lQueryAndDocument); + lResult.setMatchingDocument (lMatchingDocument); // Add the Result object (holding the list of matching // documents) to the dedicated list. @@ -83,8 +87,9 @@ assert (lResult_ptr != NULL); // Retrieve the parameters of the best matching document - const Xapian::Document& lDocument = lResult_ptr->getDocument(); - const Xapian::percent& lDocPercentage = lResult_ptr->getPercentage(); + const Xapian::Document& lDocument = lResult_ptr->getXapianDocument(); + const Xapian::percent& lDocPercentage = + lResult_ptr->getXapianPercentage(); const Xapian::docid& lDocID = lDocument.get_docid(); const std::string& lDocData = lDocument.get_data(); Modified: trunk/opentrep/opentrep/factory/FacPlaceHolder.cpp =================================================================== --- trunk/opentrep/opentrep/factory/FacPlaceHolder.cpp 2009-07-18 09:33:50 UTC (rev 136) +++ trunk/opentrep/opentrep/factory/FacPlaceHolder.cpp 2009-07-18 15:15:40 UTC (rev 137) @@ -59,15 +59,16 @@ ioPlace._placeHolder = &ioPlaceHolder; // Add the Place to the PlaceHolder internal map (of Place objects) - const bool insertSucceeded = ioPlaceHolder._placeList. - insert (PlaceList_T::value_type (ioPlace.describeShortKey(), - &ioPlace)).second; - if (insertSucceeded == false) { - OPENTREP_LOG_ERROR ("Insertion failed for " - << ioPlaceHolder.describeKey() - << " and " << ioPlace.describeShortKey()); - assert (insertSucceeded == true); - } + // const bool insertSucceeded = + ioPlaceHolder._placeList. + insert (PlaceList_T::value_type (ioPlace.describeShortKey(), &ioPlace)); + +// if (insertSucceeded == false) { +// OPENTREP_LOG_ERROR ("Insertion failed for " +// << ioPlaceHolder.describeKey() +// << " and " << ioPlace.describeShortKey()); +// assert (insertSucceeded == true); +// } // Add the Place to the PlaceHolder internal list (of Place objects) ioPlaceHolder._placeOrderedList.push_back (&ioPlace); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |