📌
Kiến thức tôi biết
  • Giới thiệu
  • Hyperledger Fabric
    • Các công cụ và môi trường
      • Công cụ hỗ trợ cho Ubuntu
      • Docker và hơn thế nữa
      • Vagrant
      • CouchDB
      • PostgresSQL
  • HYPERLEDGER INDY
  • Laravel
    • Cài đặt
    • Tổng hợp câu lệnh
    • Blade Template Engine
  • MySQL
    • Untitled
  • Design pattern
    • Untitled
  • Angular
    • Untitled
  • React
    • Untitled
  • Ethereum
    • Untitled
  • IBM Waston iot platform
    • Untitled
  • dijango
    • Untitled
  • nodejs
    • Untitled
  • java
    • Untitled
  • C# - Winform
    • Untitled
  • C# - ASP.Net
    • Untitled
  • golang
    • Untitled
  • OOP
    • Untitled
  • load balancer
    • Untitled
  • HTML
    • Untitled
  • CSS-SCSS-LESS-SASS
    • Untitled
  • JS-JSX-TS
    • Untitled
  • Vuejs
    • Untitled
  • Ngoài lề
    • Hướng dẫn cài đặt iSpring 9.1 Việt Hóa
  • Xử lý ảnh
    • Miền không gian
    • Miền tần số
    • Ảnh màu
  • Python
    • Tổng quan
  • OpenVPN
  • Symspellpy
  • SymSpell vs. BK-tree: 100x faster fuzzy string search & spell checking
Powered by GitBook
On this page

Was this helpful?

Symspellpy

PreviousOpenVPNNextSymSpell vs. BK-tree: 100x faster fuzzy string search & spell checking

Last updated 5 years ago

Was this helpful?

II. Hướng dẫn sử dụng:

Source code:

Custom code:

git clone https://github.com/phuctu1901/symspellpy symspellpy-vi
cd symspellpy-vi
pip install ./symspellpy-vi
import json, sys
from collections import Counter
import re
from itertools import islice

from symspellpy import SymSpell, Verbosity

def correct_address(data, input):

    sym_spell = SymSpell()
    sym_spell.create_address_list_from_data(data)

    suggestions = sym_spell.lookup(input, Verbosity.CLOSEST,
                                max_edit_distance=6)
    # display suggestion term, term frequency, and edit distance
    
    return suggestions


def find_address(input_str):
    input_str = input_str.replace('\n', ',')
    input_str = input_str.replace(';', ',')
    input_arr=[(o.strip().lstrip()) for o in input_str.split(',')]


    with open('dataset.json', 'r') as fp:
        data = json.load(fp)
    provinces=data.keys()
    results = correct_address(provinces, input_arr[-1])

    if (len(results)==0):
        return "Không so khớp được tỉnh/thành phố"
    key1 = results[0].term
    
    results2 = correct_address(data[key1].keys(), input_arr[-2])
    if (len(results2)==0):
       return "Không so khớp được quận/huyện"
    key2 = results2[0].term


  

    results3 = correct_address(data[key1][key2], input_arr[-3])
    if (len(results3)==0):
       return "Không so khớp được xã/phường {},{}".format(results2[0].term,results[0].term)
    # print(results3[0].term)

    final_result = '{}, {}, {}'.format(results3[0].term,results2[0].term,results[0].term)

    return final_result


def demo(path):
    from os import walk
    files = []
    for (dirpath, dirnames, filenames) in walk(path):
        files.extend(filenames)
        break
    for f in files:
        with open('./DataSample/'+f) as sampleJson:
            sampledata = json.load(sampleJson)
            
            txt = sampledata['Nơi thường trú']
            # txt = sampledata['Quê quán']
            print("\nĐầu vào: {}".format(txt))
            print("\nĐầu ra: {}".format(find_address(txt)))
            print("\n")

if __name__ == "__main__":
    demo('./DataSample')




    
    
    

Trong đó DataSample và dataset.json nằm trong thư mục utils của source vừa tải về.

https://github.com/mammothb/symspellpy
https://github.com/phuctu1901/symspellpy