티스토리 뷰
Functions¶
Jellyfish provides a variety of functions for string comparison[문자 비교], phonetic encoding[발음 구분], and stemming [어간 추출].
String Comparison¶
These methods are all measures of the difference (aka edit distance) between two strings.
Levenshtein Distance¶
def levenshtein_distance(s1: str, s2: str)
Compute the Levenshtein distance between s1 and s2.
Levenshtein distance represents the number of insertions, deletions, and substitutions required to change one word to another.
For example: levenshtein_distance('berne', 'born') == 2 representing the transformation of the first e to o and the deletion of the second e.
See the Levenshtein distance article at Wikipedia for more details.
Damerau-Levenshtein Distance¶
def damerau_levenshtein_distance(s1: str, s2: str)
Compute the Damerau-Levenshtein distance between s1 and s2.
A modification of Levenshtein distance, Damerau-Levenshtein distance counts transpositions (such as ifsh for fish) as a single edit.
Where levenshtein_distance('fish', 'ifsh') == 2 as it would require a deletion and an insertion, though damerau_levenshtein_distance('fish', 'ifsh') == 1 as this counts as a transposition.
See the Damerau-Levenshtein distance article at Wikipedia for more details.
Hamming Distance¶
def hamming_distance(s1: str, s2: str)
Compute the Hamming distance between s1 and s2.
Hamming distance is the measure of the number of characters that differ between two strings.
Typically Hamming distance is undefined when strings are of different length, but this implementation considers extra characters as differing. For example hamming_distance('abc', 'abcd') == 1.
See the Hamming distance article at Wikipedia for more details.
Jaro Similarity¶
def jaro_similarity(s1: str, s2: str)
Compute the Jaro similarity between s1 and s2.
Jaro distance is a string-edit distance that gives a floating point response in [0,1] where 0 represents two completely dissimilar strings and 1 represents identical strings.
Warning
Prior to 0.8.1 this function was named jaro_distance. That name is still available, but is no longer recommended. It will be replaced in 1.0 with a correct version.
Jaro-Winkler Similarity¶
def jaro_winkler_similarity(s1: str, s2: str)
Compute the Jaro-Winkler distance between s1 and s2.
Jaro-Winkler is a modification/improvement to Jaro distance, like Jaro it gives a floating point response in [0,1] where 0 represents two completely dissimilar strings and 1 represents identical strings.
Warning
Prior to 0.8.1 this function was named jaro_winkler. That name is still available, but is no longer recommended. It will be replaced in 1.0 with a correct version.
See the Jaro-Winkler distance article at Wikipedia for more details.
Match Rating Approach (comparison)¶
def match_rating_comparison(s1, s2)
Compare s1 and s2 using the match rating approach algorithm, returns True if strings are considered equivalent or False if not. Can also return None if s1 and s2 are not comparable (length differs by more than 3).
The Match rating approach algorithm is an algorithm for determining whether or not two names are pronounced similarly. Strings are first encoded using :py:func:match_rating_codex then compared according to the MRA algorithm.
See the Match Rating Approach article at Wikipedia for more details.
Phonetic Encoding¶
These algorithms convert a string to a normalized phonetic encoding, converting a word to a representation of its pronunciation. Each takes a single string and returns a coded representation.
American Soundex¶
def soundex(s: str)
Calculate the American Soundex of the string s.
Soundex is an algorithm to convert a word (typically a name) to a four digit code in the form 'A123' where 'A' is the first letter of the name and the digits represent similar sounds.
For example soundex('Ann') == soundex('Anne') == 'A500' and soundex('Rupert') == soundex('Robert') == 'R163'.
See the Soundex article at Wikipedia for more details.
Metaphone¶
def metaphone(s: str)
Calculate the metaphone code for the string s.
The metaphone algorithm was designed as an improvement on Soundex. It transforms a word into a string consisting of '0BFHJKLMNPRSTWXY' where '0' is pronounced 'th' and 'X' is a '[sc]h' sound.
For example metaphone('Klumpz') == metaphone('Clumps') == 'KLMPS'.
See the Metaphone article at Wikipedia for more details.
NYSIIS¶
def nysiis(s: str)
Calculate the NYSIIS code for the string s.
The NYSIIS algorithm is an algorithm developed by the New York State Identification and Intelligence System. It transforms a word into a phonetic code. Like soundex and metaphone it is primarily intended for use on names (as they would be pronounced in English).
For example nysiis('John') == nysiis('Jan') == JAN.
See the NYSIIS article at Wikipedia for more details.
Match Rating Approach (codex)¶
def match_rating_codex(s: str)
Calculate the match rating approach value (also called PNI) for the string s.
The Match rating approach algorithm is an algorithm for determining whether or not two names are pronounced similarly. The algorithm consists of an encoding function (similar to soundex or nysiis) which is implemented here as well as :py:func:match_rating_comparison which does the actual comparison.
See the Match Rating Approach article at Wikipedia for more details.
Stemming¶
Porter Stemmer¶
def porter_stem(s: str)
Reduce the string s to its stem using the common Porter stemmer.
Stemming is the process of reducing a word to its root form, for example 'stemmed' to 'stem'.
Martin Porter's algorithm is a common algorithm used for stemming that works for many purposes.
See the official homepage for the Porter Stemming Algorithm for more details.
'IT > IT 이것 저것' 카테고리의 다른 글
[Python, Data analysis] Numpy(1)_nbarray 만들기 (0) | 2022.11.11 |
---|---|
[자연어 처리] CRF in python (0) | 2022.09.12 |
[논문해석] Semi supervised(준지도 학습)을 활용한 모바일 제품명 추출하기 (0) | 2022.09.08 |
[IT, 통계]문자열 전처리 내용 정리 (0) | 2022.09.03 |
(IT) 크롤링 기본? 이걸로 끝. (0) | 2022.08.10 |
- Total
- Today
- Yesterday
- PYTHON
- 크롤링
- Unity
- 마케팅
- 알고리즘
- IT기초
- 심리학
- Anet
- 강화학습
- requests
- 파이썬
- 주식투자
- 유니티
- 프로그래머스
- 비전공자
- 사진크롤링
- 경영학
- 랜덤맵
- 스타트업
- 머신러닝
- 터틀트레이딩
- 주식
- beautifulsoup
- ET5X
- C#
- It
- 일자별
- 가격데이터
- 시스템투자
- json
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |