From 28889dc717cff61933e1411cfbd68c9c1a9b8d28 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 2 May 2022 10:46:07 +0800 Subject: [PATCH] SubLMs // Simplify (has)values/unigramsFor(). --- Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift | 5 +---- Source/Modules/LangModelRelated/SubLMs/lmCore.swift | 5 +---- Source/Modules/LangModelRelated/SubLMs/lmLite.swift | 5 +---- Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift | 6 +----- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift b/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift index 2e894159..db15a73a 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmAssociates.swift @@ -115,10 +115,7 @@ extension vChewing { } public func hasValuesFor(key: String) -> Bool { - if let arrEntry = keyValueMap[key] { - return !arrEntry.isEmpty - } - return false + keyValueMap[key] != nil } } } diff --git a/Source/Modules/LangModelRelated/SubLMs/lmCore.swift b/Source/Modules/LangModelRelated/SubLMs/lmCore.swift index 0ee1cf8a..cd3c060c 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmCore.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmCore.swift @@ -159,10 +159,7 @@ extension vChewing { } open func hasUnigramsFor(key: String) -> Bool { - if let arrEntry = keyValueScoreMap[key] { - return !arrEntry.isEmpty - } - return false + keyValueScoreMap[key] != nil } } } diff --git a/Source/Modules/LangModelRelated/SubLMs/lmLite.swift b/Source/Modules/LangModelRelated/SubLMs/lmLite.swift index e06e02eb..5a9faead 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmLite.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmLite.swift @@ -136,10 +136,7 @@ extension vChewing { } public func hasUnigramsFor(key: String) -> Bool { - if let arrEntry = keyValueMap[key] { - return !arrEntry.isEmpty - } - return false + keyValueMap[key] != nil } } } diff --git a/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift b/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift index d18c21eb..b189f8d5 100644 --- a/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift +++ b/Source/Modules/LangModelRelated/SubLMs/lmReplacements.swift @@ -105,11 +105,7 @@ extension vChewing { } public func valuesFor(key: String) -> String { - var v = "" - if let matched = keyValueMap[key] { - v = matched - } - return v + keyValueMap[key] ?? "" } } }