Skip to content

bw-pt/ChineseCharacterSimilarity

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chinese Character Similarity

A tool for calculating the similarity of two chars.

Key Idea

Tone Similarity:

  • PinYin edit distance

Shape Similarity:

  • Stroke counts difference
  • Sijiao Encoding edit distance
  • Character images differences ratio

CharSimilarity.similarity(ch1, ch2) Usage

Parameters:

  • tone:  - Flag for tone similarity computing. (default: True)
    • Type: Bool
  • shape:
    • Flag for shape similarity computing. (default: True)
    • Type: Bool
  • wpy:
    • Weight of PinYin similarity. (default: 0.4)
    • Type: Float
    • Range: 0.0 - 1.0
  • wst:
    • Weight of stroke count similarity. (default: 0.1)
    • Type: Float
    • Range: 0.0 - 1.0
  • wsj:
    • Weight of Sijiao encoding similarity. (default: 0.3)
    • Type: Float
    • Range: 0.0 - 1.0
  • wmatrix:
    • Weight of character image matrix similarity. (default: 0.2)
    • Type: Float
    • Range: 0.0 - 1.0
In [1]: import CharSimilarity

In [2]: ch1 = '侯'

In [3]: ch2 = '候'

In [4]: tone_similarity = CharSimilarity.similarity(ch1,ch2,tone=True,shape=False)

In [5]: print(tone_similarity)
1.0

In [6]: shape_similarity = CharSimilarity.similarity(ch1,ch2,tone=False,shape=True,wpy=0.0,wst=0.33,wsj=0.33,wmatrix=0.34)

In [7]: print(shape_similarity)
0.8253333333333334

In [8]: tone_shape_similarity = CharSimilarity.similarity(ch1,ch2,tone=True,shape=True,wpy=0.4,wst=0.1,wsj=0.3,wmatrix=0.2)

In [9]: print(tone_shape_similarity)
0.9066666666666667

References

About

A tool for calculating the similarity of two chars.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%