使用Matlab实现英文单词的"形近词"查找

引言

最近在背考博词汇,考博词汇是12000词左右.

短时间内去记忆这么多单词是很有挑战性的.我个人习惯用的方法是:

  1. 将陌生的长单词分成熟悉的小单词, 用小单词造句, 把生词的意义包含进去;
  2. 多读一些这个生词的句子, 在语境中加深意义;
  3. 通过一个与这个生词长的很相近的自己很熟悉的词来记忆生词.
  4. 艾宾浩斯多次复习减少遗忘.

第三个方法就是用"形近词"去记忆.

这个方法我感觉是很好用的, 就跟有个朋友给你介绍新朋友一样.

而且, 因为在背单词的时候常常很容易将一个单词与他的形近词相混淆, 所以, 在背单词的时候如果能查找形近词该多好啊.

把一些形近词放到一起, 便于记忆,也便于辨析.

比如:

complexity
complicacy
complicate
complicity
simplicity
网上虽然有不少英语学习爱好者和研究教育机构整理的形近词词库,遗憾的是,并没有一款词典能够提供形近词查询功能.

金山词霸等词典软件虽然可以使用通配符, 但是, 通过通配符去找形近词需要你自己去拟定通配规则, 很麻烦.


考察了一下,做了个简单的小程序,这下子,大大辅助我背单词了.


方法

这个问题,其实就是一个词形近似度的问题[4].其实,跟spell checking[3]根据词形相近度自动提供spell suggestion和spell correction是一样的问题,

用正则表达式也可以实现, 不过, 需要你自己定义n多的变形规则.很麻烦.

在这里,我主要是通过计算两词之间的编辑距离(edit distance)[1]来判断.


在Matlab下做了一个toy程序,用经典的Levenshtein Distance[2]算法(算法细节参考Wikipedia及相关文章)实现了形近词查找功能. word-to-word匹配用了动态规划,所以速度很快.

另外,还有Jaro–Winkler distance[5], 还有发音相似度(phonetic distance)[6]都可以考虑使用, 我这里暂时只用了L氏距离.

关于L氏算法的一个直观的实例:


用法

  1. 提供你想查询的词汇;
  2. 提供相似度阈值n(n就是edit distance,意思就是通过几次元编辑操作,插入,删除,替换, 可以实现两个单词的匹配);
  3. 提供你想要查询的词典(这里用的是一个txt格式的word list);

运行算法之后, 会对word list进行一次遍历,计算词典里每个词跟你要查询词之间的edit distance, 最后, 用一个阈值过滤出最相近的单词.


效果

词库用的是四六级词库.

edit distance取3.

从四六级词库里插simple的形近词,有4个(算上它自己):


代码

主函数:

%% this is the main function
% Input :
%	wordToMatch - input word
%	distThresh	- edit distance threshold, usually use 3
%	dicPath		- file path of the word list file, txt format with every
%				  line of a single word
% 
% Output :
%	command window output 
% 
% Created by visionfans @ 2011.07.20
function findSimilarWords(wordToMatch, distThresh, dicPath )
	global word;
	word = wordToMatch;

	%% check parameters
	switch nargin
		case 0,
			error('Wrong arguments!');
		case 1,
			distThresh = 3;
			dicPath = '46.txt';
	end
	
	%% load word list
	wordList = loadWordList(dicPath);

	%% calculate edit distance
	editDist = cellfun(@calcEditDist,wordList);

	%% filter the similar words
	similarWords = wordList(editDist < distThresh);

	%% display results
	fprintf('There are %d similar words with "%s" : \n', length(similarWords), word);
	cellfun(@(x)fprintf('\t%s\n', x),similarWords);
end

L氏距离计算函数:

%% this function is used to calculate the Levenshtein Edit Distance
% 
% S1 and S2 are two words you want to calculate their edit distance
% 
% Created by visionfans @ 2011.07.20
function dist = calcEditDist(s1,s2)    
    global word;

    if nargin == 1
        s2 = word;
    end
        
    %% calculate the edit distance with DP
    m = length(s1);
    n = length(s2);

    if m*n == 0
        dist = Inf;
        return;
    end
    
    table = zeros(m,n);

    table(:,1) = 0:m-1;
    table(1,:) = 0:n-1;
    
    for i=2:m
        for j=2:n
            if s1(i-1)==s2(j-1)
                table(i,j) = table(i-1,j-1);
            else
                table(i,j) = 1 + min([(min(table(i-1,j),table(i,j-1))),table(i-1,j-1)]);
            end
        end
    end
    
    %% set result
    dist = table(m,n);
    return;
end

词典加载函数:

%% this function is used to load the dictionary file
% The dictionary file is a text file with the format of every line be a
% single word.
% 
% You can find a word list file with adequate common words here:
%    Kevin's Word List Page - http://wordlist.sourceforge.net/
% 
% Created by visionfans @ 2011.07.20
function wordList = loadWordList(dictPath)
    fprintf('Loading word list ...\n');
    fid = fopen(dictPath);

    i = 1;
    tline = fgetl(fid);
    while ischar(tline)
        wordList{i,1} = tline;
        tline = fgetl(fid);
        i = i+1;
    end
    fclose(fid);
end


补充

有很多更全的词库文件,在这里[7]可以找到很多.

感谢Jukuu网工程师YNYS提供四六级word list, Thanks.微笑

已经长传到这里[8], 有兴趣的同学可以做测试.


-----------------------------------------------------------------------个人使用,所以懒得改C了.


References

[1] Edit distance , http://nlp.stanford.edu/IR-book/html/htmledition/edit-distance-1.html

[2] Levenshtein distance - Wikipedia, the free encyclopedia, http://en.wikipedia.org/wiki/Levenshtein_distance

[3] How to Write a Spelling Corrector, http://norvig.com/spell-correct.html

[4] Approximate string matching - Wikipedia, the free encyclopedia, http://en.wikipedia.org/wiki/Approximate_string_matching

[5] Jaro–Winkler distance - Wikipedia, the free encyclopedia, http://en.wikipedia.org/wiki/Jaro-Winkler_distance

[6] Soundex - Wikipedia, the free encyclopedia, http://en.wikipedia.org/wiki/Soundex

[7] Dictionary & Glossary Links; Downloadable Word Lists, http://www.net-comber.com/wordurls.html

[8] 四六级词汇表, http://download.youkuaiyun.com/source/3455828

    ### 关于 UniApp 框架推荐资源与教程 #### 1. **Uniapp 官方文档** 官方文档是最权威的学习资料之一,涵盖了从基础概念到高级特性的全方位讲解。对于初学者来说,这是了解 UniApp 架构技术细节的最佳起点[^3]。 #### 2. **《Uniapp 从入门到精通:案例分析与最佳实践》** 该文章提供了系统的知识体系,帮助开发者掌握 Uniapp 的基础知识、实际应用以及开发过程中的最佳实践方法。它不仅适合新手快速上手,也能够为有经验的开发者提供深入的技术指导[^1]。 #### 3. **ThorUI-uniapp 开源项目教程** 这是一个专注于 UI 组件库设计实现的教学材料,基于 ThorUI 提供了一系列实用的功能模块。通过学习此开源项目的具体实现方式,可以更好地理解如何高效构建美观且一致的应用界面[^2]。 #### 4. **跨平台开发利器:UniApp 全面解析与实践指南** 这篇文章按照章节形式详细阐述了 UniApp 的各个方面,包括但不限于其工作原理、技术栈介绍、开发环境配置等内容,并附带丰富的实例演示来辅助说明理论知识点。 以下是几个重要的主题摘选: - **核心特性解析**:解释了跨端运行机制、底层架构组成及其主要功能特点。 - **开发实践指南**:给出了具体的页面编写样例代码,展示了不同设备间 API 调用的方法论。 - **性能优化建议**:针对启动时间缩短、图形绘制效率提升等方面提出了可行策略。 ```javascript // 示例代码片段展示条件编译语法 export default { methods: { showPlatform() { console.log(process.env.UNI_PLATFORM); // 输出当前平台名称 #ifdef APP-PLUS console.log('Running on App'); #endif #ifdef H5 console.log('Running on Web'); #endif } } } ``` #### 5. **其他补充资源** 除了上述提到的内容外,还有许多在线课程视频可供选择,比如 Bilibili 上的一些免费系列讲座;另外 GitHub GitCode 平台上也有不少优质的社区贡献作品值得借鉴研究。 --- ###
    评论 4
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值