#ifndef ANUBIS_SEARCHER_HDR #define ANUBIS_SEARCHER_HDR #include #include "concordia/common/config.hpp" #include "concordia/common/utils.hpp" #include "concordia/substring_occurence.hpp" #include "concordia/concordia_exception.hpp" #include "concordia/concordia_config.hpp" #include "concordia/concordia_search_result.hpp" #include "concordia/anubis_search_result.hpp" #include "concordia/tm_matches.hpp" #include #include /*! Class for searching using Concordia algorithm. All searches are performed on data structures passed to the methods of this class by smart pointers. */ class ConcordiaSearcher { public: explicit ConcordiaSearcher(); /*! Destructor. */ virtual ~ConcordiaSearcher(); /*! Performs concordia lookup on the RAM-based index. This is a unique library functionality, designed to facilitate Computer-Aided Translation. For more info see \ref tutorial1_3. \param result variable to store the result \param T hashed index to search in \param markers markers array for the needs of searching \param SA suffix array for the needs of searching \param pattern pattern to be searched in the index. This pattern needs to be hashed. \throws ConcordiaException */ void concordiaSearch( boost::shared_ptr result, boost::shared_ptr > T, boost::shared_ptr > markers, boost::shared_ptr > SA, const std::vector & pattern) throw(ConcordiaException); /*! \deprecated Finds the examples from the index, whose resemblance to the pattern is maximal. This method may perform very slow, try using concordiaSearch instead. \param config concordia config object (to read the anubis threshold parameter) \param T hashed index to search in \param markers markers array for the needs of searching \param SA suffix array for the needs of searching \param pattern pattern to be searched in the index. This pattern needs to be hashed. \returns vector of results \throws ConcordiaException */ std::vector anubisSearch( boost::shared_ptr config, boost::shared_ptr > T, boost::shared_ptr > markers, boost::shared_ptr > SA, const std::vector & pattern) throw(ConcordiaException); /*! Generates map of all examples in the index which have at least one word in common with the pattern. This method is internally used in anubisSearch and may perform slow. \param T hashed index to search in \param markers markers array for the needs of searching \param SA suffix array for the needs of searching \param pattern pattern to be searched in the index. This pattern needs to be hashed. \returns generated map \throws ConcordiaException */ boost::shared_ptr getTmMatches( boost::shared_ptr > T, boost::shared_ptr > markers, boost::shared_ptr > SA, const std::vector & pattern) throw(ConcordiaException); /*! Looks for fragments in the index which have the longest common prefix with the pattern. This method return the list of locations of these longest fragments (as return value) and their length in the length parameter. There is a tight limit on the number of longest fragments (currently set to 3). This method is used in conordiaSearch. \param T hashed index to search in \param markers markers array for the needs of searching \param SA suffix array for the needs of searching \param pattern pattern to be searched in the index. This pattern needs to be hashed. \param length the returned length of the longest fragments \returns list of locations of the longest fragments \throws ConcordiaException */ std::vector lcpSearch( boost::shared_ptr > T, boost::shared_ptr > markers, boost::shared_ptr > SA, const std::vector & pattern, SUFFIX_MARKER_TYPE & length) throw(ConcordiaException); private: void _collectResults(std::vector & result, boost::shared_ptr > markers, boost::shared_ptr > SA, saidx_t left, saidx_t size); void _addToMap(boost::shared_ptr > SA, boost::shared_ptr > markers, boost::shared_ptr tmMatchesMap, saidx_t sa_pos, SUFFIX_MARKER_TYPE totalPatternLength, SUFFIX_MARKER_TYPE matchedFragmentLength, SUFFIX_MARKER_TYPE patternOffset); bool _getOccurenceFromSA(boost::shared_ptr > SA, boost::shared_ptr > markers, saidx_t sa_pos, SubstringOccurence & occurence); void _addOccurenceToMap(boost::shared_ptr tmMatchesMap, SubstringOccurence & occurence, SUFFIX_MARKER_TYPE totalPatternLength, SUFFIX_MARKER_TYPE matchedFragmentLength, SUFFIX_MARKER_TYPE patternOffset); }; #endif