LMAssembly // Format tweaks.
This commit is contained in:
parent
04bdb0db47
commit
fd3c48bf02
|
@ -16,17 +16,13 @@ extension vChewingLM {
|
||||||
var rangeMap: [String: [(Range<String.Index>, Int)]] = [:]
|
var rangeMap: [String: [(Range<String.Index>, Int)]] = [:]
|
||||||
var strData: String = ""
|
var strData: String = ""
|
||||||
|
|
||||||
public var count: Int {
|
public var count: Int { rangeMap.count }
|
||||||
rangeMap.count
|
|
||||||
}
|
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
rangeMap = [:]
|
rangeMap = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
public var isLoaded: Bool {
|
public var isLoaded: Bool { !rangeMap.isEmpty }
|
||||||
!rangeMap.isEmpty
|
|
||||||
}
|
|
||||||
|
|
||||||
internal func cnvNGramKeyFromPinyinToPhona(target: String) -> String {
|
internal func cnvNGramKeyFromPinyinToPhona(target: String) -> String {
|
||||||
guard target.contains("("), target.contains(","), target.contains(")") else {
|
guard target.contains("("), target.contains(","), target.contains(")") else {
|
||||||
|
@ -40,9 +36,7 @@ extension vChewingLM {
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult public mutating func open(_ path: String) -> Bool {
|
@discardableResult public mutating func open(_ path: String) -> Bool {
|
||||||
if isLoaded {
|
if isLoaded { return false }
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
LMConsolidator.fixEOF(path: path)
|
LMConsolidator.fixEOF(path: path)
|
||||||
LMConsolidator.consolidate(path: path, pragma: true)
|
LMConsolidator.consolidate(path: path, pragma: true)
|
||||||
|
@ -72,10 +66,8 @@ extension vChewingLM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func close() {
|
public mutating func close() {
|
||||||
if isLoaded {
|
|
||||||
rangeMap.removeAll()
|
rangeMap.removeAll()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public func valuesFor(pair: Megrez.Compositor.KeyValuePaired) -> [String] {
|
public func valuesFor(pair: Megrez.Compositor.KeyValuePaired) -> [String] {
|
||||||
var pairs: [String] = []
|
var pairs: [String] = []
|
||||||
|
|
|
@ -30,9 +30,7 @@ extension vChewingLM {
|
||||||
var shouldForceDefaultScore = false
|
var shouldForceDefaultScore = false
|
||||||
|
|
||||||
/// 資料陣列內承載的資料筆數。
|
/// 資料陣列內承載的資料筆數。
|
||||||
public var count: Int {
|
public var count: Int { rangeMap.count }
|
||||||
rangeMap.count
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 初期化該語言模型。
|
/// 初期化該語言模型。
|
||||||
///
|
///
|
||||||
|
@ -53,17 +51,13 @@ extension vChewingLM {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 檢測資料庫辭典內是否已經有載入的資料。
|
/// 檢測資料庫辭典內是否已經有載入的資料。
|
||||||
public var isLoaded: Bool {
|
public var isLoaded: Bool { !rangeMap.isEmpty }
|
||||||
!rangeMap.isEmpty
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 將資料從檔案讀入至資料庫辭典內。
|
/// 將資料從檔案讀入至資料庫辭典內。
|
||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - path: 給定路徑。
|
/// - path: 給定路徑。
|
||||||
@discardableResult public mutating func open(_ path: String) -> Bool {
|
@discardableResult public mutating func open(_ path: String) -> Bool {
|
||||||
if isLoaded {
|
if isLoaded { return false }
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if allowConsolidation {
|
if allowConsolidation {
|
||||||
LMConsolidator.fixEOF(path: path)
|
LMConsolidator.fixEOF(path: path)
|
||||||
|
@ -95,10 +89,8 @@ extension vChewingLM {
|
||||||
|
|
||||||
/// 將當前語言模組的資料庫辭典自記憶體內卸除。
|
/// 將當前語言模組的資料庫辭典自記憶體內卸除。
|
||||||
public mutating func close() {
|
public mutating func close() {
|
||||||
if isLoaded {
|
|
||||||
rangeMap.removeAll()
|
rangeMap.removeAll()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Advanced features
|
// MARK: - Advanced features
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,7 @@ extension vChewingLM {
|
||||||
var shouldForceDefaultScore = false
|
var shouldForceDefaultScore = false
|
||||||
|
|
||||||
/// 資料陣列內承載的資料筆數。
|
/// 資料陣列內承載的資料筆數。
|
||||||
public var count: Int {
|
public var count: Int { rangeMap.count }
|
||||||
rangeMap.count
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 初期化該語言模型。
|
/// 初期化該語言模型。
|
||||||
///
|
///
|
||||||
|
@ -54,17 +52,13 @@ extension vChewingLM {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 檢測資料庫辭典內是否已經有載入的資料。
|
/// 檢測資料庫辭典內是否已經有載入的資料。
|
||||||
public var isLoaded: Bool {
|
public var isLoaded: Bool { !rangeMap.isEmpty }
|
||||||
!rangeMap.isEmpty
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 將資料從檔案讀入至資料庫辭典內。
|
/// 將資料從檔案讀入至資料庫辭典內。
|
||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - path: 給定路徑。
|
/// - path: 給定路徑。
|
||||||
@discardableResult public mutating func open(_ path: String) -> Bool {
|
@discardableResult public mutating func open(_ path: String) -> Bool {
|
||||||
if isLoaded {
|
if isLoaded { return false }
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let rawData = try Data(contentsOf: URL(fileURLWithPath: path))
|
let rawData = try Data(contentsOf: URL(fileURLWithPath: path))
|
||||||
|
@ -81,10 +75,8 @@ extension vChewingLM {
|
||||||
|
|
||||||
/// 將當前語言模組的資料庫辭典自記憶體內卸除。
|
/// 將當前語言模組的資料庫辭典自記憶體內卸除。
|
||||||
public mutating func close() {
|
public mutating func close() {
|
||||||
if isLoaded {
|
|
||||||
rangeMap.removeAll()
|
rangeMap.removeAll()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Advanced features
|
// MARK: - Advanced features
|
||||||
|
|
||||||
|
|
|
@ -14,22 +14,16 @@ extension vChewingLM {
|
||||||
@frozen public struct LMPlainBopomofo {
|
@frozen public struct LMPlainBopomofo {
|
||||||
var rangeMap: [String: String] = [:]
|
var rangeMap: [String: String] = [:]
|
||||||
|
|
||||||
public var count: Int {
|
public var count: Int { rangeMap.count }
|
||||||
rangeMap.count
|
|
||||||
}
|
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
rangeMap = [:]
|
rangeMap = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
public var isLoaded: Bool {
|
public var isLoaded: Bool { !rangeMap.isEmpty }
|
||||||
!rangeMap.isEmpty
|
|
||||||
}
|
|
||||||
|
|
||||||
@discardableResult public mutating func open(_ path: String) -> Bool {
|
@discardableResult public mutating func open(_ path: String) -> Bool {
|
||||||
if isLoaded {
|
if isLoaded { return false }
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let rawData = try Data(contentsOf: URL(fileURLWithPath: path))
|
let rawData = try Data(contentsOf: URL(fileURLWithPath: path))
|
||||||
|
@ -46,10 +40,8 @@ extension vChewingLM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func close() {
|
public mutating func close() {
|
||||||
if isLoaded {
|
|
||||||
rangeMap.removeAll()
|
rangeMap.removeAll()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public func valuesFor(key: String) -> [String] {
|
public func valuesFor(key: String) -> [String] {
|
||||||
var pairs: [String] = []
|
var pairs: [String] = []
|
||||||
|
|
|
@ -14,22 +14,16 @@ extension vChewingLM {
|
||||||
var rangeMap: [String: Range<String.Index>] = [:]
|
var rangeMap: [String: Range<String.Index>] = [:]
|
||||||
var strData: String = ""
|
var strData: String = ""
|
||||||
|
|
||||||
public var count: Int {
|
public var count: Int { rangeMap.count }
|
||||||
rangeMap.count
|
|
||||||
}
|
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
rangeMap = [:]
|
rangeMap = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
public var isLoaded: Bool {
|
public var isLoaded: Bool { !rangeMap.isEmpty }
|
||||||
!rangeMap.isEmpty
|
|
||||||
}
|
|
||||||
|
|
||||||
@discardableResult public mutating func open(_ path: String) -> Bool {
|
@discardableResult public mutating func open(_ path: String) -> Bool {
|
||||||
if isLoaded {
|
if isLoaded { return false }
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
LMConsolidator.fixEOF(path: path)
|
LMConsolidator.fixEOF(path: path)
|
||||||
LMConsolidator.consolidate(path: path, pragma: true)
|
LMConsolidator.consolidate(path: path, pragma: true)
|
||||||
|
@ -57,10 +51,8 @@ extension vChewingLM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func close() {
|
public mutating func close() {
|
||||||
if isLoaded {
|
|
||||||
rangeMap.removeAll()
|
rangeMap.removeAll()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public func dump() {
|
public func dump() {
|
||||||
var strDump = ""
|
var strDump = ""
|
||||||
|
|
Loading…
Reference in New Issue