[英]How to find singular in the plural when some letters change? What is the best approach?
當某些字母發生變化時,如何在復數中找到單數?
以下情況:
Schließfach
是一個密碼箱。Schließfächer.
如您所見,字母a
在ä
中發生了變化。 出於這個原因,第一個單詞不再是第二個單詞的子字符串,它們在“正則表達式技術”上是不同的。
也許我在下面選擇的標簽不在正確的角落。 也許正則表達式對我來說不是正確的工具。 我已經看到naturaljs
( naturaljs
( natural.NounIflector()
) 為英語單詞提供了開箱即用的功能。 也許德語也有同樣的解決方案?
什么是最好的方法,我如何在德語的復數中找到單數?
我曾經不得不構建一個文本處理器來解析多種語言,包括非常隨意到非常正式的語言。 要確定的一件事是某些單詞是否相關(例如標題中的名詞與一系列事物相關 - 有時用復數形式標記。)
IIRC,在我們支持的所有語言中,70-90% 的單復數詞形式的“Levenshtein 距離”小於 3 或 4。(最終添加了幾個詞典以提高准確性,因為僅“距離”就產生了許多誤報。)另一個有趣的發現是,單詞越長,3 或更少的距離就越有可能意味着意義上的關系。
這是我們使用的庫的示例:
const fastLevenshtein = require('fast-levenshtein');
console.log('Deburred Distances:')
console.log('Score 1:', fastLevenshtein.get('Schließfächer', 'Schließfach'));
// -> 3
console.log('Score 2:', fastLevenshtein.get('Blumtach', 'Blumtächer'));
// -> 3
console.log('Score 3:', fastLevenshtein.get('schließfächer', 'Schliessfaech'));
// -> 7
console.log('Score 4:', fastLevenshtein.get('not-it', 'Schliessfaech'));
// -> 12
console.log('Score 5:', fastLevenshtein.get('not-it', 'Schiesse'));
// -> 8
/**
* Additional strategy for dealing with other various languages:
* "Deburr" the strings to omit diacritics before checking the distance:
*/
const deburr = require('lodash.deburr');
console.log('Deburred Distances:')
console.log('Score 1:', deburr(fastLevenshtein.get('Schließfächer', 'Schließfach')));
// -> 3
console.log('Score 2:', deburr(fastLevenshtein.get('Blumtach', 'Blumtächer')));
// -> 3
console.log('Score 3:', deburr(fastLevenshtein.get('schließfächer', 'Schliessfaech')));
// -> 7
// Same in this case, but helpful in other similar use cases.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.