Skip to content

Commit

Permalink
Typo fix: preceeding -> preceding. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen authored Apr 25, 2022
1 parent 4909033 commit 80ddbc0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions Sources/Megrez/4_Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension Megrez {
var mutUnigrams: [Unigram]
var mutCandidates: [KeyValuePair]
var mutValueUnigramIndexMap: OrderedDictionary<String, Int>
var mutPreceedingGramBigramMap: OrderedDictionary<KeyValuePair, [Megrez.Bigram]>
var mutPrecedingBigramMap: OrderedDictionary<KeyValuePair, [Megrez.Bigram]>

var mutCandidateFixed: Bool = false
var mutSelectedUnigramIndex: Int = 0
Expand All @@ -46,7 +46,7 @@ extension Megrez {
mutUnigrams = unigrams
mutCandidates = []
mutValueUnigramIndexMap = [:]
mutPreceedingGramBigramMap = [:]
mutPrecedingBigramMap = [:]

mutCandidateFixed = false
mutSelectedUnigramIndex = 0
Expand Down Expand Up @@ -77,19 +77,19 @@ extension Megrez {
}

for gram in bigrams {
mutPreceedingGramBigramMap[gram.preceedingKeyValue]?.append(contentsOf: [gram])
mutPrecedingBigramMap[gram.precedingKeyValue]?.append(contentsOf: [gram])
}
}

public func primeNodeWith(preceedingKeyValues: [KeyValuePair]) {
// TODO: primeNodeWithPreceedingKeyValues
public func primeNodeWith(precedingKeyValues: [KeyValuePair]) {
// TODO: primeNodeWithPrecedingKeyValues
// Please check the same function in C++ version of Gramambumlar for references.
var newIndex = mutSelectedUnigramIndex
var max = mutScore

if !isCandidateFixed() {
for (index, _) in preceedingKeyValues.enumerated() {
let bigrams = mutPreceedingGramBigramMap.elements[index].1
for (index, _) in precedingKeyValues.enumerated() {
let bigrams = mutPrecedingBigramMap.elements[index].1
for (_, bigram) in bigrams.enumerated() {
if bigram.score > max {
if let valRetrieved = mutValueUnigramIndexMap[bigram.keyValue.value] {
Expand Down Expand Up @@ -174,7 +174,7 @@ extension Megrez {
public static func == (lhs: Node, rhs: Node) -> Bool {
lhs.mutUnigrams == rhs.mutUnigrams && lhs.mutCandidates == rhs.mutCandidates
&& lhs.mutValueUnigramIndexMap == rhs.mutValueUnigramIndexMap
&& lhs.mutPreceedingGramBigramMap == rhs.mutPreceedingGramBigramMap
&& lhs.mutPrecedingBigramMap == rhs.mutPrecedingBigramMap
&& lhs.mutCandidateFixed == rhs.mutCandidateFixed
&& lhs.mutSelectedUnigramIndex == rhs.mutSelectedUnigramIndex
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Megrez/5_LanguageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extension Megrez {
key.isEmpty ? [Megrez.Unigram]() : [Megrez.Unigram]()
}

open func bigramsForKeys(preceedingKey: String, key: String) -> [Megrez.Bigram] {
preceedingKey == key ? [Megrez.Bigram]() : [Megrez.Bigram]()
open func bigramsForKeys(precedingKey: String, key: String) -> [Megrez.Bigram] {
precedingKey == key ? [Megrez.Bigram]() : [Megrez.Bigram]()
}

open func hasUnigramsFor(key: String) -> Bool {
Expand Down
14 changes: 7 additions & 7 deletions Sources/Megrez/6_Bigram.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
extension Megrez {
public class Bigram: Equatable {
public var keyValue: KeyValuePair
public var preceedingKeyValue: KeyValuePair
public var precedingKeyValue: KeyValuePair
public var score: Double
// var paired: String

public init(preceedingKeyValue: KeyValuePair, keyValue: KeyValuePair, score: Double) {
public init(precedingKeyValue: KeyValuePair, keyValue: KeyValuePair, score: Double) {
self.keyValue = keyValue
self.preceedingKeyValue = preceedingKeyValue
self.precedingKeyValue = precedingKeyValue
self.score = score
// paired = "(" + keyValue.paired + "|" + preceedingKeyValue.paired + "," + String(score) + ")"
// paired = "(" + keyValue.paired + "|" + precedingKeyValue.paired + "," + String(score) + ")"
}

public func hash(into hasher: inout Hasher) {
hasher.combine(keyValue)
hasher.combine(preceedingKeyValue)
hasher.combine(precedingKeyValue)
hasher.combine(score)
// hasher.combine(paired)
}
Expand All @@ -54,11 +54,11 @@ extension Megrez {
// }

public static func == (lhs: Bigram, rhs: Bigram) -> Bool {
lhs.preceedingKeyValue == rhs.preceedingKeyValue && lhs.keyValue == rhs.keyValue && lhs.score == rhs.score
lhs.precedingKeyValue == rhs.precedingKeyValue && lhs.keyValue == rhs.keyValue && lhs.score == rhs.score
}

public static func < (lhs: Bigram, rhs: Bigram) -> Bool {
lhs.preceedingKeyValue < rhs.preceedingKeyValue
lhs.precedingKeyValue < rhs.precedingKeyValue
|| (lhs.keyValue < rhs.keyValue || (lhs.keyValue == rhs.keyValue && lhs.keyValue < rhs.keyValue))
}

Expand Down

0 comments on commit 80ddbc0

Please sign in to comment.