Open ektapadaliya opened 7 years ago
You have to create the bin file prior to using it in an app.
You can create a bin file using this line of code in a New macOS -> Command Line Tool project.
// Create a dawg binary file from a word list file.
assert(DawgBuilder.build(readingFrom: "~/input.txt", writingTo: "~/output.bin"))
Once that completes you should have a bin file in your home directory.
You can then load the bin file using:
let dawg = Dawg.load(from: "~/output.bin")
assert(dawg != nil)
This should only be done once ideally, as it's not a quick process, so you should create a singleton or inject it where you need to use the object.
In order to see if words exist you use the 'lookup' method.
// Returns false if the word is undefined
assert(dawg.lookup("plane"))
Please let me know if you need more information.
Hi Chris,
Thanks for your feedback.
Can you please tell me that how to open command line tool from xcode?
Can I use this library in single view application?
Once you've compiled the .bin file you can use it wherever you like. It should just be compiled separately to a production app as it takes quite a while to process.
It gives me "assertion failed".
I have added "file.txt".
assert(DawgBuilder.build(readingFrom: "~/file.txt", writingTo: "~/output.bin"))
That is the incorrect path if you're going to bundle the file you'd need to find it using NSBundle.
Just paste the input file in ~ directory and use the example provided it's easier.
Means I need to create one directory named "~".
On a mac/unix system ~
refers to the home directory.
Okay Now I got. Sorry. :(
Can I close this issue?
No. Please help me. I have added that file in root dir but still error.
You pasted it in ~ and called it input.txt Then you loaded the file in the app by calling ~/input.txt?
Yes. in main.swift file
import Foundation
print("Hello, World!")
// Create a dawg binary file from a word list file. assert(DawgBuilder.build(readingFrom: "~/input.txt", writingTo: "~/output.bin"))
Check this.
What format is your input.txt file?
It should contain each word on a new line
If the build command fails it's because the file is not readable.
Can you paste this above the 'build' method:
do {
let data = try String(contentsOfFile: "~/input.txt", encoding: String.Encoding.utf8)
} catch err {
print(err)
}
Then paste what you get?
Cheers
Hi,
I used this library in my app. I have one txt file in my app folder. How to use this library in app?
I am unable to find output.bin file in app?
Please help me.
Thanks, Ekta