Giter Club home page Giter Club logo

dimsim's Introduction

DimSim - A Chinese Soundex Library (Python version)

DimSim is a library developed by the Scalable Knowledge Intelligence team at IBM Almaden Research Center as part of the SystemT project.

The PyPi project page can be found here. It was created in collaboration with IBM Center for Open-Source Data and AI Technologies (CODAIT).

Overview

We provide a phonetic algorithm for indexing Chinese characters by sound. The technical details can be found in the following paper:

Min Li, Marina Danilevsky, Sara Noeman and Yunyao Li. DIMSIM: An Accurate Chinese Phonetic Similarity Algorithm based on Learned High Dimensional Encoding. CoNLL 2018.

In this library, we provide a pre-trained model that can perform the following functions, in compliance with the phonetic principles of Mandarin Chinese as guided by the Romanization defined in ISO 7098:2015:

  • Given two Chinese phrases (of the same length), return the phonetic distance of the input phrases. Optionally you can feed in pinyin strings of Chinese phrases too.
  • Given a Chinese phrase, return its top-k similar (phoentically) Chinese phrases.

How to install

Dependencies:

  • pypinyin: used for translating Chinese characters into their correponding pinyins.

There are two ways to install this library:

  • Install from PyPi
pip install dimsim
  • Download the source code by cloning this repo and compile it yourself.
git clone [email protected]:System-T/DimSim.git

cd DimSim/

pip install -e .

How to use

Once you have the package installed you can use it for the two functions as shown below.

  • Computing phonetic distance of two Chinese phrases. The optional argument pinyin (False by default) can be used to provide a pinyin string list directly. See example usage below.
import dimsim

dist = dimsim.get_distance("大侠","大虾")
0.0002380952380952381

dist = dimsim.get_distance("大侠","大人")
25.001417183349876

dist = dimsim.get_distance(['da4','xia2'],['da4','xia1']], pinyin=True)
0.0002380952380952381

dist = dimsim.get_distance(['da4','xia2'],['da4','ren2']], pinyin=True)
25.001417183349876

  • Return top-k phonetically similar phrases of a given Chinese phrase. Two parameters:
  • mode controls the character type of the returned Chinese phrases, where 'simplified' represents simplified Chinese and 'traditional' represents traditional Chinese.
  • theta controls the size of search space for the candidate phrases.
import dimsim

candidates = dimsim.get_candidates("大侠", mode="simplified", theta=1)

['打下', '大虾', '大侠']

candidates = dimsim.get_candidates("粉丝", mode="traditinoal", theta=1)
['門市', '分時', '焚屍', '粉飾', '粉絲']

Return Pinyin RCode

rcode = getRCode("海底小纵队")
"hai'di'xiao'zong'dui"

rcode = getRCode("海底小中队")
"hai'di'xiao'zong'dui"

Citation

Please cite the library by referencing the published paper:

@InProceedings{K18-1043,
  author = 	{Li, Min and Danilevsky, Marina and Noeman, Sara and Li, Yunyao},
  title = 	{{DIMSIM:} An Accurate Chinese Phonetic Similarity Algorithm Based on Learned High Dimensional Encoding},
  booktitle = 	{Proceedings of the 22nd Conference on Computational Natural Language Learning},
  year = 	{2018},
  publisher = 	{Association for Computational Linguistics},
  pages = 	{444-453},
  location = 	{Brussels, Belgium},
  url = 	{http://aclweb.org/anthology/K18-1043}
}

dimsim's People

Contributors

kmh4321 avatar kunqian-usa avatar marina-danilevsky avatar thelostpeace avatar xuhdev avatar yunyaoli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dimsim's Issues

对于声母为w y的情况 有非常严重的偏误

    if b.locp[0] == 'w' and b.vowel[0] == 'u' and len(b.vowel) > 1:
        b.consonant = 'w'
        b.vowel = b.vowel[1:]
    
    if a.locp[0] == 'w' and a.vowel[0] == 'u' and len(a.vowel) > 1:
        a.consonant = 'w'
        a.vowel = a.vowel[1:]
    
    if a.locp[0] == 'y' and a.vowel[0] == 'u' and len(a.vowel) > 1:
        a.consonant = 'y'
        a.vowel = a.vowel[1:]
        if a.vowel[-1] == ':':
            a.vowel = a.vowel[:-1]

    if b.locp[0] == 'y' and b.vowel[0] == 'u' and len(b.vowel) > 1:
        b.consonant = 'y'
        # b.vowel = b.vowel[1:]
        if b.vowel[-1] == ':':
            b.vowel = b.vowel[:-1]

自己写代码先修了一下,总之就是pypinyin这个库对这两个的识别和其他的是不一样的

Bad case caused by no-consonant char

In your trained consonantMap_TwoDCode, no-consontant mappings to (99999.0,99999.0), which causes some chars like "我", "一" are not similar with any char with consonant(e.g. "过", "鸡"). Does this make sense?

For some inputs, there is error message when calling dimsim.get_candidates

dimsim.get_candidates("大侠") works fine.
But when calling dimsim.get_candidates("龌龊"), it gives this error

Traceback (most recent call last):
  File "gen_sim_data.py", line 15, in <module>
    print(get_similar_phrase("龌龊"))
  File "gen_sim_data.py", line 8, in get_similar_phrase
    return dimsim.get_candidates(phrase, mode="simplified", theta=int(num_candid/2))[:-1]
  File "/usr/local/lib/python3.7/dist-packages/dimsim/core/model.py", line 80, in get_candidates
    candid = _get_close_pinyin_candids(word, theta)
  File "/usr/local/lib/python3.7/dist-packages/dimsim/core/model.py", line 109, in _get_close_pinyin_candids
    res.append(Pinyin(newPy))
  File "/usr/local/lib/python3.7/dist-packages/dimsim/utils/pinyin.py", line 15, in __init__
    self.pinyinRewrite()
  File "/usr/local/lib/python3.7/dist-packages/dimsim/utils/pinyin.py", line 41, in pinyinRewrite
    if 'v' in self.vowel:
TypeError: argument of type 'NoneType' is not iterable

any thoughts?

Thanks

TypeError: 'float' object is not iterable

if self.consonant is "w":

您好,想請教在這段 consonant 判斷式設計上的意義,

在實做上,以 wang2 為例,進入判段式後
將 vowel 取代為 u+self.vowel
並使 consonant w 為 ""

回到 getEditDistanceClose_TwoDCode 後,"" mapping 到 99999.0,

接著進入到 cDis = abs(getDistance_TwoDCode(twoDcode_consonant_a, twoDcode_consonant_b)) ,在此段中,因傳入的值為 99999.0 ,因此造成 x2 or y2 沒辦法 mapping 到 value,進而產生 TypeError: 'float' object is not iterable

因為不了解將 consonet w 取代成 "" 的意義,因此不敢隨意修改,希望可以請教設計上的相關事宜,謝謝您

The range of distances

Hi, I'm using the package for fuzzy matching and want to convert the distance measure to a similarity measure. I would like to use min-max normalization to convert the distance to [0, 1] and use (1 - normalized distance) as my similarity measure. Is there any chance I could know about the upper bound of the distance between two Chinese characters in DimSim? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.