LMI // Rewrite documentation in Chinese.

This commit is contained in:
ShikiSuen 2022-06-18 14:45:12 +08:00
parent 6d4adea6ed
commit 2a97a6a80a
1 changed files with 25 additions and 27 deletions

View File

@ -24,9 +24,6 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
// NOTE: We still keep some of the comments left by Zonble,
// regardless that he is not in charge of this Swift module
import Foundation import Foundation
// //
@ -39,27 +36,23 @@ private var lmSymbols = vChewing.LMCoreNS(
) )
extension vChewing { extension vChewing {
/// LMInstantiator is a facade for managing a set of models including /// LMInstantiatorLMI
/// the input method language model, user phrases and excluded phrases. /// LanguageModel 使
///
/// ///
/// It is the primary model class that the input controller and input compositor /// LMI 調
/// of vChewing talks to. When the input compositor starts to build a sentence /// LMI
/// from a series of BPMF readings, it passes the readings to the model to see ///
/// if there are valid unigrams, and use returned unigrams to produce the final
/// results.
/// ///
/// LMInstantiator combine and transform the unigrams from the primary language /// LMI
/// model and user phrases. The process is
/// ///
/// 1) Get the original unigrams. /// 1.
/// 2) Drop the unigrams whose value is contained in the exclusion map. /// 2.
/// 3) Replace the values of the unigrams using the phrase replacement map. /// 3.
/// 4) Drop the duplicated phrases from the generated unigram array. /// 4.
/// ///
/// The controller can ask the model to load the primary input method language /// LMI LMI
/// model while launching and to load the user phrases anytime if the custom ///
/// files are modified. It does not keep the reference of the data pathes but
/// you have to pass the paths when you ask it to load.
public class LMInstantiator: Megrez.LanguageModel { public class LMInstantiator: Megrez.LanguageModel {
// //
public var isPhraseReplacementEnabled = false public var isPhraseReplacementEnabled = false
@ -76,9 +69,9 @@ extension vChewing {
/// LMCoreEX 2010-2013 mac /// LMCoreEX 2010-2013 mac
/// LMCoreNS plist /// LMCoreNS plist
// //
/// Reverse // Reverse
/// Reverse // Reverse
var lmCore = LMCoreNS( var lmCore = LMCoreNS(
reverse: false, consolidate: false, defaultScore: -9.9, forceDefaultScore: false reverse: false, consolidate: false, defaultScore: -9.9, forceDefaultScore: false
) )
@ -194,12 +187,12 @@ extension vChewing {
// MARK: - Core Functions (Public) // MARK: - Core Functions (Public)
/// Not implemented since we do not have data to provide bigram function. ///
// public func bigramsForKeys(preceedingKey: String, key: String) -> [Megrez.Bigram] { } // public func bigramsForKeys(preceedingKey: String, key: String) -> [Megrez.Bigram] { }
/// Returns a list of available unigram for the given key. /// LMI
/// @param key:String represents the BPMF reading or a symbol key. /// - Parameter key:
/// For instance, it you pass "ˇ", it returns "" and other possible candidates. /// - Returns:
override open func unigramsFor(key: String) -> [Megrez.Unigram] { override open func unigramsFor(key: String) -> [Megrez.Unigram] {
if key == " " { if key == " " {
/// ///
@ -267,6 +260,11 @@ extension vChewing {
// MARK: - Core Functions (Private) // MARK: - Core Functions (Private)
///
/// - Parameters:
/// - unigrams:
/// - filteredPairs:
/// - Returns:
func filterAndTransform( func filterAndTransform(
unigrams: [Megrez.Unigram], unigrams: [Megrez.Unigram],
filter filteredPairs: Set<Megrez.KeyValuePair> filter filteredPairs: Set<Megrez.KeyValuePair>