當前位置: 首頁>>代碼示例>>Python>>正文


Python wikipedia.summary方法代碼示例

本文整理匯總了Python中wikipedia.summary方法的典型用法代碼示例。如果您正苦於以下問題:Python wikipedia.summary方法的具體用法?Python wikipedia.summary怎麽用?Python wikipedia.summary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wikipedia的用法示例。


在下文中一共展示了wikipedia.summary方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def __call__(self, jarvis, s):
        k = s.split(' ', 1)
        if len(k) == 1:
            jarvis.say(
                "Do you mean:\n1. wiki search <subject>\n2. wiki summary <subject>\n3. wiki content <subject>")
        else:
            data = None
            if k[0] == "search":
                data = self.search(" ".join(k[1:]))
            elif k[0] == "summary":
                data = self.summary(" ".join(k[1:]))
            elif k[0] == "content":
                data = self.content(" ".join(k[1:]))
            else:
                jarvis.say("I don't know what you mean")
                return

            if isinstance(data, list):
                print("\nDid you mean one of these pages?\n")
                for d in range(len(data)):
                    print(str(d + 1) + ": " + data[d])
            else:
                print("\n" + data) 
開發者ID:sukeesh,項目名稱:Jarvis,代碼行數:25,代碼來源:wiki.py

示例2: wiki

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def wiki(self, ctx, *, query):
        '''Search up something on wikipedia'''
        em = discord.Embed(title=str(query))
        em.set_footer(text='Powered by wikipedia.org')
        try:
            result = wikipedia.summary(query)
            if len(result) > 2000:
                em.color = discord.Color.red()
                em.description = f"Result is too long. View the website [here](https://wikipedia.org/wiki/{query.replace(' ', '_')}), or just google the subject."
                return await ctx.send(embed=em)
            em.color = discord.Color.green()
            em.description = result
            await ctx.send(embed=em)
        except wikipedia.exceptions.DisambiguationError as e:
            em.color = discord.Color.red()
            options = '\n'.join(e.options)
            em.description = f"**Options:**\n\n{options}"
            await ctx.send(embed=em)
        except wikipedia.exceptions.PageError:
            em.color = discord.Color.red()
            em.description = 'Error: Page not found.'
            await ctx.send(embed=em) 
開發者ID:cree-py,項目名稱:RemixBot,代碼行數:24,代碼來源:utility.py

示例3: wiki

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def wiki(bot, update, args):
	try:
		topic = ""
		for arg in args:
			topic += arg + " "
		summary = wikipedia.summary(topic, sentences = 30)
		page = wikipedia.page(topic)
		extra = "\nFor more details visit " + page.url
		summary += extra
		bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING)
		bot.sendMessage(chat_id = update.message.chat_id, parse_mode=ParseMode.HTML, text = summary)

	except wikipedia.exceptions.DisambiguationError as e:
		error = "Please be more specific with your search query as there are a couple of other options meaning the same."
		for options in e.options:
			error += options.decode("utf-8","ignore")+'\n'
		bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING)
		bot.sendMessage(chat_id = update.message.chat_id, text = error)

	except wikipedia.exceptions.PageError:
		error = "No messages could be found with the topic you entered!"
		bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING)
		bot.sendMessage(chat_id = update.message.chat_id, text = error) 
開發者ID:rahulkumaran,項目名稱:Utlyz-CLI,代碼行數:25,代碼來源:app.py

示例4: get_short_answer

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def get_short_answer(self, query):
		logging.info("searching in wolfram: {}".format(query))

		try:
			wolfram_res = self.wolfram_client.query(query)
			logging.info("wolfram res: {}".format(wolfram_res))

			return next(wolfram_res.results).text
		except:
			# use wikipedia as failover
			wikiepedia_res = wikipedia.summary(query, sentences=1)
			logging.info("wikipedia res: {}".format(wikiepedia_res))
			if wikiepedia_res:
				return wikiepedia_res

			return self.NOT_FOUND_MSG 
開發者ID:plutov,項目名稱:bot,代碼行數:18,代碼來源:dataprovider.py

示例5: summary

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def summary(self, query, sentences=0, chars=0):
        """Returns a plain text summary from the query's page."""
        try:
            return wikipedia.summary(query, sentences, chars)
        except wikipedia.exceptions.PageError:
            return "No page matches, try another item."
        except wikipedia.exceptions.DisambiguationError as error:
            return error.options[:5] 
開發者ID:sukeesh,項目名稱:Jarvis,代碼行數:10,代碼來源:wiki.py

示例6: wikipediaLookUp

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def wikipediaLookUp(a_string,num_sentences):
	print a_string
	pattern = re.compile('([^\s\w]|_)+')
	b_string = re.sub(pattern, '', a_string)
	phrase=b_string
	print phrase
	pattern = re.compile("\\b(lot|lots|a|an|who|can|you|what|is|info|somethings|whats|have|i|something|to|know|like|Id|information|about|tell|me)\\W", re.I)
	phrase_noise_removed = [pattern.sub("", phrase)] 
	print phrase_noise_removed[0]
	a = wikipedia.search(phrase_noise_removed[0])
	print a[0]
	the_summary = (wikipedia.summary(a[0], sentences=num_sentences))
	print the_summary
	return the_summary 
開發者ID:schollz,項目名稱:rpi_ai,代碼行數:16,代碼來源:temporal_lobe.py

示例7: wiki

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def wiki(celestial_object):
    ans = celestial_object
    cwd = os.getcwd()
    with open(os.path.join(cwd, 'display_info.yml'), 'r') as stream:
        all_display_statistics = load(stream, Loader=SafeLoader)

    req_statistics = all_display_statistics.get(ans, {})

    if ans in ["spiral", "elliptical"]:
        print("--------------------------------------------------------")
        print("Classified Celestial Object is {} Galaxy : ".format(ans.capitalize()))
        print("-------------------------------------------------------- \n")
        # print(wikipedia.summary("Spiral Galaxy", sentences=2))
        print(wikipedia.WikipediaPage(title='{} galaxy'.format(ans)).summary)
    elif ans in ['mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune']:
        print("--------------------------------------------------------")
        print("Classified Celestial Object is {} Planet : ".format(ans.capitalize()))
        print("-------------------------------------------------------- \n")
        statistics = "\n".join(['-- {}: {}'.format(parameter, value) for parameter, value in req_statistics.items()])
        print("{}\n\n".format(statistics))
        # print(wikipedia.summary("Mercury (planet)", sentences=2))
        print(wikipedia.WikipediaPage(title='{} (planet)'.format(ans)).summary)
    elif ans == 'moon':
        print("--------------------------------------------------------")
        print("Classified Celestial Object is the {} : ".format(ans.capitalize()))
        print("-------------------------------------------------------- \n")
        statistics = "\n".join(['-- {}: {}'.format(parameter, value) for parameter, value in req_statistics.items()])
        print("{}\n\n".format(statistics))
        print(wikipedia.WikipediaPage(title='{}'.format(ans)).summary)
    return " " 
開發者ID:ritwik12,項目名稱:Celestial-bodies-detection,代碼行數:32,代碼來源:label_image.py

示例8: search

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def search(self, search_term):
        summary = wiki.summary(search_term, sentences = 7)
        summary = re.sub(r"\([^)]*\)", "", summary)

        return tokenize.sent_tokenize(summary) 
開發者ID:crhenr,項目名稱:youtube-video-maker,代碼行數:7,代碼來源:searchrobot.py

示例9: help

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def help(bot, update):
	bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING)
	bot.sendMessage(chat_id = update.message.chat_id, text = '''
		The following are the avaiable commands with me!\n
		/news				To get news bulletins
		/lyrics <name_of_song>		To get lyrics of songs
		/wiki <topic>			To get wikipedia summary on a given topic
		/fb <username> <password>	To get certain facebook updates
	''') 
開發者ID:rahulkumaran,項目名稱:Utlyz-CLI,代碼行數:11,代碼來源:app.py

示例10: _

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def _(event):
    if event.fwd_from:
        return
    await event.edit("Processing ...")
    input_str = event.pattern_match.group(1)
    result = wikipedia.summary(input_str)
    await event.edit("**Search**: {} \n\n **Result**: \n\n {}".format(input_str, result)) 
開發者ID:mkaraniya,項目名稱:BotHub,代碼行數:9,代碼來源:wikipedia.py

示例11: who_is

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def who_is(query, session_id="general"):
    try:
        return wikipedia.summary(query)
    except requests.exceptions.SSLError:
        return "Sorry I could not search online due to SSL error"
    except:
        pass
    for new_query in wikipedia.search(query):
        try:
            return wikipedia.summary(new_query)
        except:
            pass
    return "Sorry I could not find any data related to '%s'" % query 
開發者ID:ahmadfaizalbh,項目名稱:Microsoft-chatbot,代碼行數:15,代碼來源:views.py

示例12: define_subject

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def define_subject(speech_text):
    words_of_message = speech_text.split()
    words_of_message.remove('define')
    cleaned_message = ' '.join(words_of_message).rstrip()
    if len(cleaned_message) == 0:
        msg = 'define requires subject words'
        print msg
        tts(msg)
        return

    try:
        wiki_data = wikipedia.summary(cleaned_message, sentences=5)

        regEx = re.compile(r'([^\(]*)\([^\)]*\) *(.*)')
        m = regEx.match(wiki_data)
        while m:
            wiki_data = m.group(1) + m.group(2)
            m = regEx.match(wiki_data)

        wiki_data = wiki_data.replace("'", "")
        tts(wiki_data)
    except wikipedia.exceptions.DisambiguationError as e:
        tts('Can you please be more specific? You may choose something' +
            'from the following.')
        print("Can you please be more specific? You may choose something" +
              "from the following; {0}".format(e)) 
開發者ID:Melissa-AI,項目名稱:Melissa-Core,代碼行數:28,代碼來源:define_subject.py

示例13: shorten_news

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def shorten_news(url, n = 5):
    from bs4 import BeautifulSoup as bs
    from summarizer import FrequencySummarizer as fs
    response = _req.get(url)
    if not response.ok:
        return False
    page = response.content
    soup = bs(page, "lxml")
    summary = fs().summarize("\n".join([x.text for x in soup.findAll("p") if len(x.text.split()) > 1]), n)
    summary.insert(0, soup.title.text)
    return ' '.join(summary) 
開發者ID:shaildeliwala,項目名稱:delbot,代碼行數:13,代碼來源:media_aggregator.py

示例14: get_gkg

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def get_gkg(query):
    try:
        s = _wk.summary(query, sentences = 5)
        for x in _findall("\(.*\)", s):
            s = s.replace(x, "")
        return s
    except _wk.DisambiguationError, e:
        return False 
開發者ID:shaildeliwala,項目名稱:delbot,代碼行數:10,代碼來源:media_aggregator.py

示例15: do_activate

# 需要導入模塊: import wikipedia [as 別名]
# 或者: from wikipedia import summary [as 別名]
def do_activate(self, args, argv):
        wikipedia.set_lang("de")
        print(wikipedia.summary(' '.join(args), sentences=2)) 
開發者ID:semicode-ltd,項目名稱:sarah,代碼行數:5,代碼來源:wiki.py


注:本文中的wikipedia.summary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。