开发者

Including Large Wordlist in Stand-alone Dictionary Application

开发者 https://www.devze.com 2022-12-08 03:43 出处:网络
The Application I\'m working on a simple dictionary search tool, with the main purpose of searching a word-list of around 180,000 words.

The Application

I'm working on a simple dictionary search tool, with the main purpose of searching a word-list of around 180,000 words.

To begin with, the word-list was a plain-text document, with each word on a single line. Upon loading, the word-list was processed into a simple array for searching.

The Objective

My objective, however, is to distribute the application as a single, portable executable file and thus I must package the word-list within the application somehow.

My Attempts

Upon my first attempt, I simply automatically generated an array definition, and included that within the project (so instead of loading the file and creating an array, I have a literal array within the project), which looks a little like this:

// Auto-generated word-list
public string[] WordList = new string[178691];

WordList[0] = "AA";
WordList[1] = "AAH";
// ...
WordList[115383] = "PHOTONEGATIVE";
WordList[115384] = "PHOTONIC";
WordList[115385] = "PHOTONICS";
WordList[115386] = "PHOTONS";
WordList[115387] = "PHOTONUCLEAR";
WordList[115388] = "PHOTOOXIDATION";
WordList[115389] = "PHOTOOXIDATIONS";
WordList[115390] = "PHOTOOXIDATIVE";
WordList[115391] = "PHOTOOXIDIZE";
WordList[115392] = "PHOTOOXIDIZED";
WordList[115393] = "PHOTOOXIDIZES";
WordList[115394] = "PHOTOOXIDIZING";
WordList[115395] = "PHOTOPERIOD";
// etc...

This achieves the goal of being completely portable, and the file-size of the overall project remains the same.

One thing that does change by approaching it in this manner, though, is an increase in the build and run time, which could be considered a minor and unavoidable problem but ideally should be shortened.

The Question

Is there any way of combini开发者_JAVA技巧ng a large (~180,000 word) dictionary into a portable/standalone application, maybe using some kind of compression technique to lower the file-size, but ultimately to keep to a reasonable load-time, which is "more favoured" than a simple, pre-defined, literal array?


You should look into adding the file as an embedded resource to your .NET assembly. Then you can read the values at run-time from within the assembly. You may also be able to use DeflateStream (see here) to compress it in the assembly somehow.

0

精彩评论

暂无评论...
验证码 换一张
取 消