For "foo" vs "Foo", the all-lowercase one wins
This commit is contained in:
parent
9019a6f827
commit
fedfcb8e44
@ -18,6 +18,10 @@
|
|||||||
#include "standard.h"
|
#include "standard.h"
|
||||||
#include "Candidate.h"
|
#include "Candidate.h"
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
|
using boost::algorithm::all;
|
||||||
|
using boost::algorithm::is_lower;
|
||||||
|
|
||||||
namespace YouCompleteMe
|
namespace YouCompleteMe
|
||||||
{
|
{
|
||||||
@ -57,15 +61,18 @@ Bitset LetterBitsetFromString( const std::string &text )
|
|||||||
return letter_bitset;
|
return letter_bitset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Candidate::Candidate( const std::string &text )
|
Candidate::Candidate( const std::string &text )
|
||||||
:
|
:
|
||||||
text_( text ),
|
text_( text ),
|
||||||
word_boundary_chars_( GetWordBoundaryChars( text ) ),
|
word_boundary_chars_( GetWordBoundaryChars( text ) ),
|
||||||
|
text_is_lowercase_( all( text, is_lower() ) ),
|
||||||
letters_present_( LetterBitsetFromString( text ) ),
|
letters_present_( LetterBitsetFromString( text ) ),
|
||||||
root_node_( new LetterNode( text ) )
|
root_node_( new LetterNode( text ) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Result Candidate::QueryMatchResult( const std::string &query ) const
|
Result Candidate::QueryMatchResult( const std::string &query ) const
|
||||||
{
|
{
|
||||||
LetterNode *node = root_node_.get();
|
LetterNode *node = root_node_.get();
|
||||||
@ -80,7 +87,8 @@ Result Candidate::QueryMatchResult( const std::string &query ) const
|
|||||||
node = list->front();
|
node = list->front();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result( true, &text_, word_boundary_chars_, query );
|
return Result( true, &text_, text_is_lowercase_, word_boundary_chars_,
|
||||||
|
query );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace YouCompleteMe
|
} // namespace YouCompleteMe
|
||||||
|
@ -59,6 +59,7 @@ private:
|
|||||||
|
|
||||||
std::string text_;
|
std::string text_;
|
||||||
std::string word_boundary_chars_;
|
std::string word_boundary_chars_;
|
||||||
|
bool text_is_lowercase_;
|
||||||
Bitset letters_present_;
|
Bitset letters_present_;
|
||||||
boost::scoped_ptr< LetterNode > root_node_;
|
boost::scoped_ptr< LetterNode > root_node_;
|
||||||
};
|
};
|
||||||
|
@ -52,12 +52,14 @@ Result::Result( bool is_subsequence )
|
|||||||
ratio_of_word_boundary_chars_in_query_( 0 ),
|
ratio_of_word_boundary_chars_in_query_( 0 ),
|
||||||
word_boundary_char_utilization_( 0 ),
|
word_boundary_char_utilization_( 0 ),
|
||||||
query_is_candidate_prefix_( false ),
|
query_is_candidate_prefix_( false ),
|
||||||
|
text_is_lowercase_( false ),
|
||||||
text_( NULL )
|
text_( NULL )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Result::Result( bool is_subsequence,
|
Result::Result( bool is_subsequence,
|
||||||
const std::string *text,
|
const std::string *text,
|
||||||
|
bool text_is_lowercase,
|
||||||
const std::string &word_boundary_chars,
|
const std::string &word_boundary_chars,
|
||||||
const std::string &query )
|
const std::string &query )
|
||||||
:
|
:
|
||||||
@ -66,10 +68,11 @@ Result::Result( bool is_subsequence,
|
|||||||
ratio_of_word_boundary_chars_in_query_( 0 ),
|
ratio_of_word_boundary_chars_in_query_( 0 ),
|
||||||
word_boundary_char_utilization_( 0 ),
|
word_boundary_char_utilization_( 0 ),
|
||||||
query_is_candidate_prefix_( false ),
|
query_is_candidate_prefix_( false ),
|
||||||
|
text_is_lowercase_( text_is_lowercase ),
|
||||||
text_( text )
|
text_( text )
|
||||||
{
|
{
|
||||||
if ( is_subsequence )
|
if ( is_subsequence )
|
||||||
SetResultFeaturesFromQuery( query, word_boundary_chars );
|
SetResultFeaturesFromQuery( word_boundary_chars, query );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,6 +85,7 @@ Result::Result( const Result& other )
|
|||||||
other.ratio_of_word_boundary_chars_in_query_ ),
|
other.ratio_of_word_boundary_chars_in_query_ ),
|
||||||
word_boundary_char_utilization_( other.word_boundary_char_utilization_ ),
|
word_boundary_char_utilization_( other.word_boundary_char_utilization_ ),
|
||||||
query_is_candidate_prefix_( other.query_is_candidate_prefix_ ),
|
query_is_candidate_prefix_( other.query_is_candidate_prefix_ ),
|
||||||
|
text_is_lowercase_( other.text_is_lowercase_ ),
|
||||||
text_( other.text_ )
|
text_( other.text_ )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -124,9 +128,7 @@ bool Result::operator< ( const Result &other ) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( query_is_candidate_prefix_ != other.query_is_candidate_prefix_ )
|
if ( query_is_candidate_prefix_ != other.query_is_candidate_prefix_ )
|
||||||
{
|
|
||||||
return query_is_candidate_prefix_;
|
return query_is_candidate_prefix_;
|
||||||
}
|
|
||||||
|
|
||||||
if ( !equal_wb_ratios )
|
if ( !equal_wb_ratios )
|
||||||
{
|
{
|
||||||
@ -142,17 +144,18 @@ bool Result::operator< ( const Result &other ) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( text_->length() != other.text_->length() )
|
if ( text_->length() != other.text_->length() )
|
||||||
{
|
|
||||||
return text_->length() < other.text_->length();
|
return text_->length() < other.text_->length();
|
||||||
}
|
|
||||||
|
if ( text_is_lowercase_ != other.text_is_lowercase_ )
|
||||||
|
return text_is_lowercase_;
|
||||||
|
|
||||||
return *text_ < *other.text_;
|
return *text_ < *other.text_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Result::SetResultFeaturesFromQuery(
|
void Result::SetResultFeaturesFromQuery(
|
||||||
const std::string &query,
|
const std::string &word_boundary_chars,
|
||||||
const std::string &word_boundary_chars )
|
const std::string &query)
|
||||||
{
|
{
|
||||||
if ( query.empty() || text_->empty() )
|
if ( query.empty() || text_->empty() )
|
||||||
return;
|
return;
|
||||||
|
@ -30,6 +30,7 @@ public:
|
|||||||
|
|
||||||
Result( bool is_subsequence,
|
Result( bool is_subsequence,
|
||||||
const std::string *text,
|
const std::string *text,
|
||||||
|
bool text_is_lowercase,
|
||||||
const std::string &word_boundary_chars,
|
const std::string &word_boundary_chars,
|
||||||
const std::string &query );
|
const std::string &query );
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ private:
|
|||||||
// number of word boundary matches / number of all word boundary chars
|
// number of word boundary matches / number of all word boundary chars
|
||||||
double word_boundary_char_utilization_;
|
double word_boundary_char_utilization_;
|
||||||
bool query_is_candidate_prefix_;
|
bool query_is_candidate_prefix_;
|
||||||
|
bool text_is_lowercase_;
|
||||||
const std::string *text_;
|
const std::string *text_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -197,5 +197,17 @@ TEST_F( CompleterTest, ShorterCandidateWins )
|
|||||||
"CompleterTest" ) );
|
"CompleterTest" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F( CompleterTest, SameLowercaseCandidateWins )
|
||||||
|
{
|
||||||
|
Pylist results;
|
||||||
|
Completer( Candidates(
|
||||||
|
"foobar",
|
||||||
|
"Foobar" ) ).GetCandidatesForQuery( "foo", results );
|
||||||
|
|
||||||
|
EXPECT_THAT( ToStringVector( results ),
|
||||||
|
ElementsAre( "foobar",
|
||||||
|
"Foobar" ) );
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace YouCompleteMe
|
} // namespace YouCompleteMe
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user