[Experimental] InputGraphの構造を変更し、LookupGraphによる辞書引きを実装 (#46)

* implement byfix lookup

* find failing test

* implement backward search

* add more test cases

* add new file

* split files

* Improve InputGraph Architecture

* implement dictionary search
This commit is contained in:
Miwa / Ensan
2024-02-23 17:51:27 +09:00
committed by GitHub
parent 784a80c46a
commit 52fc9ae4c2
8 changed files with 731 additions and 537 deletions

View File

@@ -125,4 +125,27 @@ extension LOUDS {
}
return result
}
/// index
static func getDataForLoudstxt3(_ identifier: String, indices: [Int], option: ConvertRequestOptions) -> [Int: [DicdataElement]] {
let binary: Data
do {
let url = getLoudstxt3URL(identifier, option: option)
binary = try Data(contentsOf: url)
} catch {
debug("getDataForLoudstxt3: \(error)")
return [:]
}
let lc = binary[0..<2].toArray(of: UInt16.self)[0]
let header_endIndex: UInt32 = 2 + UInt32(lc) * UInt32(MemoryLayout<UInt32>.size)
let ui32array = binary[2..<header_endIndex].toArray(of: UInt32.self)
var result: [Int: [DicdataElement]] = [:]
for index in indices {
let startIndex = Int(ui32array[index])
let endIndex = index == (lc - 1) ? binary.endIndex : Int(ui32array[index + 1])
result[index] = parseBinary(binary: binary[startIndex ..< endIndex])
}
return result
}
}