2017-06-19 4 views

Antwort

0

Sie könnten store_replacement verwenden, aber mein Verständnis ist, dass store_replacement vom zugrunde liegenden Provider implementiert werden muss. Wenn Sie den Anbieter Aspell verwenden, die es implementiert Sie es arbeiten wie so sehen: (Anmerkung müssen Sie Aspell installieren und es ist Wörterbücher diese Funktion sehen)

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

Wahr. Apell implementiert die store_replacement() ... Aber die Herausforderung ist die meiste Zeit, Aspell wird mein gesetztes Wort NICHT vorschlagen (zB: mit store_replacement ("soooooo", "so") als FIRST Suggestion. Es kann als zweites kommen. In diesem Fall gibt es eine Möglichkeit, die WEIGHTAGE meines Set-Vorschlags zu erhöhen, so erscheint es immer zuerst in den Vorschlägen? –

+0

Wenn das Wort im Wörterbuch ist, wird der vorgeschlagene Ersatz an zweiter Stelle kommen, andernfalls wird es zuerst kommen Ich habe gerade mit store_replacement ("soooooo", "so") getestet und es kam zuerst: Kannst du mir ein Beispiel geben, wenn es an zweiter Stelle steht und nicht im Dictionary ie print (d.check (s)) ist False und der vorgeschlagene Ersatz kommt an zweiter Stelle? Ein anderer Test ist, wenn das Wort, das geprüft wird, nicht der erste Vorschlag ist und der vorgeschlagene Ersatz an zweiter Stelle steht? –

Verwandte Themen