Rename variables for consistency
This commit is contained in:
parent
d8a3b420ee
commit
6726c5245b
@ -87,10 +87,10 @@ func (meta *jmdictMetadata) MakeReferenceToSeqMap() {
|
|||||||
func (meta *jmdictMetadata) MakeHashToSearchValuesMap() {
|
func (meta *jmdictMetadata) MakeHashToSearchValuesMap() {
|
||||||
meta.hashToSearchValues = make(map[hash][]searchValue)
|
meta.hashToSearchValues = make(map[hash][]searchValue)
|
||||||
for seq, searchHashes := range meta.seqToSearchHashes {
|
for seq, searchHashes := range meta.seqToSearchHashes {
|
||||||
for score, searchHash := range searchHashes {
|
for idx, searchHash := range searchHashes {
|
||||||
searchValue := searchValue{
|
searchValue := searchValue{
|
||||||
sequence: seq,
|
sequence: seq,
|
||||||
index: score,
|
index: idx,
|
||||||
isPriority: searchHash.isPriority,
|
isPriority: searchHash.isPriority,
|
||||||
}
|
}
|
||||||
meta.hashToSearchValues[searchHash.hash] =
|
meta.hashToSearchValues[searchHash.hash] =
|
||||||
@ -100,6 +100,10 @@ func (meta *jmdictMetadata) MakeHashToSearchValuesMap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* This function attemps to convert a JMdict reference string into a
|
||||||
|
* single definite sequence number. These reference strings are often
|
||||||
|
* ambiguous, so we have to resort to using heuristics.
|
||||||
|
*
|
||||||
* Generally, correspondence is determined by the order in which term
|
* Generally, correspondence is determined by the order in which term
|
||||||
* pairs are extracted from each JMdict entry. Take for example the
|
* pairs are extracted from each JMdict entry. Take for example the
|
||||||
* JMdict entry for ご本, which contains a reference to 本 (without a
|
* JMdict entry for ご本, which contains a reference to 本 (without a
|
||||||
@ -115,7 +119,7 @@ func (meta *jmdictMetadata) MakeHashToSearchValuesMap() {
|
|||||||
* returned.
|
* returned.
|
||||||
*
|
*
|
||||||
* In situations in which multiple sequences are found with the same
|
* In situations in which multiple sequences are found with the same
|
||||||
* score, the entry with a priority tag ("news1", "ichi1", "spec1",
|
* index, the entry with a priority tag ("news1", "ichi1", "spec1",
|
||||||
* "spec2", "gai1") is given preference. This mostly affects
|
* "spec2", "gai1") is given preference. This mostly affects
|
||||||
* katakana-only loanwords like ラグ.
|
* katakana-only loanwords like ラグ.
|
||||||
*
|
*
|
||||||
@ -129,8 +133,8 @@ func (meta *jmdictMetadata) MakeHashToSearchValuesMap() {
|
|||||||
*
|
*
|
||||||
* All else being equal, the entry with the smallest sequence number
|
* All else being equal, the entry with the smallest sequence number
|
||||||
* is chosen. References in the JMdict file are currently ambiguous,
|
* is chosen. References in the JMdict file are currently ambiguous,
|
||||||
* and getting this perfect won't be possible until sequence numbers
|
* and getting this perfect won't be possible until reference sequence
|
||||||
* are explictly identified in these references. See:
|
* numbers are included in the file. See:
|
||||||
* https://github.com/JMdictProject/JMdictIssues/issues/61
|
* https://github.com/JMdictProject/JMdictIssues/issues/61
|
||||||
*/
|
*/
|
||||||
func (meta *jmdictMetadata) FindBestSequence(reference string) sequence {
|
func (meta *jmdictMetadata) FindBestSequence(reference string) sequence {
|
||||||
@ -142,24 +146,24 @@ func (meta *jmdictMetadata) FindBestSequence(reference string) sequence {
|
|||||||
return bestSeq
|
return bestSeq
|
||||||
}
|
}
|
||||||
hash := headword.Hash()
|
hash := headword.Hash()
|
||||||
for _, seqScore := range meta.hashToSearchValues[hash] {
|
for _, v := range meta.hashToSearchValues[hash] {
|
||||||
if meta.seqToSenseCount[seqScore.sequence] < senseNumber {
|
if meta.seqToSenseCount[v.sequence] < senseNumber {
|
||||||
// entry must contain the specified sense
|
// entry must contain the specified sense
|
||||||
continue
|
continue
|
||||||
} else if lowestIndex < seqScore.index {
|
} else if lowestIndex < v.index {
|
||||||
// lower indices are better
|
// lower indices are better
|
||||||
continue
|
continue
|
||||||
} else if (lowestIndex == seqScore.index) && (bestIsPriority && !seqScore.isPriority) {
|
} else if (lowestIndex == v.index) && (bestIsPriority && !v.isPriority) {
|
||||||
// if scores match, check priority
|
// if indices match, check priority
|
||||||
continue
|
continue
|
||||||
} else if (lowestIndex == seqScore.index) && (bestIsPriority == seqScore.isPriority) && (bestSeq < seqScore.sequence) {
|
} else if (lowestIndex == v.index) && (bestIsPriority == v.isPriority) && (bestSeq < v.sequence) {
|
||||||
// if scores and priority match, check sequence number.
|
// if indices and priority match, check sequence number.
|
||||||
// lower sequence numbers are better
|
// lower sequence numbers are better
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
lowestIndex = seqScore.index
|
lowestIndex = v.index
|
||||||
bestSeq = seqScore.sequence
|
bestSeq = v.sequence
|
||||||
bestIsPriority = seqScore.isPriority
|
bestIsPriority = v.isPriority
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bestSeq
|
return bestSeq
|
||||||
|
Loading…
Reference in New Issue
Block a user