本文整理汇总了Python中PyDictionary.PyDictionary.meaning方法的典型用法代码示例。如果您正苦于以下问题:Python PyDictionary.meaning方法的具体用法?Python PyDictionary.meaning怎么用?Python PyDictionary.meaning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyDictionary.PyDictionary
的用法示例。
在下文中一共展示了PyDictionary.meaning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DictExpandQuery
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
def DictExpandQuery(q_terms, k=5):
dic = PyDictionary()
new_terms = []
for term in q_terms:
if isStopWord(term):
continue
# check if word exists in the dictionary
w_found = True
try:
dic.meaning(term)
except:
w_found = False
# get k first synonyms
if w_found:
try:
synonyms = dic.synonym(term)
except:
continue
if synonyms == None:
continue
if len(synonyms) > k:
synonyms = synonyms[:k]
new_terms.extend(synonyms)
new_query_terms = q_terms + new_terms
return new_query_terms
示例2: dictionary
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
def dictionary(command):
dictionary = PyDictionary()
words = command.split()
choice = words[0]
word = str(words[-1])
print(choice)
print(word)
try:
if choice == "define":
definition = str(dictionary.meaning(word))
return(definition)
elif choice == "synonyms":
synonyms = dictionary.synonym(word)
result = ', '.join(synonyms)
print(result)
return result
elif choice == "antonyms":
antonyms = dictionary.antonym(word)
result = ', '.join(antonyms)
print(result)
return result
else:
return "Please retry your question"
except TypeError:
return ("Your word had no " + choice)
示例3: dictionary
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
def dictionary(word):
i=0
#while (1):
print word
dictionary=PyDictionary()
dict=dictionary.meaning(word)
if dict is not None:
espeak.synth("your word is " + word)
time.sleep(2.5)
if ( dict.has_key('Adjective')) :
s= dict['Adjective']
if len(s)>=i :
print s[i]
l= len(s[i])
t = l /12.0
espeak.synth("(adjective)" + s[i])
time.sleep(t)
if dict.has_key('Noun') :
s= dict['Noun']
if len(s)>=i :
print s[i]
l= len(s[0])
t = l /12.0
espeak.synth("(NOUN)" + s[i])
time.sleep(t)
if dict.has_key('Verb') :
s= dict['Verb']
if len(s)>=i :
print s[i]
l= len(s[i])
t = l /12.0
espeak.synth("VERB" + s[i])
time.sleep(t)
if dict.has_key('Adverb') :
s= dict['Adverb']
if len(s)>=i :
print s[i]
l= len(s[i])
t = l /12.0
espeak.synth("(ADVERB)" + s[i])
time.sleep(t)
if dict.has_key('Preposition') :
s= dict['Preposition']
if len(s)>=i :
print s[i]
l= len(s[i])
t = l /12.0
espeak.synth("(PREPO)" + s[i])
time.sleep(t)
print 5
示例4: Meaning
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
class Meaning():
def __init__(self):
self.dictionary=PyDictionary()
def meaning_function(self,query,task="mn"): #task can be meaning, translate,
fo=open("meaning.txt","w")
if task == "mn" :
fo.write("Meaning :")
fo.write(str(self.dictionary.meaning(query)))
fo.write("Synonym :")
fo.write(str(self.dictionary.synonym(query)))
fo.write("Antonym :")
fo.write(str(self.dictionary.antonym(query)))
print (self.dictionary.meaning(query))
elif task =="tr":
fo.write("Translation :")
unicodedata.normalize('NFKD', self.dictionary.translate(query,'hi')).encode('ascii','ignore')
fo.write(unicodedata.normalize('NFKD', self.dictionary.translate(query,'hi')).encode('ascii','ignore')) ##Unicode to string conversion
print(self.dictionary.translate(query,'hi'))
fo.close()
def __del__(self):
os.remove("meaning.txt")
示例5: dictionary
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
def dictionary(word):
i=0
while (1):
dictionary=PyDictionary()
dict=dictionary.meaning(word)
if (dict.has_key('Adjective')) :
s= dict['Adjective']
if len(s)>=i :
print s[i]
l= len(s[i])
t = l /12.0
espeak.synth("(adjective)" + s[i])
time.sleep(t)
if dict.has_key('Noun') :
s= dict['Noun']
if len(s)>=i :
print s[i]
l= len(s[0])
t = l /12.0
espeak.synth("(NOUN)" + s[i])
time.sleep(t)
if dict.has_key('Verb') :
s= dict['Verb']
if len(s)>=i :
print s[i]
l= len(s[i])
t = l /12.0
espeak.synth("VERB" + s[i])
time.sleep(t)
if dict.has_key('Adverb') :
s= dict['Adverb']
if len(s)>=i :
print s[i]
l= len(s[i])
t = l /12.0
espeak.synth("(ADVERB)" + s[i])
time.sleep(t)
if dict.has_key('Preposition') :
s= dict['Preposition']
if len(s)>=i :
print s[i]
l= len(s[i])
t = l /12.0
espeak.synth("(PREPO)" + s[i])
time.sleep(t)
espeak.synth("If alternate meaning required, give a double tap within the next 3 seconds")
示例6: dictionary
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
async def dictionary(self, word):
"""Checks the dictionary for the meanings of a given word."""
word = word.lower()
try:
result = dictionary.meaning(word)
nountext = self.meaning_text_format("Noun", result)
verbtext = self.meaning_text_format("Verb", result)
adjtext = self.meaning_text_format("Adjective", result)
advtext = self.meaning_text_format("Adverb", result)
except TypeError:
return await self.bot.say("No results found. Are you " +
"searching for a valid word?")
text = "\n" + nountext + verbtext + adjtext + advtext
definition = "Found the following definitions for **" + word + "**:" \
+ text
return await self.bot.say(definition)
示例7: handle
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
def handle(text, mic, profile):
lst = text.split()
text = lst[len(lst)-1]
if(text):
dictionary=PyDictionary()
mean = dictionary.meaning(text)
if not mean:
mic.say("I'm sorry I couldn't find the meaning of the word "+text)
return
mic.say(text)
for keys in mean:
mic.say(keys)
lst = mean[keys]
for l in lst:
mic.say(l)
示例8: PyDictionary
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
from PyDictionary import PyDictionary
dictionary= PyDictionary()
print (dictionary.meaning("indentation"))
示例9: print
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
try:
with sr.Microphone() as source: # use the default microphone as the audio source
audio = r.listen(source)
sentence=r.recognize_google(audio)
print('I heard that you said:\n',sentence)
except:
sentence=input('Enter a sentence (we could not figure out what you said)')
google_username = "[email protected]"
google_password = "password"
path = ""
sent=[]
for elem in sentence.split(' '):
pier=dictionary.meaning(elem)
if 'Noun' in str(pier):
if len(pier)==1:
sent.append(elem)
pie=[]
real=[]
loopy=0
tea=[]
if len(sent)>3:
for elem in sent:
loopy=loopy+1
tea.append(elem)
if loopy==3:
loopy=0
pie.append(','.join(tea))
tea=[]
示例10: len
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
bot_response = ", ".join(bot_response)
else:
bot_response = "Sorry i couldn't find the synonym for "," ".join(bot_response)
print bot_response
elif " ".join(message.strip().lower().split()[:2]) == "antonym of":
bot_response = (dictionary.antonym(" ".join(message.strip().lower().split()[2:])))
if(len(bot_response) >= 1 ):
bot_response = ", ".join(bot_response)
else:
bot_response = "Sorry i couldn't find the antonym for "," ".join(bot_response)
print bot_response
elif " ".join(message.strip().lower().split()[:2]) == "meaning of":
bot_response = dictionary.meaning(" ".join(message.strip().lower().split()[2:]))
if len (bot_response.keys()) == 0 :
bot_response = "Sorry, Couldn't find the meaning "
else:
if 'Noun' in bot_response.keys():
print bot_response['Noun'][0]
else:
print "Not found"
#tasks
elif message.strip().split()[0].lower() == 'tasks' :
bot_response = ''
示例11: PyDictionary
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
# currently just the list of matched words
text_output = class_list.__str__()
# Parts of speech recognition
tokens = nltk.word_tokenize(class_str)
dictionary = PyDictionary()
nouns = []
verbs = []
adjectives = []
otherPos = []
for word in tokens:
definition = dictionary.meaning(word) # https://pypi.python.org/pypi/PyDictionary/1.3.4
assignment = definition.keys()[0] # Get the part of speech from the dictonary
# assignment = tuple[1]
if assignment == 'Noun':
nouns.append(word)
elif assignment == 'Verb':
verbs.append(word)
elif assignment == 'Adjective':
adjectives.append(word)
else:
otherPos.append(word)
# Create the grammar
示例12: syno
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
def syno(word):
dictionary=PyDictionary()
return (dictionary.meaning(word))
示例13: print
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
sent=[]
for elem in t:
fee=[]
tre=elem.split(' ')
for eem in tre:
if eem!='' and eem!='/n':
fee.append(eem)
sent.append(fee)
l=[]
real=[]
var=0
for elem in sent:
l=[]
var=0
for ele in elem:
fr=dictionary.meaning(ele)
try:
fr=list(fr.keys())
try:
l.append(mode(fr))
except StatisticsError:
l.append(fr[0])
print(l)
except AttributeError:
var=1
if var==0:
real.append(l)
示例14: __init__
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
class DictionaryIndicator:
def __init__(self):
#dictionary related
self.dictionary_offline=PyDictionary()
#appindicator related
self.indicator=appindicator.Indicator("dictionary-indicator", gtk.STOCK_SPELL_CHECK, appindicator.CATEGORY_APPLICATION_STATUS)
self.indicator.set_status(appindicator.STATUS_ACTIVE)
self.indicator.set_attention_icon("Dictionary")
self.start()
self.indicator.set_menu(self.menu)
def start(self):
# start a dictionary window
self.menu=gtk.Menu()
self.dictionary=gtk.MenuItem("Start Dictionary")
self.dictionary.connect("activate", self.openWindow)
self.dictionary.show()
self.menu.append(self.dictionary)
# exit button
self.quit_button=gtk.MenuItem("Quit")
self.quit_button.connect("activate", self.quit)
self.quit_button.show()
self.menu.append(self.quit_button)
def main(self):
self.start()
gtk.main()
def openWindow(self, widget):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Dictionary")
self.window.set_size_request(300, 150)
# container box
self.vbox=gtk.VBox(False, 0)
self.window.add(self.vbox)
self.vbox.show()
#input
self.textbox=gtk.Entry()
self.textbox.set_max_length(30)
self.textbox.set_text("Enter word here")
self.vbox.pack_start(self.textbox, True, True, 0)
self.textbox.show()
#output
self.results=gtk.Entry()
self.results.set_max_length(300)
self.results.set_text("Meanings appear here")
self.vbox.pack_start(self.results, True, True, 0)
self.results.show()
self.find_meaning=gtk.Button(stock=gtk.STOCK_DIALOG_QUESTION)
self.find_meaning.connect("clicked", self.meaning)
self.find_meaning.show()
self.vbox.pack_start(self.find_meaning, True, True, 0)
self.window.show()
def meaning(self, widget):
words=self.textbox.get_text()
words_to_find_meaning = re.split('[^a-zA-Z0-9]',words)
meanings=""
for w in words_to_find_meaning:
for key, val in self.dictionary_offline.meaning(w).items():
if(len(val) > 0):
meanings+=val[0]
else:
meanings+="Not found"
break
meanings+=";"
self.results.set_text(meanings)
def quit(self, widget):
print "hell came here"
sys.exit(0)
示例15: BeautifulSoup
# 需要导入模块: from PyDictionary import PyDictionary [as 别名]
# 或者: from PyDictionary.PyDictionary import meaning [as 别名]
@author: SRINIVAS
"""
"""
import urllib
from bs4 import BeautifulSoup
url = "http://weather.weatherbug.com/MN/Wahkon-weather.html?zcode=z6286&zip=56386"
soup = BeautifulSoup(urllib.request.urlopen(url).read())
a=soup.find(name="span", id="divHi").get_text()
b=soup.find(name="span", id="divLo").get_text()
"""
from PyDictionary import PyDictionary
dictionary=PyDictionary()
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source: # use the default microphone as the audio source
audio = r.listen(source) # listen for the first phrase and extract it into audio data
try:
a=r.recognize_google(audio)
except LookupError: # speech is unintelligible
print("Could not understand audio")
s=a.split(' ')
der=-1
trte=0
if len(s)==2 and s[0]=='Define':
srer=s[1]
fret=dictionary.meaning(srer).items()
for elem in fret:
print(elem[0],'\n',elem[1][0])