Skip to content

Instantly share code, notes, and snippets.

@darcwader
Created October 29, 2017 13:53
Show Gist options
  • Select an option

  • Save darcwader/1005b167e1b0c0f9596d176ea90d6d9b to your computer and use it in GitHub Desktop.

Select an option

Save darcwader/1005b167e1b0c0f9596d176ea90d6d9b to your computer and use it in GitHub Desktop.
init() {
let wordsPath = Bundle.main.url(forResource:"words_array", withExtension:"json")
do {
let wordsData = try Data(contentsOf: wordsPath!)
if let wordsDict = try JSONSerialization.jsonObject(with: wordsData, options: []) as? [String:Int] {
self.vocabulary = wordsDict
}
} catch {
fatalError("oops could not load words_array")
}
let idfPath = Bundle.main.url(forResource: "words_idf", withExtension: "json")
do {
let idfData = try Data(contentsOf: idfPath!)
if let idfJson = try JSONSerialization.jsonObject(with: idfData, options: []) as? [String:[Double]] {
self.idf = idfJson["idf"]!
}
} catch {
fatalError("oops could not load words_idf file")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment