当前位置: 首页>>代码示例>>Python>>正文


Python PyDictionary.PyDictionary类代码示例

本文整理汇总了Python中PyDictionary.PyDictionary的典型用法代码示例。如果您正苦于以下问题:Python PyDictionary类的具体用法?Python PyDictionary怎么用?Python PyDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PyDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dictionary

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)
开发者ID:jcallin,项目名称:eSeMeS,代码行数:27,代码来源:dictionary.py

示例2: DictExpandQuery

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
开发者ID:HemanthShetty,项目名称:CS6200Project,代码行数:33,代码来源:QueryExpansion.py

示例3: game

def game():
    words = create_word_list()
    lookup = PyDictionary()
    global attempts, wins
    idx = 0
    answer = random.choice(words)
    while idx < 3:
        clue = lookup.synonym(answer)[idx]
        now = time.time()
        future = now + 10
        print('\nClue: ' + clue)
        guess = input('Guess: ').lower()
        if guess == answer or guess + 's' == answer or guess == answer[:-3]:
            print("\nCorrect!")
            wins += 1
            break
        elif now > future:
            print("You ran out of time! The answer was %s." % answer)
            break
        else:
            print("\nWrong.")
            idx += 1
            if idx == 3:
                print("\nThe answer was %s." % answer)

    attempts += 1
    print("Game over. Your score was %d / %d." % (wins, attempts))
    print('-' * 10)
    words.remove(answer)
    restart()
开发者ID:reeses-pieces,项目名称:word_games,代码行数:30,代码来源:password.py

示例4: process_dictionary

def process_dictionary(word):
    meaning = "You searched for the word {}.  "
    dictionary = PyDictionary(word)
    our_meaning = dictionary.getMeanings()
    meaning = meaning.format(our_meaning.keys()[0])
    l = zip(our_meaning.values()[0].keys(),our_meaning.values()[0].values()[0])
    for idx in l:
        meaning += idx[0] + ":" + idx[1] + ", "
    return meaning[:-1]
开发者ID:mascot6699,项目名称:Hackapi-Demo,代码行数:9,代码来源:utils.py

示例5: antonym

def antonym(word):
	try:
		word = word.lower()
		dictionary = PyDictionary()
		anto_list = (dictionary.antonym(word))
		print("The antonym(s) of the word %s are:"%word)
		for i in range(0,len(anto_list)):
			print (str(i+1)+')'+anto_list[i].encode('ascii'))
	except TypeError:
		word = raw_input("Re-enter the word with the correct spelling: ")
		antonym(word)
开发者ID:nityanandagohain,项目名称:PyDic,代码行数:11,代码来源:main.py

示例6: dictionary

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
开发者ID:PAAF-itsp2016,项目名称:final-programs,代码行数:54,代码来源:Final.py

示例7: dictionary

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")
开发者ID:PAAF-itsp2016,项目名称:learning-codes,代码行数:49,代码来源:Dict.py

示例8: handle

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)
开发者ID:TuxSeb,项目名称:naomi,代码行数:17,代码来源:Dictionary.py

示例9: __init__

 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)
开发者ID:harunrashidanver,项目名称:dictionary-indicator-applet,代码行数:11,代码来源:DictionaryIndicator.py

示例10: pieceOfLyric

 def pieceOfLyric(self, video, numWord): 
     """ Para la que la Api de MusixMatch funcione solo neceisita un trozo de la letra con palabras
         relevantes, por ello se usa pieceLyric. Que se queda con las palabras mayores de tres letras"""
     
     lyric = self.scanOCR(video) 
     searchLyric = lyric[100:]
     searchLyriclist = searchLyric.split()
     listLyric = ""
     lenLyriclist = len(searchLyriclist)
     count = 0
     countlen = 0
     dictionary=PyDictionary()
     while (count <= numWord) and (countlen < lenLyriclist):
         # El numero de letras por palabra es mayor de dos
         if len(searchLyriclist[countlen]) > 2:
             if searchLyriclist[countlen] not in listLyric:
                 #Busca si la palabra existe en google
                 if dictionary.googlemeaning(searchLyriclist[countlen]):
                     listLyric = listLyric + " " + searchLyriclist[countlen]
                     count += 1
         countlen += 1
     return listLyric
开发者ID:vtinoco,项目名称:TFM,代码行数:22,代码来源:karaokeSearch.py

示例11: Synsets

class Synsets(object):
    def __init__(self, synsets={}): # synsets are hashmap of (string:Word objects) pair
        self.dictionary = PyDictionary()
        self.synsets = synsets

    def find(self, word):
        try:
            return map(str, self.dictionary.synonym(word))
        except:
            if word not in synsets:
                return []
            return synsets[word].synonyms

    def add(self, synsets):
        self.synsets.update(synsets)
开发者ID:bsoe003,项目名称:notefy_rest_api,代码行数:15,代码来源:synonyms.py

示例12: __init__

	def __init__(self):
		self.lambda_comp_tree=AVLTree()
		self.index_tree=BinaryTree()
		self.word_list=[]
		self.word_dict={}
		self.index_dict={}
		self.index_list=[]
		self.lambda_expression=[]
		self.lambda_composition=""
		self.graph_tensor_neuron_network_intrinsic_merit=1.0
		self.entropy=10000000000.0
		self.conceptnet=ConceptNet5Client()
		#self.Similarity="ConceptNet"
		self.Similarity="WordNet"
		self.ClosedPaths=True
		self.dictionary=PyDictionary()
开发者ID:shrinivaasanka,项目名称:asfer-github-code,代码行数:16,代码来源:RecursiveLambdaFunctionGrowth.py

示例13: Meaning

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")
开发者ID:SDES-IITB-course-archive,项目名称:SDES_Readout,代码行数:21,代码来源:Meaning.py

示例14: output

def output(request):
    # Validation of form
    if request.method == "POST":
        # Validation of request
        if 'inputURL' in request.POST:
            # Validation of image url
            imageURL = request.POST.get('inputURL')
            image_output = imageURL
            indexOfDot = imageURL.rfind(".")
            if indexOfDot == -1:
                return fail(request) # not an image URL
            indexOfDot += 1
            extension = imageURL[indexOfDot:]
            if extension != 'jpg' and extension != 'jpeg' and extension != 'png':
                return fail(request) # not a valid image (jpg, jpeg, png)
                
            client_id = '8SkASX_SM8xc-fxMF4SdpzS_b9uew8yG0UrQp0y6'
            secret_id = 'EXkfCNxXeiHtnpsxn9Njui_yUpCuvcSAXzfSYjwN'
                
            clarifai_api = ClarifaiApi(client_id, secret_id) # assumes environment variables are set.
            return output(request, makes{image_output:'image_output', text_output:'text_output'})
                result = clarifai_api.tag_image_urls(imageURL)
            except ApiError:
                #return fail(request)
                
                messages.add_message(request, messages.INFO, "ApiError")
                return HttpResponseRedirect('makestory/fail.html')
            
            
            class_list = result['results'][0]['result']['tag']['classes']
            prob_list = result['results'][0]['result']['tag']['probs']
            
            class_str = ""
            for i in range(0, len(class_list)):
                class_str += class_list[i] + " " 
            
            # 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
            #P:prepositions, DET:articles, adverbs
            P = ["on","in","at","since","for","ago","before","to","past","to","until","by","in","at","on","under","below","over","above","into","from","of","on","at"]
            DET = ["the","a","one","some","few","a few","the few","some"]
            
            assignments = pos_tag(tokens) # tagset='universal' for ADJ, NOUN, etc.
            
            pos_tags = []
            pos_words = {}
            for tuple in assignments:
                word = tuple[0]
                pos = tuple[1]
                if pos in pos_words:
                    pos_words[pos].append(word)
                else:
                    pos_words[pos] = []
                pos_tags.append(pos)
                
                
            
            
            grammar = """
            S -> NP VP
            PP -> P NP
            NP -> Det N | Det N PP
            VP -> V NP | VP PP
            Det -> 'DT'
            """
            # N -> 'NN'
            # V -> 'VBZ'
            # P -> 'PP'
            
            
            # adverb is RB
            
#.........这里部分代码省略.........
开发者ID:cts5ws,项目名称:hackuva2016,代码行数:101,代码来源:.~c9_invoke_BYOsKe.py

示例15: print

for x in submission_titles:
    if 'egypt' in x.lower():
        if 'plane' in x.lower() or 'flight' in x.lower():
            print(x)


# However, this becomes tedious if we want to keep adding additional keywords such as 'aircraft'.  
# A better approach is to, for example, include synonyms for the word 'airplane'.  
# 
# We can do this using one of the above libraries but we could also use `PyDictionary`, `pip install PyDictionary`

# In[39]:

from PyDictionary import PyDictionary
dictionary=PyDictionary()


# In[40]:

print(dictionary.synonym('airplane'))


# In[41]:

plane_words = dictionary.synonym('airplane') + ['airplane', 'flight']


# In[42]:

for x in submission_titles:
开发者ID:mitzipp,项目名称:opensource_workshop,代码行数:30,代码来源:4_text_mining.py


注:本文中的PyDictionary.PyDictionary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。