Skip to content

Commit

Permalink
Configurable parameter for DSL headwords' maximum size.
Browse files Browse the repository at this point in the history
By default, it is unchanged, still 256.

In those rare cases when users really need more lengthy
headwords, they could adjust the config file,
maxHeadwordSize parameter.
  • Loading branch information
Tvangeste committed Jan 11, 2013
1 parent c40de2d commit 7496f5f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions btreeidx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -900,14 +900,14 @@ static uint32_t buildBtreeNode( IndexedWords::const_iterator & nextIndex,
return offset;
}

void IndexedWords::addWord( wstring const & word, uint32_t articleOffset )
void IndexedWords::addWord( wstring const & word, uint32_t articleOffset, unsigned int maxHeadwordSize )
{
wchar const * wordBegin = word.c_str();
string::size_type wordSize = word.size();

// Safeguard us against various bugs here. Don't attempt adding words
// which are freakishly huge.
if ( wordSize > 256 )
if ( wordSize > maxHeadwordSize )
return;

// Skip any leading whitespace
Expand Down
2 changes: 1 addition & 1 deletion btreeidx.hh
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct IndexedWords: public map< string, vector< WordArticleLink > >
/// Instead of adding to the map directly, use this function. It does folding
/// itself, and for phrases/sentences it adds additional entries beginning with
/// each new word.
void addWord( wstring const & word, uint32_t articleOffset );
void addWord( wstring const & word, uint32_t articleOffset, unsigned int maxHeadwordSize = 256U );

/// Differs from addWord() in that it only adds a single entry. We use this
/// for zip's file names.
Expand Down
13 changes: 13 additions & 0 deletions config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,15 @@ Class load() throw( exError )
if ( !root.namedItem( "maxPictureWidth" ).isNull() )
c.maxPictureWidth = root.namedItem( "maxPictureWidth" ).toElement().text().toInt();

if ( !root.namedItem( "maxHeadwordSize" ).isNull() )
{
unsigned int value = root.namedItem( "maxHeadwordSize" ).toElement().text().toUInt();
if ( value != 0 ) // 0 is invalid value for our purposes
{
c.maxHeadwordSize = value;
}
}

return c;
}

Expand Down Expand Up @@ -1405,6 +1414,10 @@ void save( Class const & c ) throw( exError )
opt = dd.createElement( "maxPictureWidth" );
opt.appendChild( dd.createTextNode( QString::number( c.maxPictureWidth ) ) );
root.appendChild( opt );

opt = dd.createElement( "maxHeadwordSize" );
opt.appendChild( dd.createTextNode( QString::number( c.maxHeadwordSize ) ) );
root.appendChild( opt );
}

QByteArray result( dd.toByteArray() );
Expand Down
6 changes: 5 additions & 1 deletion config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,16 @@ struct Class

int maxPictureWidth; // Maximum picture width

/// Maximum size for the headwords.
/// Bigger headwords won't be indexed. For now, only in DSL.
unsigned int maxHeadwordSize;

QString editDictionaryCommandLine; // Command line to call external editor for dictionary

Class(): lastMainGroupId( 0 ), lastPopupGroupId( 0 ),
pinPopupWindow( false ), showingDictBarNames( false ),
usingSmallIconsInToolbars( false ), maxDictionaryRefsInContextMenu( 20 ),
maxPictureWidth( 0 )
maxPictureWidth( 0 ), maxHeadwordSize ( 256U )
{}
Group * getGroup( unsigned id );
Group const * getGroup( unsigned id ) const;
Expand Down
6 changes: 3 additions & 3 deletions dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
vector< string > const & fileNames,
string const & indicesDir,
Dictionary::Initializing & initializing,
int maxPictureWidth )
int maxPictureWidth, unsigned int maxHeadwordSize )
throw( std::exception )
{
vector< sptr< Dictionary::Class > > dictionaries;
Expand Down Expand Up @@ -1765,7 +1765,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
{
unescapeDsl( *j );
normalizeHeadword( *j );
indexedWords.addWord( *j, descOffset );
indexedWords.addWord( *j, descOffset, maxHeadwordSize );
}

++articleCount;
Expand Down Expand Up @@ -1829,7 +1829,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
unescapeDsl( (*i).headword );
normalizeHeadword( (*i).headword );

indexedWords.addWord( (*i).headword, descOffset );
indexedWords.addWord( (*i).headword, descOffset, maxHeadwordSize );

++articleCount;
++wordCount;
Expand Down
2 changes: 1 addition & 1 deletion dsl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
vector< string > const & fileNames,
string const & indicesDir,
Dictionary::Initializing &,
int maxPictureWidth )
int maxPictureWidth, unsigned int maxHeadwordSize )
throw( std::exception );

}
Expand Down
6 changes: 4 additions & 2 deletions loaddictionaries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ LoadDictionaries::LoadDictionaries( Config::Class const & cfg ):
paths( cfg.paths ), soundDirs( cfg.soundDirs ), hunspell( cfg.hunspell ),
transliteration( cfg.transliteration ),
exceptionText( "Load did not finish" ), // Will be cleared upon success
maxPictureWidth( cfg.maxPictureWidth )
maxPictureWidth( cfg.maxPictureWidth ),
maxHeadwordSize( cfg.maxHeadwordSize )
{
// Populate name filters

Expand Down Expand Up @@ -131,7 +132,8 @@ void LoadDictionaries::handlePath( Config::Path const & path )

{
vector< sptr< Dictionary::Class > > dslDictionaries =
Dsl::makeDictionaries( allFiles, FsEncoding::encode( Config::getIndexDir() ), *this, maxPictureWidth );
Dsl::makeDictionaries(
allFiles, FsEncoding::encode( Config::getIndexDir() ), *this, maxPictureWidth, maxHeadwordSize );

dictionaries.insert( dictionaries.end(), dslDictionaries.begin(),
dslDictionaries.end() );
Expand Down
1 change: 1 addition & 0 deletions loaddictionaries.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LoadDictionaries: public QThread, public Dictionary::Initializing
std::vector< sptr< Dictionary::Class > > dictionaries;
std::string exceptionText;
int maxPictureWidth;
unsigned int maxHeadwordSize;

public:

Expand Down

0 comments on commit 7496f5f

Please sign in to comment.