cjnevin / Dawg

Directed acyclic word graph in Swift
MIT License
6 stars 2 forks source link

How to check that output.bin file. #2

Open ektapadaliya opened 7 years ago

ektapadaliya commented 7 years ago

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

cjnevin commented 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.

ektapadaliya commented 7 years ago

Hi Chris,

Thanks for your feedback.

Can you please tell me that how to open command line tool from xcode?

ektapadaliya commented 7 years ago

Can I use this library in single view application?

cjnevin commented 7 years ago
  1. File -> New Project -> macOS -> Command Line Tool
  2. Paste the line above.
  3. Put your file in ~ and call it 'input.txt'
  4. Press ⌘R
  5. Wait until it completes.
cjnevin commented 7 years ago

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.

ektapadaliya commented 7 years ago

It gives me "assertion failed".

I have added "file.txt".

screen shot 2017-01-30 at 4 04 13 pm

assert(DawgBuilder.build(readingFrom: "~/file.txt", writingTo: "~/output.bin"))

cjnevin commented 7 years ago

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.

ektapadaliya commented 7 years ago

Means I need to create one directory named "~".

cjnevin commented 7 years ago

On a mac/unix system ~ refers to the home directory.

ektapadaliya commented 7 years ago

Okay Now I got. Sorry. :(

cjnevin commented 7 years ago

Can I close this issue?

ektapadaliya commented 7 years ago

No. Please help me. I have added that file in root dir but still error.

cjnevin commented 7 years ago

You pasted it in ~ and called it input.txt Then you loaded the file in the app by calling ~/input.txt?

ektapadaliya commented 7 years ago

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"))

ektapadaliya commented 7 years ago

screen shot 2017-01-30 at 4 22 49 pm

Check this.

cjnevin commented 7 years ago

What format is your input.txt file?

It should contain each word on a new line

ektapadaliya commented 7 years ago

screen shot 2017-01-30 at 4 26 07 pm

cjnevin commented 7 years ago

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