question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DisambiguationError: perhaps a better response?

See original GitHub issue

For example:

    wikipedia.summary('recommendation')

gives the following error and terminates the program:

    290       may_refer_to = [li.a.get_text() for li in filtered_lis if li.a]
    291 
--> 292       raise DisambiguationError(self.title, may_refer_to)
    293 
    294     else:

DisambiguationError: "Recommendation" may refer to: 
norm (philosophy)
Recommender systems
European Union recommendation
W3C recommendation
letter of recommendation

Perhaps a better response, maybe in a JSON format, would help? without termination, and instead ask for further clarification?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
arcolifecommented, Mar 13, 2014

yeah well that could be one option. I was thinking:

try:
    page = wikipedia.page("Recommendation")
    print page.summary
except:
    topics = wikipedia.search("Recommendation")
    print "Recommendation may refer to: "
    for i, topic in enumerate(topics):
        print i, topic
    choice = int(raw_input("Enter a choice: "))
    assert choice in xrange(len(topics))
    print wikipedia.summary(topics[choice])

this would help counter the error and give the user a chance to select an input at run-time instead.

Sample output

Recommendation may refer to: 
0 Recommendation
1 Recommender system
2 World Wide Web Consortium
3 Life imprisonment in England and Wales
4 Web standards
5 Recommendation (European Union)
6 List of ITU-T V-Series Recommendations
7 Recommendation letter
8 Driver Steering Recommendation
9 Rec. 709
Enter a choice:
6reactions
goldsmithcommented, Mar 13, 2014

the DisambiguationError object does store a list of the suggested article titles:

try:
  page = wikipedia.page("Recommendation")
except wikipedia.exceptions.DisambiguationError as e:
  print e.options

# [u'norm (philosophy)', u'Recommender systems', u'European Union recommendation', u'W3C recommendation', u'letter of recommendation']
Read more comments on GitHub >

github_iconTop Results From Across the Web

Wikipedia disambiguation error - python - Stack Overflow
A less-good but perhaps easier fix would be for you to simply try/except the DisambiguationError and try again.
Read more >
Spurious Disambiguation Error Detection - Stefano Zacchiroli
Abstract. The disambiguation approach to the input of formulae en- ables the user to type correct formulae in a terse syntax close to...
Read more >
DragonComputer/Lobby - Gitter
DisambiguationError : Today I'm only an user of Dragonfire, you would have some idea about exeptions handling in Dragonfire. Maybe you can let...
Read more >
Wikipedia API for Python. In this tutorial let us understand the…
But sometimes be careful, you might run into a DisambiguationError . Which means the same words with different meanings. For example, the word...
Read more >
Python page Examples, wikipedia.page Python Examples
DisambiguationError as e: for article in e.options: try: article ... page = wikipedia.page(error.options[0]) response['title'] = page.title response['url'] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found