Skip to content

Commit

Permalink
Merge "solve_disambiguation.py: Do not suggest duplicate alternatives"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jul 16, 2016
2 parents a8c8997 + fb1161c commit 0af65f1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions scripts/solve_disambiguation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# (C) Daniel Herding, 2004
# (C) Andre Engels, 2003-2004
# (C) WikiWichtel, 2004
# (C) Pywikibot team, 2003-2015
# (C) Pywikibot team, 2003-2016
#
# Distributed under the terms of the MIT license.
#
Expand Down Expand Up @@ -651,9 +651,16 @@ def checkContents(self, text):
return None

def makeAlternativesUnique(self):
"""Remove duplicate entries stable."""
unique = set(self.alternatives)
self.alternatives = [alt for alt in self.alternatives if alt in unique]
"""Remove duplicate items from self.alternatives.
Preserve the order of alternatives.
@rtype: None
"""
seen = set()
self.alternatives = [
i for i in self.alternatives if i not in seen and not seen.add(i)
]

def listAlternatives(self):
"""Show a list of alternatives."""
Expand Down Expand Up @@ -954,7 +961,7 @@ def treat(self, refPage, disambPage):
def findAlternatives(self, disambPage):
"""Extend self.alternatives using correctcap of disambPage.linkedPages.
@param disambPage: the disabiguation page
@param disambPage: the disambiguation page
@type disambPage: pywikibot.Page
@return: True if everything goes fine, False otherwise
@rtype: bool
Expand Down Expand Up @@ -1002,6 +1009,7 @@ def findAlternatives(self, disambPage):
u"The specified page is not a redirect. Skipping.")
return False
elif self.getAlternatives:
# not disambPage.isRedirectPage() or self.primary
try:
if self.primary:
try:
Expand Down

0 comments on commit 0af65f1

Please sign in to comment.