本文整理汇总了Python中wikipedia.summary函数的典型用法代码示例。如果您正苦于以下问题:Python summary函数的具体用法?Python summary怎么用?Python summary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了summary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_wiki_search
def make_wiki_search(sent):
global anna_answered
sent += " fixforsearch"
search = 0
count = 0
words = sent.split()
countin = len(sent.split())
for i in range(0, countin):
if (words[i] == "search") or (words[i] == "search?"):
search = 1
break
count = count + 1
if (search == 1) and (words[count + 1] != "fixforsearch"):
newword = words[count + 1]
print ("\n")
print (wikipedia.summary(newword))
elif (search == 1):
print("OK, but what should I search?")
newword = input_type()
print ("\n")
print (wikipedia.summary(newword))
else:
return;
print("\n\n",AI_speaking,"Hope you got the answer")
anna_answered=True
return;
示例2: info
def info(topic):
response = {}
response["type"] = "wiki"
try:
page = wikipedia.page(topic)
response['title'] = page.title
response['url'] = page.url
response['content'] = wikipedia.summary(page.title,sentences = 5)
if len(response['content']) < 200:
response['content'] = wikipedia.summary(page.title,sentences = 10)
except Exception as error:
ename = type(error).__name__
if ename == 'DisambiguationError':
page = wikipedia.page(error.options[0])
response['title'] = page.title
response['url'] = page.url
response['content'] = wikipedia.summary(page.title,sentences = 2)
if len(response['content']) < 200:
response['content'] = wikipedia.summary(page.title,sentences = 10)
elif ename == 'HTTPTimeoutError':
response['type'] = "error"
response['error'] = "I couldn't reach wikipedia"
elif ename == 'PageError':
response['type'] = "error"
response['error'] = "I couldn't find anything on wikipedia"
else:
response['type'] = "error"
response['error'] = "Unknown error occured while reaching wikipedia"
return response
示例3: add_word
def add_word(word):
print "[+] Current search:", word, " [", cont + 1, "/", MAX_CRAWL, "]"
try:
## Fetch summary
summary = wikipedia.summary(word)
except wikipedia.exceptions.PageError as e:
e.message
if len(WORDS) == 0:
print "[!]"
except wikipedia.exceptions.DisambiguationError as e:
## Choose a suggestion that explicitly has the word in it. If none, choose first suggestion
try:
suggestion = next(sug for sug in e.options if word.lower() in sug.lower())
except StopIteration:
suggestion = e.options[0]
print "[!] Ambiguous term, using:", suggestion
# print e.options
summary = wikipedia.summary(suggestion)
## Append term and summary
WORDS.append(word)
SUMMARIES.append(summary)
print " Summary fetched."
print SUMMARIES[-1]
print "\n"
示例4: inf
def inf(d, s):
wikipedia.summary("Wikipedia")
wikipedia.set_lang("ru")
types = ['museum', 'park', 'church', 'zoo', 'train_station', 'stadium']
def param(t):
content = urlopen(
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?language=ru&location=' + str(d) + ',' + str(
s) + '&rankby=distance&types=' + t + '&key=' + apikey).read()
c = json.loads(content.decode("utf-8"))
c = c.get('results')
if len(c) != 0:
c = c[0].get('name')
# print(c)
m = wikipedia.search(c, results=5, suggestion=False)
# print(m[0])
if len(m) != 0:
textsong = wikipedia.summary(m, sentences=5, chars=1)
if textsong != '':
return textsong
#print(textsong)
# if len(wikipedia.search(c)) != 0:
# st = wikipedia.page(c)
# if st.content
# print(st.content)
for type in types: #i in range(6):
temp = param(type)
if temp:
return temp
示例5: make_wiki_search
def make_wiki_search(sent):
global anna_answered
network=is_connected()
if network==1:
sent += " fixforsearch"
search = 0
count = 0
words = sent.split()
countin = len(sent.split())
for i in range(0, countin):
if (words[i] == "search") or (words[i] == "search?"):
search = 1
break
count = count + 1
if (search == 1) and (words[count + 1] != "fixforsearch"):
newword = words[count + 1]
print ("\n")
print(AI_speaking,wikipedia.summary(newword))
elif (search == 1):
audio_output("OK, but what should I search?")
newword = input_type()
print ("\n")
print(AI_speaking,wikipedia.summary(newword))
else:
return;
print("\n\n",)
audio_output("Hope you got the answer")
anna_answered=True
return;
elif network==0:
audio_output("Sorry I can't search anything now :/ I am not connected.")
anna_answered=True
示例6: command_wiki
def command_wiki(word):
'''Post the wikipedia definition for a word'''
definition = ""
try:
definition = wikipedia.summary(word, sentences=2)
if len(definition) > 220:
definition = wikipedia.summary(word, sentences=1)
if len(definition) > 200:
send_message(CHAN, definition[:197] + "...")
else:
send_message(CHAN, definition)
elif len(definition) < 30:
definition = wikipedia.summary(word, sentences=3)
if len(definition) > 200:
send_message(CHAN, definition[:197] + "...")
else:
send_message(CHAN, definition)
else:
send_message(CHAN, definition)
except wikipedia.exceptions.DisambiguationError as e:
send_message(CHAN, "Disambiguation: 1. " + e.options[0] + " 2. " + e.options[1] + " ...")
except wikipedia.exceptions.PageError as e:
send_message(CHAN, "Page error. Please try another word.")
示例7: skwiki
def skwiki(titlequery):
log.info("in skwiki")
log.info(titlequery)
try:
return wikipedia.summary(titlequery, sentences=2). \
encode("ascii", "ignore")
except wikipedia.exceptions.DisambiguationError as e:
return wikipedia.summary(e.options[0], sentences=2). \
encode("ascii", "ignore")
示例8: useCommandLineInput
def useCommandLineInput():
while True:
print("\nwhat would you like to search?")
toSearch = raw_input("enter here: ")
if (toSearch == "q"):
break
try:
print wikipedia.summary(toSearch, sentences = 2)
except wikipedia.exceptions.DisambiguationError:
print "there was an error!"
示例9: whoIs
def whoIs(query,sessionID="general"):
try:
return wikipedia.summary(query)
except:
for newquery in wikipedia.search(query):
try:
return wikipedia.summary(newquery)
except:
pass
return "I don't know about "+query
示例10: send_wiki_info
def send_wiki_info(who, text):
answ=" ".join(text)
if(answ[-1] == "?"): answ = answ[:-1]
wikipedia.set_lang("ru")
try:
resp=wikipedia.summary(answ, sentences=6, chars=1, auto_suggest=False, redirect=True)
except wikipedia.exceptions.DisambiguationError as error:
resp=wikipedia.summary(error.options[0], sentences=6, chars=1, auto_suggest=False, redirect=True)
except wikipedia.exceptions.WikipediaException:
resp=wikipedia.summary(answ, sentences=6, chars=0, auto_suggest=True, redirect=True)
bot.messages.send(peer_id=who, random_id=random.randint(0, 200000),message=resp)
示例11: get_random_articles_v2
def get_random_articles_v2():
"""Retrieves random articles until the user types 'stop' """
ans = input('Press enter to continue or stop to stop: ')
while ans != 'stop':
try:
print(wikipedia.summary(wikipedia.random()))
print()
ans = input('Press enter to continue or stop to stop: ')
except wikipedia.exceptions.DisambiguationError:
print(wikipedia.summary(wikipedia.random()))
print()
ans = input('Press enter to continue or stop to stop: ')
示例12: downloadArticle
def downloadArticle(self, article_title, data_path):
output_file = os.path.join(data_path, '{:}.json'.format(article_title))
if os.path.isfile( output_file ):
print(article_title + "exists, skipping")
return
try:
wikipedia.set_lang('simple')
summary = wikipedia.summary(article_title, sentences=1)
wikipedia.set_lang('en')
text = wikipedia.summary(article_title)
except wikipedia.exceptions.PageError, e:
return
示例13: result
def result(message):
wikipedia.set_lang("en")
#here we get message from user
ij = message.text
#here we say that ij is string
string = ij
#here i`ll say for python "Don`t read fucking command /wiki, and read all latter from 6 to 99 "
tj = string[6:99]
#here is stupid debug. I`m not smart and i send result of wikipedia.summary to console
print(wikipedia.summary(tj))
#here bot send to user result of this shity magic.
bot.reply_to(message,wikipedia.summary(tj))
示例14: getWiki
def getWiki(activity):
pattern = re.compile("\\b(of|the|in|for|at|check|find|how|how\'s|is|tell|me|check|out|about|wiki|wikipedia|summarize)\\W", re.I)
string = re.sub(pattern, "", activity)
if "summarize" in activity or "summary" in activity:
result = wikipedia.summary(string[len('summarize'):], sentences = 2)
elif "wiki" in activity or "wikipedia" in activity:
result = wikipedia.summary(activity[len('wiki'):])
else:
try:
result = wikipedia.search(string,results=10,suggestion=False)
except Exception, e:
result = wikipedia.search(string,results=10,suggestion=True)
示例15: OnEnter
def OnEnter(self, event):
input = self.txt.GetValue()
input = input.lower()
try:
#wolframalpha
app_id = "YOUR APP ID"
client = wolframalpha.Client(app_id)
res = client.query(input)
answer = next(res.results).text
print answer
except:
#wikipedia
print wikipedia.summary(input)