PJTernarySearchTreeをCocoa Framework化したsearchTreeKitを呼び出して、高速にテキスト検索を行う(はずの)AppleScriptです。
–> SearchTreeKit.framework (To ~/Library/Frameworks/)
普通に1DのNSArrayにテキストを入れて絞り込みを行うよりもスピード面でメリットがあるのかは実測していないのでなんともいえません。PJTernarySearchTreeは検索フィールドの入力履歴からの候補語の検索などに利用するために作られた部品のようです。
AppleScript名:SearchTreeKitのじっけん1(ファイル書き込み) |
— Created 2018-05-08 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "SearchTreeKit" –https://github.com/peakji/PJTernarySearchTree set savePath to POSIX path of (path to desktop) & (do shell script "uuidgen") & "_test.tree" set aTree to current application’s PJTernarySearchTree’s alloc()’s init() aTree’s insertString:"http://www.peakji.com" aTree’s insertString:"http://www.peak-labs.com" aTree’s insertString:"http://www.facebook.com" aTree’s insertString:"http://www.face.com" aTree’s insertString:"http://blog.foo.com" aTree’s insertString:"http://blog.foo.com/bar" aTree’s insertString:"http://chinese.hello.com/ぴよー" aTree’s insertString:"http://chinese.hello.com/ぴよぴよー" aTree’s saveTreeToFile:savePath |
AppleScript名:SearchTreeKitのじっけん2(ファイル読み込み) |
— Created 2018-05-08 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "SearchTreeKit" –https://github.com/peakji/PJTernarySearchTree set savePath to POSIX path of (choose file) set aTree to current application’s PJTernarySearchTree’s treeWithFile:savePath set aRetrieved to (aTree’s retrievePrefix:"http://" countLimit:0) as list –return aRetrieved –> {"http://blog.foo.com", "http://blog.foo.com/bar", "http://chinese.hello.com/ぴよぴよー", "http://chinese.hello.com/ぴよー", "http://www.face.com", "http://www.facebook.com", "http://www.peak-labs.com", "http://www.peakji.com"} set bRetrieved to (aTree’s retrievePrefix:"http://" countLimit:2) as list –return bRetrieved –>{"http://blog.foo.com", "http://blog.foo.com/bar"} set cRetrieved to (aTree’s retrievePrefix:"http://www." countLimit:0) as list –return cRetrieved –> {"http://www.face.com", "http://www.facebook.com", "http://www.peak-labs.com", "http://www.peakji.com"} –Remove a string or object aTree’s removeString:"http://www.face.com" set dRetrieved to (aTree’s retrievePrefix:"http://www.fa." countLimit:0) as list –> {} |
AppleScript名:SearchTreeKitのじっけん3(オブジェクトの追加と検索) |
— Created 2018-05-09 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "SearchTreeKit" –https://github.com/peakji/PJTernarySearchTree set tagSearchTree to current application’s PJTernarySearchTree’s alloc()’s init() tagSearchTree’s insertString:"abcd" (tagSearchTree’s retrievePrefix:"abc") as list –> {"abcd"} tagSearchTree’s insertString:"def" tagSearchTree’s insertString:"ghi" tagSearchTree’s removeString:"abcd" set aList to (tagSearchTree’s retrievePrefix:"") as list –> {"def", "ghi"} |
More from my site
(Visited 39 times, 1 visits today)