2014-01-13 14:08:43 -05:00
|
|
|
// Copyright (C) 2011, 2012 Google Inc.
|
2012-04-15 19:57:10 -04:00
|
|
|
//
|
|
|
|
// This file is part of YouCompleteMe.
|
|
|
|
//
|
|
|
|
// YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#ifndef RESULT_H_CZYD2SGN
|
|
|
|
#define RESULT_H_CZYD2SGN
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2013-01-19 23:10:52 -05:00
|
|
|
namespace YouCompleteMe {
|
2012-04-15 19:57:10 -04:00
|
|
|
|
2013-01-19 23:10:52 -05:00
|
|
|
class Result {
|
2012-04-15 19:57:10 -04:00
|
|
|
public:
|
2012-07-20 00:17:39 -04:00
|
|
|
Result();
|
2012-04-15 19:57:10 -04:00
|
|
|
explicit Result( bool is_subsequence );
|
|
|
|
|
|
|
|
Result( bool is_subsequence,
|
|
|
|
const std::string *text,
|
2012-04-17 01:13:05 -04:00
|
|
|
bool text_is_lowercase,
|
2012-06-24 18:35:00 -04:00
|
|
|
int char_match_index_sum,
|
2012-04-15 19:57:10 -04:00
|
|
|
const std::string &word_boundary_chars,
|
|
|
|
const std::string &query );
|
|
|
|
|
|
|
|
bool operator< ( const Result &other ) const;
|
|
|
|
|
2013-01-19 23:10:52 -05:00
|
|
|
inline bool IsSubsequence() const {
|
2012-04-15 19:57:10 -04:00
|
|
|
return is_subsequence_;
|
|
|
|
}
|
|
|
|
|
2013-01-19 23:10:52 -05:00
|
|
|
inline const std::string *Text() const {
|
2012-04-15 19:57:10 -04:00
|
|
|
return text_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetResultFeaturesFromQuery(
|
2013-01-19 23:10:52 -05:00
|
|
|
const std::string &query,
|
|
|
|
const std::string &word_boundary_chars );
|
2012-04-15 19:57:10 -04:00
|
|
|
|
2012-07-15 22:40:24 -04:00
|
|
|
// true when the query for which the result was created was an empty string;
|
|
|
|
// in these cases we just use a lexicographic comparison
|
|
|
|
bool query_is_empty_;
|
2012-04-15 19:57:10 -04:00
|
|
|
|
2012-06-24 18:35:00 -04:00
|
|
|
// true when the characters of the query are a subsequence of the characters
|
|
|
|
// in the candidate text, e.g. the characters "abc" are a subsequence for
|
|
|
|
// "xxaygbefc" but not for "axxcb" since they occur in the correct order ('a'
|
|
|
|
// then 'b' then 'c') in the first string but not in the second.
|
2012-04-15 19:57:10 -04:00
|
|
|
bool is_subsequence_;
|
2012-06-24 18:35:00 -04:00
|
|
|
|
|
|
|
// true when the first character of the query and the candidate match
|
2012-04-15 19:57:10 -04:00
|
|
|
bool first_char_same_in_query_and_text_;
|
|
|
|
|
|
|
|
// number of word boundary matches / number of chars in query
|
|
|
|
double ratio_of_word_boundary_chars_in_query_;
|
|
|
|
|
|
|
|
// number of word boundary matches / number of all word boundary chars
|
|
|
|
double word_boundary_char_utilization_;
|
2012-06-24 18:35:00 -04:00
|
|
|
|
|
|
|
// true when the query is a prefix of the candidate string, e.g. "foo" query
|
|
|
|
// for "foobar" candidate.
|
2012-04-15 19:57:10 -04:00
|
|
|
bool query_is_candidate_prefix_;
|
2012-06-24 18:35:00 -04:00
|
|
|
|
|
|
|
// true when the candidate text is all lowercase, e.g. "foo" candidate.
|
2012-04-17 01:13:05 -04:00
|
|
|
bool text_is_lowercase_;
|
2012-06-24 18:35:00 -04:00
|
|
|
|
|
|
|
// The sum of the indexes of all the letters the query "hit" in the candidate
|
|
|
|
// text. For instance, the result for the query "abc" in the candidate
|
|
|
|
// "012a45bc8" has char_match_index_sum of 3 + 6 + 7 = 16 because those are
|
|
|
|
// the char indexes of those letters in the candidate string.
|
|
|
|
int char_match_index_sum_;
|
|
|
|
|
|
|
|
// points to the full candidate text
|
2012-04-15 19:57:10 -04:00
|
|
|
const std::string *text_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-02-10 22:55:05 -05:00
|
|
|
template< class T >
|
|
|
|
struct ResultAnd {
|
2013-09-25 13:56:46 -04:00
|
|
|
// TODO: Swap the order of these parameters
|
2013-02-10 22:55:05 -05:00
|
|
|
ResultAnd( T extra_object, const Result &result )
|
|
|
|
: extra_object_( extra_object ), result_( result ) {}
|
|
|
|
|
|
|
|
bool operator< ( const ResultAnd &other ) const {
|
|
|
|
return result_ < other.result_;
|
|
|
|
}
|
|
|
|
|
|
|
|
T extra_object_;
|
|
|
|
Result result_;
|
|
|
|
};
|
|
|
|
|
2013-02-23 20:54:04 -05:00
|
|
|
template< class T >
|
2013-03-23 13:47:30 -04:00
|
|
|
struct ResultAnd<T * > {
|
|
|
|
ResultAnd( const T *extra_object, const Result &result )
|
2013-02-23 20:54:04 -05:00
|
|
|
: extra_object_( extra_object ), result_( result ) {}
|
|
|
|
|
|
|
|
bool operator< ( const ResultAnd &other ) const {
|
|
|
|
return result_ < other.result_;
|
|
|
|
}
|
|
|
|
|
2013-03-23 13:47:30 -04:00
|
|
|
const T *extra_object_;
|
2013-02-23 20:54:04 -05:00
|
|
|
Result result_;
|
|
|
|
};
|
|
|
|
|
2012-04-15 19:57:10 -04:00
|
|
|
} // namespace YouCompleteMe
|
|
|
|
|
|
|
|
#endif /* end of include guard: RESULT_H_CZYD2SGN */
|
|
|
|
|