2011-11-11 8 views
0

私はsowpods辞書をAS3の配列に埋め込み、indexOf()を使って検索して単語の存在を確認します。AS3:配列上にindexOf()を持つ大きなテキストファイル

小さいテキストファイルを読み込むと、動作するように見えますが、それほど大きくはありません。コンパイル時にファイルが埋め込まれているので、読み込みのためのイベントが正しく聞こえるはずはありませんか?

コード:私の経験で

package { 
    import flash.display.MovieClip; 

    public class DictionaryCheck extends MovieClip { 

     [Embed(source="test.txt",mimeType="application/octet-stream")] // Works fine 10 rows. 
       //[Embed(source="sowpods.txt",mimeType="application/octet-stream")] //Won't work too large. 
     private static const DictionaryFile:Class; 

     private static var words:Array = new DictionaryFile().toString().split("\n"); 

     public function DictionaryCheck() { 
      containsWord("AARDVARKS"); 
     } 

     public static function containsWord(word:String):* { 
      trace(words[10]); //Traces "AARDVARKS" in both versions of file 
      trace((words[10]) == word); // Traces true in shorter text file false in longer 
      trace("Returning: " + (words.indexOf(word))); // traces Returning: 10 in smaller file 
      if((words.indexOf(word)) > -1){ 
       trace("Yes!"); // traces "Yes" in shorter file not in longer 
      } 
     } 
    } 
} 

答えて

0

(私は私をバックアップするには直接ドキュメントを持っていない)、フラッシュは非常に大きなテキストファイルを開くことができません。前に辞書をインポートしているときと同じ問題がありました。

私がやったことは、辞書をActionScriptクラスに変換することでした。ファイルをロードしてより良い検索のために辞書に解析する必要がなくなり、辞書はすでに解析されて格納されていました配列。配列メンバはすでにソートされているので、単純な半区間検索関数(http://en.wikipedia.org/wiki/Binary_search_algorithm)を使用して、辞書に単語が含まれているかどうかを判断しました。

基本的には、あなたの辞書は次のようになります。

public class DictSOWPODS { 
    protected var parsedDictionary : Array = ["firstword", "secondword", ..., "lastword"]; // yes, this will be the hugest array initialization you've ever seen, just make sure it's sorted so you can search it fast 

    public function containsWord(word : String) : Boolean { 
     var result : Boolean = false; 
     // perform the actual half-interval search here (please do not keep it this way) 
     var indexFound : int = parsedDictionary.indexOf(word); 
     result = (indexFound >= 0) 
     // end of perform the actual half-interval search (please do not keep it this way) 
     return result; 
    } 
} 

をあなたの代わりにテキストファイルのASクラスを使用することによって失う唯一のことは、あなたがにSWCを使用しない限り、あなたは(実行時にそれを変更することはできませんということですクラスを保持する)が、すでに.swfにテキストファイルを埋め込んでいるので、これははるかに良い解決策であるはずです(ファイルを読み込んで解析する必要はありません)。 辞書が本当に本当に大きければ、フラッシュコンパイラは最終的には恥ずかしくて爆発することに注意することも重要です。

EDIT:

私はここでそれを得る、私はここにhttp://www.isc.ro/en/commands/lists.html労働者階級にで見つかったSOWPODSを変えてきました: http://www.4shared.com/file/yQl659Bq/DictSOWPODS.html

関連する問題