亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當某些字母發生變化時,如何在復數中找到單數?最好的方法是什么?

當某些字母發生變化時,如何在復數中找到單數?最好的方法是什么?

海綿寶寶撒 2023-07-29 13:40:34
當某些字母發生變化時,如何找到復數中的單數?以下情況:德語單詞Schlie?fach是“密碼箱”。復數是Schlie?f?cher.正如您所看到的,這封信a在 中發生了變化?。因此,第一個單詞不再是第二個單詞的子字符串,它們在“正則表達式技術上”是不同的。也許我并不在下面我選擇的標簽的正確角落。也許正則表達式不是適合我的工具。我已經看到naturaljs( natural.NounIflector()) 為英語單詞提供了開箱即用的功能。也許德語也有同樣的解決方案?最好的方法是什么,如何在德語中找到復數中的單數?
查看完整描述

1 回答

?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

我曾經不得不構建一個文本處理器來解析多種語言,包括非常隨意的語言和非常正式的語言。需要確定的一件事是某些單詞是否相關(例如標題中的名詞與一系列事物相關 - 有時用復數形式標記。)


IIRC,我們支持的所有語言中 70-90% 的單數和復數單詞形式的“編輯距離”小于 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.


查看完整回答
反對 回復 2023-07-29
  • 1 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號