英文:
hunspell suggest hyphen for words misspelled without hyphens
问题
我有单词 wi-fi,spell-check,line-break 在我的 .dic 文件中。
我想要以下建议:
wifi -> 建议 wi-fi
spellcheck -> 建议 spell-check
linebreak -> 建议 line-break
我需要哪种 aff 设置来允许这样做?
英文:
I have the words wi-fi, spell-check, line-break in my .dic file.
I want the following suggestions:
wifi -> Suggest wi-fi
spellcheck -> Suggest spell-check
linebreak -> Suggest line-break
What aff setup do I need to allow that?
答案1
得分: 1
在Typo.js中,可以用于建议的字符字母表被限制在a-z范围内。请查看源代码的第788行:
self.alphabet = "abcdefghijklmnopqrstuvwxyz";
有趣的是,在这行下面有一段被注释掉的代码,它可以根据字典自动确定字母表,这本来可以防止问题发生。然而,如果不使用该代码,您可以在这个列表中手动添加字符。请将源代码中的那一行替换为以下内容:
self.alphabet = "abcdefghijklmnopqrstuvwxyz-";
然后建议将包含连字符的字典项。代码(改编自https://github.com/cfinke/Typo.js/blob/master/examples/node/index.js):
<!DOCTYPE html>
<html lang="en">
<head>
<script src="typo.js"></script>
<script>
function checkwords(){
var is_spelled_correctly = dictionary.check("normal");
console.log( "Is 'normal' spelled correctly? " + is_spelled_correctly );
var is_spelled_correctly = dictionary.check("line-break");
console.log( "Is 'line-break' spelled correctly? " + is_spelled_correctly );
var is_spelled_correctly = dictionary.check("linebreak");
console.log( "Is 'linebreak' spelled correctly? " + is_spelled_correctly );
var array_of_suggestions = dictionary.suggest("linebreak");
console.log( "Spelling suggestions for 'linebreak': " + array_of_suggestions.join( ', ' ) );
}
var dictionary = new Typo("yourdictionary", false, false, { dictionaryPath: ".", asyncLoad: 1, loadedCallback: checkwords });
</script>
<meta charset="utf-8" />
</head>
<body>
Typo.js测试<br>
</body>
</html>
用于测试的字典:
5
normal
word
wi-fi
spell-check
line-break
输出:
Is 'normal' spelled correctly? true
Is 'line-break' spelled correctly? true
Is 'linebreak' spelled correctly? false
Spelling suggestions for 'linebreak': line-break
英文:
In Typo.js the alphabet of characters that can be used in suggestions is limited to a-z. See line 788 of the source code:
self.alphabet = "abcdefghijklmnopqrstuvwxyz";
Interestingly, below this line there is a commented out piece of code that determines the alphabet from the dictionary itself, which would have prevented the issue in the question. However, without using that code you can add characters manually in this list. Replace that line in the source by the following:
self.alphabet = "abcdefghijklmnopqrstuvwxyz-";
Then the suggestions will include dictionary items with a hyphen. Code (adapted from https://github.com/cfinke/Typo.js/blob/master/examples/node/index.js):
<!DOCTYPE html>
<html lang="en">
<head>
<script src="typo.js"></script>
<script>
function checkwords(){
var is_spelled_correctly = dictionary.check("normal");
console.log( "Is 'normal' spelled correctly? " + is_spelled_correctly );
var is_spelled_correctly = dictionary.check("line-break");
console.log( "Is 'line-break' spelled correctly? " + is_spelled_correctly );
var is_spelled_correctly = dictionary.check("linebreak");
console.log( "Is 'linebreak' spelled correctly? " + is_spelled_correctly );
var array_of_suggestions = dictionary.suggest("linebreak");
console.log( "Spelling suggestions for 'linebreak': " + array_of_suggestions.join( ', ' ) );
}
var dictionary = new Typo("yourdictionary", false, false, { dictionaryPath: ".", asyncLoad: 1, loadedCallback: checkwords });
</script>
<meta charset="utf-8" />
</head>
<body>
Typo.js test<br>
</body>
</html>
Dictionary used for testing:
5
normal
word
wi-fi
spell-check
line-break
Output:
Is 'normal' spelled correctly? true
Is 'line-break' spelled correctly? true
Is 'linebreak' spelled correctly? false
Spelling suggestions for 'linebreak': line-break
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论