2017-06-19 4 views
0

"sooooooooooooooo"のような単語を特定し、スペルチェックで "so"と置き換えたいと思います。どうすればこれを達成できますか?私は何を書いていますか(フィルターなどを意味します)、そして同じコードをどこで微調整しますか?PyEnchant:インターネットにやさしい単語を英語の単語に置き換えてください

ありがとうございます!

+0

理想的には、私は同じあちこちREGEXを書くことになり、コードを微調整するのはどこですか? –

答えて

0

store_replacementを使用することもできますが、私はstore_replacementを基になるプロバイダが実装する必要があることを理解しています。あなたは、プロバイダAspellのを使用している場合は、それを実装しているあなたはそれがそうのような作業を見ることができます(あなたがAspellのをインストールする必要があります注意してください、それは、この作業を見て辞書です)

import enchant 
# Get the broker. 
b = enchant.Broker() 
# Set the ordering on the broker so aspell gets used first. 
b.set_ordering("en_US","aspell,myspell") 
# Print description of broker just to see what's available. 
print (b.describe()) 
# Get an US English dictionary. 
d=b.request_dict("en_US") 
# Print the provider of the US English dictionary. 
print (d.provider) 
# A test string. 
s = 'sooooooooooooooo' 
# We will check the word is not in the dictionary not needed if we know it isn't. 
print (d.check(s)) 
# Print suggestions for the string before we change anything. 
print (d.suggest(s)) 
# Store a relacement for our string as "so". 
d.store_replacement(s, 'so') 
# Print our suggestions again and see "so" appears at the front of the list. 
print (d.suggest(s)) 

[<Enchant: Aspell Provider>, <Enchant: Ispell Provider>, <Enchant: Myspell Provider>, <Enchant: Hspell Provider>] 
<Enchant: Aspell Provider> 
False 
['SO', 'so', 'spoor', 'sou', 'sow', 'soy', 'zoo', 'Soho', 'Soto', 'solo', 'soon', 'soot', 'shoo', 'soar', 'sour', 'shoos', 'sooth', 'sooty', 'Si', 'sootier', 'sough', 'SOP', 'sop', 'S', 'poo', 's', 'sooner', 'soothe', 'sorrow', 'Sir', 'Sui', 'sci', 'sir', 'poos', 'silo', 'soap', 'soil', 'soup', 'SA', 'SE', 'SS', 'SW', 'Se', 'soother', 'SOB', 'SOS', 'SOs', 'SRO', 'Soc', 'Sol', 'Son', 'sob', 'soc', 'sod', 'sol', 'son', 'sot', 'boo', 'coo', 'foo', 'goo', 'loo', 'moo', 'ooh', 'too', 'woo', 'CEO', "S's", 'SSA', 'SSE', 'SSS', 'SSW', 'Sue', 'Zoe', 'saw', 'say', 'sea', 'see', 'sew', 'sue', 'xor', 'Snow', 'Sony', 'Sosa', 'boos', 'bozo', 'coos', 'loos', 'moos', 'oohs', 'ooze', 'oozy', 'orzo', 'ouzo', 'sago', 'scow', 'sloe', 'slow', 'snow', 'soak'] 
['so', 'SO', 'spoor', 'sou', 'sow', 'soy', 'zoo', 'Soho', 'Soto', 'solo', 'soon', 'soot', 'shoo', 'soar', 'sour', 'shoos', 'sooth', 'sooty', 'Si', 'sootier', 'sough', 'SOP', 'sop', 'S', 'poo', 's', 'sooner', 'soothe', 'sorrow', 'Sir', 'Sui', 'sci', 'sir', 'poos', 'silo', 'soap', 'soil', 'soup', 'SA', 'SE', 'SS', 'SW', 'Se', 'soother', 'SOB', 'SOS', 'SOs', 'SRO', 'Soc', 'Sol', 'Son', 'sob', 'soc', 'sod', 'sol', 'son', 'sot', 'boo', 'coo', 'foo', 'goo', 'loo', 'moo', 'ooh', 'too', 'woo', 'CEO', "S's", 'SSA', 'SSE', 'SSS', 'SSW', 'Sue', 'Zoe', 'saw', 'say', 'sea', 'see', 'sew', 'sue', 'xor', 'Snow', 'Sony', 'Sosa'] 
+0

真。 Apellはstore_replacement()を実装していますが、ほとんどの場合、Aspellは最初の提案としてstore_replacement( "soooooo"、 "so")を使用して設定語を提案しません。その場合は、私の設定提案の重量を増やす方法はありますか?それは常に最初に表示されているのですか? –

+0

私の経験では、単語が辞書にあれば、推奨置換は2番目に来ます私はstore_replacement( "soooooo"、 "so")でテストしたところ、最初に来たのですが、それが二番目に来て辞書にない例を教えてもらえますか?つまり、print(d.check(s))はFalseですもう1つのテストは、テストされている単語が最初の提案ではなく、示唆された置換が2番目に来るときです。 –

関連する問題