605f52
diff -ru mythes-en-3.0/wn2ooo/wn2ooo.py mythes-en-3.0.fixed/wn2ooo/wn2ooo.py
605f52
--- mythes-en-3.0/wn2ooo/wn2ooo.py	2005-07-23 23:21:20.000000000 +0100
605f52
+++ mythes-en-3.0.fixed/wn2ooo/wn2ooo.py	2018-07-30 14:46:52.695201526 +0100
605f52
@@ -65,7 +65,7 @@
605f52
 				entry = getRelatedTerms(u, HYPERNYM, '')
605f52
 			try:
605f52
 				listpos = l.index(entry)
605f52
-			except ValueError, e:
605f52
+			except ValueError as e:
605f52
 				l.append(entry)
605f52
 	return str.join("|", l)
605f52
 	
605f52
@@ -74,12 +74,12 @@
605f52
 	for word in words:
605f52
 		l = []
605f52
 		if c % 100 == 0:
605f52
-			print >> sys.stderr, "Working on word %d" % c
605f52
+			print("Working on word %d" % c, file=sys.stderr)
605f52
 		for pos in [ADJ, N, V, ADV]:
605f52
 			try:
605f52
 				for s in pos[word].getSenses():
605f52
 					l.append(s)
605f52
-			except KeyError, e:
605f52
+			except KeyError as e:
605f52
 				#print >> sys.stderr, e
605f52
 				continue
605f52
 		syn_count = 0
605f52
@@ -118,7 +118,7 @@
605f52
 					syn_lines = "%s%s" % (syn_lines, more_generic_terms)
605f52
 				syn_count = syn_count + 1
605f52
 		if syn_count > 0:
605f52
-			print "%s|%d\n%s" % (word, syn_count, syn_lines)
605f52
+			print("%s|%d\n%s" % (word, syn_count, syn_lines))
605f52
 		c = c + 1
605f52
 	return
605f52
 
605f52
@@ -132,40 +132,38 @@
605f52
 	return s
605f52
 
605f52
 def main():
605f52
-	print "ISO8859-1"
605f52
+	print("ISO8859-1")
605f52
 
605f52
 	words = {}
605f52
 	dic = Dictionary(ADJECTIVE, "adj")
605f52
-	for w in dic.keys():
605f52
+	for w in list(dic.keys()):
605f52
 		words[w] = None
605f52
 
605f52
 	dic = Dictionary(NOUN, "noun")
605f52
-	for w in dic.keys():
605f52
+	for w in list(dic.keys()):
605f52
 		words[w] = None
605f52
 	
605f52
 	dic = Dictionary(VERB, "verb")
605f52
-	for w in dic.keys():
605f52
+	for w in list(dic.keys()):
605f52
 		words[w] = None
605f52
 
605f52
 	dic = Dictionary(ADVERB, "adv")
605f52
-	for w in dic.keys():
605f52
+	for w in list(dic.keys()):
605f52
 		words[w] = None
605f52
 
605f52
-	words = words.keys()
605f52
+	words = list(words.keys())
605f52
 	# tests:
605f52
 	#words = ['dog', 'house', 'nullipara']
605f52
 	#words = ['absent', 'whistle stop']
605f52
 	#words = ['war']
605f52
-	print >>sys.stderr, "Dictionaries contain %d words" % len(words)
605f52
-	print >>sys.stderr, "Sorting..."
605f52
-	words.sort(mycompare)
605f52
+	print("Dictionaries contain %d words" % len(words), file=sys.stderr)
605f52
+	print("Sorting...", file=sys.stderr)
605f52
+	words = sorted(words, key=mycompare)
605f52
 	printSynsForWords(words)
605f52
 	return
605f52
 
605f52
-def mycompare(a, b):
605f52
+def mycompare(elem):
605f52
 	# stupid hack to make sure the list is sorted like Kevin's original list:
605f52
-	a = a.replace(" ", "Z")
605f52
-	b = b.replace(" ", "Z")
605f52
-	return cmp(a, b)
605f52
+	return elem.replace(" ", "Z")
605f52
 
605f52
 main()
605f52
diff -ru mythes-en-3.0/wn2ooo/wordnet.py mythes-en-3.0.fixed/wn2ooo/wordnet.py
605f52
--- mythes-en-3.0/wn2ooo/wordnet.py	2005-07-23 23:21:16.000000000 +0100
605f52
+++ mythes-en-3.0.fixed/wn2ooo/wordnet.py	2018-07-30 14:46:52.695201526 +0100
605f52
@@ -44,7 +44,6 @@
605f52
 import string
605f52
 import os
605f52
 from os import environ
605f52
-from types import IntType, ListType, StringType, TupleType
605f52
 
605f52
 
605f52
 #
605f52
@@ -212,15 +211,15 @@
605f52
     
605f52
     def __init__(self, line):
605f52
         """Initialize the word from a line of a WN POS file."""
605f52
-	tokens = string.split(line)
605f52
-	ints = map(int, tokens[int(tokens[3]) + 4:])
605f52
-	self.form = string.replace(tokens[0], '_', ' ')
605f52
+        tokens = line.split()
605f52
+        ints = list(map(int, tokens[int(tokens[3]) + 4:]))
605f52
+        self.form = tokens[0].replace('_', ' ')
605f52
         "Orthographic representation of the word."
605f52
-	self.pos = _normalizePOS(tokens[1])
605f52
+        self.pos = _normalizePOS(tokens[1])
605f52
         "Part of speech.  One of NOUN, VERB, ADJECTIVE, ADVERB."
605f52
-	self.taggedSenseCount = ints[1]
605f52
+        self.taggedSenseCount = ints[1]
605f52
         "Number of senses that are tagged."
605f52
-	self._synsetOffsets = ints[2:ints[0]+2]
605f52
+        self._synsetOffsets = ints[2:ints[0]+2]
605f52
     
605f52
     def getPointers(self, pointerType=None):
605f52
         """Pointers connect senses and synsets, not words.
605f52
@@ -233,17 +232,17 @@
605f52
         raise self.getPointers.__doc__
605f52
 
605f52
     def getSenses(self):
605f52
-	"""Return a sequence of senses.
605f52
-	
605f52
-	>>> N['dog'].getSenses()
605f52
-	('dog' in {noun: dog, domestic dog, Canis familiaris}, 'dog' in {noun: frump, dog}, 'dog' in {noun: dog}, 'dog' in {noun: cad, bounder, blackguard, dog, hound, heel}, 'dog' in {noun: frank, frankfurter, hotdog, hot dog, dog, wiener, wienerwurst, weenie}, 'dog' in {noun: pawl, detent, click, dog}, 'dog' in {noun: andiron, firedog, dog, dog-iron})
605f52
-	"""
605f52
-	if not hasattr(self, '_senses'):
605f52
-	    def getSense(offset, pos=self.pos, form=self.form):
605f52
-		return getSynset(pos, offset)[form]
605f52
-	    self._senses = tuple(map(getSense, self._synsetOffsets))
605f52
-	    del self._synsetOffsets
605f52
-	return self._senses
605f52
+        """Return a sequence of senses.
605f52
+        
605f52
+        >>> N['dog'].getSenses()
605f52
+        ('dog' in {noun: dog, domestic dog, Canis familiaris}, 'dog' in {noun: frump, dog}, 'dog' in {noun: dog}, 'dog' in {noun: cad, bounder, blackguard, dog, hound, heel}, 'dog' in {noun: frank, frankfurter, hotdog, hot dog, dog, wiener, wienerwurst, weenie}, 'dog' in {noun: pawl, detent, click, dog}, 'dog' in {noun: andiron, firedog, dog, dog-iron})
605f52
+        """
605f52
+        if not hasattr(self, '_senses'):
605f52
+            def getSense(offset, pos=self.pos, form=self.form):
605f52
+                return getSynset(pos, offset)[form]
605f52
+            self._senses = tuple(map(getSense, self._synsetOffsets))
605f52
+            del self._synsetOffsets
605f52
+        return self._senses
605f52
 
605f52
     # Deprecated.  Present for backwards compatability.
605f52
     def senses(self):
605f52
@@ -255,70 +254,70 @@
605f52
         return self.getSense()
605f52
     
605f52
     def isTagged(self):
605f52
-	"""Return 1 if any sense is tagged.
605f52
-	
605f52
-	>>> N['dog'].isTagged()
605f52
-	1
605f52
-	"""
605f52
-	return self.taggedSenseCount > 0
605f52
+        """Return 1 if any sense is tagged.
605f52
+        
605f52
+        >>> N['dog'].isTagged()
605f52
+        1
605f52
+        """
605f52
+        return self.taggedSenseCount > 0
605f52
     
605f52
     def getAdjectivePositions(self):
605f52
-	"""Return a sequence of adjective positions that this word can
605f52
-	appear in.  These are elements of ADJECTIVE_POSITIONS.
605f52
-	
605f52
-	>>> ADJ['clear'].getAdjectivePositions()
605f52
-	[None, 'predicative']
605f52
-	"""
605f52
-	positions = {}
605f52
-	for sense in self.getSenses():
605f52
-	    positions[sense.position] = 1
605f52
-	return positions.keys()
605f52
+        """Return a sequence of adjective positions that this word can
605f52
+        appear in.  These are elements of ADJECTIVE_POSITIONS.
605f52
+        
605f52
+        >>> ADJ['clear'].getAdjectivePositions()
605f52
+        [None, 'predicative']
605f52
+        """
605f52
+        positions = {}
605f52
+        for sense in self.getSenses():
605f52
+            positions[sense.position] = 1
605f52
+        return list(positions.keys())
605f52
 
605f52
     adjectivePositions = getAdjectivePositions # backwards compatability
605f52
     
605f52
     def __cmp__(self, other):
605f52
-	"""
605f52
-	>>> N['cat'] < N['dog']
605f52
-	1
605f52
-	>>> N['dog'] < V['dog']
605f52
-	1
605f52
-	"""
605f52
-	return _compareInstances(self, other, ('pos', 'form'))
605f52
+        """
605f52
+        >>> N['cat'] < N['dog']
605f52
+        1
605f52
+        >>> N['dog'] < V['dog']
605f52
+        1
605f52
+        """
605f52
+        return _compareInstances(self, other, ('pos', 'form'))
605f52
     
605f52
     def __str__(self):
605f52
-	"""Return a human-readable representation.
605f52
-	
605f52
-	>>> str(N['dog'])
605f52
-	'dog(n.)'
605f52
-	"""
605f52
-	abbrs = {NOUN: 'n.', VERB: 'v.', ADJECTIVE: 'adj.', ADVERB: 'adv.'}
605f52
-	return self.form + "(" + abbrs[self.pos] + ")"
605f52
+        """Return a human-readable representation.
605f52
+        
605f52
+        >>> str(N['dog'])
605f52
+        'dog(n.)'
605f52
+        """
605f52
+        abbrs = {NOUN: 'n.', VERB: 'v.', ADJECTIVE: 'adj.', ADVERB: 'adv.'}
605f52
+        return self.form + "(" + abbrs[self.pos] + ")"
605f52
     
605f52
     def __repr__(self):
605f52
-	"""If ReadableRepresentations is true, return a human-readable
605f52
-	representation, e.g. 'dog(n.)'.
605f52
-	
605f52
-	If ReadableRepresentations is false, return a machine-readable
605f52
-	representation, e.g. "getWord('dog', 'noun')".
605f52
-	"""
605f52
-	if ReadableRepresentations:
605f52
-	    return str(self)
605f52
-	return "getWord" + `(self.form, self.pos)`
605f52
-	
605f52
+        """If ReadableRepresentations is true, return a human-readable
605f52
+        representation, e.g. 'dog(n.)'.
605f52
+        
605f52
+        If ReadableRepresentations is false, return a machine-readable
605f52
+        representation, e.g. "getWord('dog', 'noun')".
605f52
+        """
605f52
+        if ReadableRepresentations:
605f52
+            return str(self)
605f52
+        return "getWord" + repr((self.form, self.pos))
605f52
+        
605f52
     #
605f52
     # Sequence protocol (a Word's elements are its Senses)
605f52
     #
605f52
-    def __nonzero__(self):
605f52
-	return 1
605f52
+    def __bool__(self):
605f52
+        return 1
605f52
     
605f52
     def __len__(self):
605f52
-	return len(self.getSenses())
605f52
+        return len(self.getSenses())
605f52
     
605f52
     def __getitem__(self, index):
605f52
-	return self.getSenses()[index]
605f52
+        return self.getSenses()[index]
605f52
     
605f52
     def __getslice__(self, i, j):
605f52
-	return self.getSenses()[i:j]
605f52
+        return self.getSenses()[i:j]
605f52
 
605f52
 
605f52
 class Synset:
605f52
@@ -356,157 +355,157 @@
605f52
     
605f52
     def __init__(self, pos, offset, line):
605f52
         "Initialize the synset from a line off a WN synset file."
605f52
-	self.pos = pos
605f52
+        self.pos = pos
605f52
         "part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB."
605f52
-	self.offset = offset
605f52
+        self.offset = offset
605f52
         """integer offset into the part-of-speech file.  Together
605f52
         with pos, this can be used as a unique id."""
605f52
-	tokens = string.split(line[:string.index(line, '|')])
605f52
-	self.ssType = tokens[2]
605f52
-	self.gloss = string.strip(line[string.index(line, '|') + 1:])
605f52
+        tokens = line[:line.index('|')].split()
605f52
+        self.ssType = tokens[2]
605f52
+        self.gloss = line[line.index('|') + 1:].strip()
605f52
         self.lexname = Lexname.lexnames[int(tokens[1])]
605f52
-	(self._senseTuples, remainder) = _partition(tokens[4:], 2, string.atoi(tokens[3], 16))
605f52
-	(self._pointerTuples, remainder) = _partition(remainder[1:], 4, int(remainder[0]))
605f52
-	if pos == VERB:
605f52
-	    (vfTuples, remainder) = _partition(remainder[1:], 3, int(remainder[0]))
605f52
-	    def extractVerbFrames(index, vfTuples):
605f52
-		return tuple(map(lambda t:string.atoi(t[1]), filter(lambda t,i=index:string.atoi(t[2],16) in (0, i), vfTuples)))
605f52
-	    senseVerbFrames = []
605f52
-	    for index in range(1, len(self._senseTuples) + 1):
605f52
-		senseVerbFrames.append(extractVerbFrames(index, vfTuples))
605f52
-	    self._senseVerbFrames = senseVerbFrames
605f52
-	    self.verbFrames = tuple(extractVerbFrames(None, vfTuples))
605f52
+        (self._senseTuples, remainder) = _partition(tokens[4:], 2, int(tokens[3], 16))
605f52
+        (self._pointerTuples, remainder) = _partition(remainder[1:], 4, int(remainder[0]))
605f52
+        if pos == VERB:
605f52
+            (vfTuples, remainder) = _partition(remainder[1:], 3, int(remainder[0]))
605f52
+            def extractVerbFrames(index, vfTuples):
605f52
+                return tuple([int(t[1]) for t in list(filter(lambda t,i=index:int(t[2],16) in (0, i), vfTuples))])
605f52
+            senseVerbFrames = []
605f52
+            for index in range(1, len(self._senseTuples) + 1):
605f52
+                senseVerbFrames.append(extractVerbFrames(index, vfTuples))
605f52
+            self._senseVerbFrames = senseVerbFrames
605f52
+            self.verbFrames = tuple(extractVerbFrames(None, vfTuples))
605f52
             """A sequence of integers that index into
605f52
             VERB_FRAME_STRINGS. These list the verb frames that any
605f52
             Sense in this synset participates in.  (See also
605f52
             Sense.verbFrames.) Defined only for verbs."""
605f52
     
605f52
     def getSenses(self):
605f52
-	"""Return a sequence of Senses.
605f52
-	
605f52
-	>>> N['dog'][0].getSenses()
605f52
-	('dog' in {noun: dog, domestic dog, Canis familiaris},)
605f52
-	"""
605f52
-	if not hasattr(self, '_senses'):
605f52
-	    def loadSense(senseTuple, verbFrames=None, synset=self):
605f52
-		return Sense(synset, senseTuple, verbFrames)
605f52
-	    if self.pos == VERB:
605f52
-		self._senses = tuple(map(loadSense, self._senseTuples, self._senseVerbFrames))
605f52
-		del self._senseVerbFrames
605f52
-	    else:
605f52
-		self._senses = tuple(map(loadSense, self._senseTuples))
605f52
-	    del self._senseTuples
605f52
-	return self._senses
605f52
+        """Return a sequence of Senses.
605f52
+        
605f52
+        >>> N['dog'][0].getSenses()
605f52
+        ('dog' in {noun: dog, domestic dog, Canis familiaris},)
605f52
+        """
605f52
+        if not hasattr(self, '_senses'):
605f52
+            def loadSense(senseTuple, verbFrames=None, synset=self):
605f52
+                return Sense(synset, senseTuple, verbFrames)
605f52
+            if self.pos == VERB:
605f52
+                self._senses = tuple(map(loadSense, self._senseTuples, self._senseVerbFrames))
605f52
+                del self._senseVerbFrames
605f52
+            else:
605f52
+                self._senses = tuple(map(loadSense, self._senseTuples))
605f52
+            del self._senseTuples
605f52
+        return self._senses
605f52
 
605f52
     senses = getSenses
605f52
 
605f52
     def getPointers(self, pointerType=None):
605f52
-	"""Return a sequence of Pointers.
605f52
+        """Return a sequence of Pointers.
605f52
 
605f52
         If pointerType is specified, only pointers of that type are
605f52
         returned.  In this case, pointerType should be an element of
605f52
         POINTER_TYPES.
605f52
-	
605f52
-	>>> N['dog'][0].getPointers()[:5]
605f52
-	(hypernym -> {noun: canine, canid}, member meronym -> {noun: Canis, genus Canis}, member meronym -> {noun: pack}, hyponym -> {noun: pooch, doggie, doggy, barker, bow-wow}, hyponym -> {noun: cur, mongrel, mutt})
605f52
-	>>> N['dog'][0].getPointers(HYPERNYM)
605f52
-	(hypernym -> {noun: canine, canid},)
605f52
-	"""
605f52
-	if not hasattr(self, '_pointers'):
605f52
-	    def loadPointer(tuple, synset=self):
605f52
-		return Pointer(synset.offset, tuple)
605f52
-	    self._pointers = tuple(map(loadPointer, self._pointerTuples))
605f52
-	    del self._pointerTuples
605f52
-	if pointerType == None:
605f52
-	    return self._pointers
605f52
-	else:
605f52
-	    _requirePointerType(pointerType)
605f52
-	    return filter(lambda pointer, type=pointerType: pointer.type == type, self._pointers)
605f52
+        
605f52
+        >>> N['dog'][0].getPointers()[:5]
605f52
+        (hypernym -> {noun: canine, canid}, member meronym -> {noun: Canis, genus Canis}, member meronym -> {noun: pack}, hyponym -> {noun: pooch, doggie, doggy, barker, bow-wow}, hyponym -> {noun: cur, mongrel, mutt})
605f52
+        >>> N['dog'][0].getPointers(HYPERNYM)
605f52
+        (hypernym -> {noun: canine, canid},)
605f52
+        """
605f52
+        if not hasattr(self, '_pointers'):
605f52
+            def loadPointer(tuple, synset=self):
605f52
+                return Pointer(synset.offset, tuple)
605f52
+            self._pointers = tuple(map(loadPointer, self._pointerTuples))
605f52
+            del self._pointerTuples
605f52
+        if pointerType == None:
605f52
+            return self._pointers
605f52
+        else:
605f52
+            _requirePointerType(pointerType)
605f52
+            return list(filter(lambda pointer, type=pointerType: pointer.type == type, self._pointers))
605f52
 
605f52
     pointers = getPointers # backwards compatability
605f52
     
605f52
     def getPointerTargets(self, pointerType=None):
605f52
-	"""Return a sequence of Senses or Synsets.
605f52
-	
605f52
+        """Return a sequence of Senses or Synsets.
605f52
+        
605f52
         If pointerType is specified, only targets of pointers of that
605f52
         type are returned.  In this case, pointerType should be an
605f52
         element of POINTER_TYPES.
605f52
-	
605f52
-	>>> N['dog'][0].getPointerTargets()[:5]
605f52
-	[{noun: canine, canid}, {noun: Canis, genus Canis}, {noun: pack}, {noun: pooch, doggie, doggy, barker, bow-wow}, {noun: cur, mongrel, mutt}]
605f52
-	>>> N['dog'][0].getPointerTargets(HYPERNYM)
605f52
-	[{noun: canine, canid}]
605f52
-	"""
605f52
-	return map(Pointer.target, self.getPointers(pointerType))
605f52
+        
605f52
+        >>> N['dog'][0].getPointerTargets()[:5]
605f52
+        [{noun: canine, canid}, {noun: Canis, genus Canis}, {noun: pack}, {noun: pooch, doggie, doggy, barker, bow-wow}, {noun: cur, mongrel, mutt}]
605f52
+        >>> N['dog'][0].getPointerTargets(HYPERNYM)
605f52
+        [{noun: canine, canid}]
605f52
+        """
605f52
+        return list(map(Pointer.target, self.getPointers(pointerType)))
605f52
 
605f52
     pointerTargets = getPointerTargets # backwards compatability
605f52
     
605f52
     def isTagged(self):
605f52
-	"""Return 1 if any sense is tagged.
605f52
-	
605f52
-	>>> N['dog'][0].isTagged()
605f52
-	1
605f52
-	>>> N['dog'][1].isTagged()
605f52
-	0
605f52
-	"""
605f52
-	return len(filter(Sense.isTagged, self.getSenses())) > 0
605f52
+        """Return 1 if any sense is tagged.
605f52
+        
605f52
+        >>> N['dog'][0].isTagged()
605f52
+        1
605f52
+        >>> N['dog'][1].isTagged()
605f52
+        0
605f52
+        """
605f52
+        return len(list(filter(Sense.isTagged, self.getSenses()))) > 0
605f52
     
605f52
     def __str__(self):
605f52
-	"""Return a human-readable representation.
605f52
-	
605f52
-	>>> str(N['dog'][0].synset)
605f52
-	'{noun: dog, domestic dog, Canis familiaris}'
605f52
-	"""
605f52
-	return "{" + self.pos + ": " + string.joinfields(map(lambda sense:sense.form, self.getSenses()), ", ") + "}"
605f52
+        """Return a human-readable representation.
605f52
+        
605f52
+        >>> str(N['dog'][0].synset)
605f52
+        '{noun: dog, domestic dog, Canis familiaris}'
605f52
+        """
605f52
+        return "{" + self.pos + ": " + string.joinfields([sense.form for sense in self.getSenses()], ", ") + "}"
605f52
     
605f52
     def __repr__(self):
605f52
-	"""If ReadableRepresentations is true, return a human-readable
605f52
-	representation, e.g. 'dog(n.)'.
605f52
-	
605f52
-	If ReadableRepresentations is false, return a machine-readable
605f52
-	representation, e.g. "getSynset(pos, 1234)".
605f52
-	"""
605f52
-	if ReadableRepresentations:
605f52
-	    return str(self)
605f52
-	return "getSynset" + `(self.pos, self.offset)`
605f52
+        """If ReadableRepresentations is true, return a human-readable
605f52
+        representation, e.g. 'dog(n.)'.
605f52
+        
605f52
+        If ReadableRepresentations is false, return a machine-readable
605f52
+        representation, e.g. "getSynset(pos, 1234)".
605f52
+        """
605f52
+        if ReadableRepresentations:
605f52
+            return str(self)
605f52
+        return "getSynset" + repr((self.pos, self.offset))
605f52
     
605f52
     def __cmp__(self, other):
605f52
-	return _compareInstances(self, other, ('pos', 'offset'))
605f52
+        return _compareInstances(self, other, ('pos', 'offset'))
605f52
     
605f52
     #
605f52
     # Sequence protocol (a Synset's elements are its senses).
605f52
     #
605f52
-    def __nonzero__(self):
605f52
-	return 1
605f52
+    def __bool__(self):
605f52
+        return 1
605f52
     
605f52
     def __len__(self):
605f52
-	"""
605f52
-	>>> len(N['dog'][0].synset)
605f52
-	3
605f52
-	"""
605f52
-	return len(self.getSenses())
605f52
+        """
605f52
+        >>> len(N['dog'][0].synset)
605f52
+        3
605f52
+        """
605f52
+        return len(self.getSenses())
605f52
     
605f52
     def __getitem__(self, idx):
605f52
-	"""
605f52
-	>>> N['dog'][0].synset[0] == N['dog'][0]
605f52
-	1
605f52
-	>>> N['dog'][0].synset['dog'] == N['dog'][0]
605f52
-	1
605f52
-	>>> N['dog'][0].synset[N['dog']] == N['dog'][0]
605f52
-	1
605f52
-	>>> N['cat'][6]
605f52
-	'cat' in {noun: big cat, cat}
605f52
-	"""
605f52
-	senses = self.getSenses()
605f52
-	if isinstance(idx, Word):
605f52
-	    idx = idx.form
605f52
-	if isinstance(idx, StringType):
605f52
-	    idx = _index(idx, map(lambda sense:sense.form, senses)) or \
605f52
-		  _index(idx, map(lambda sense:sense.form, senses), _equalsIgnoreCase)
605f52
-	return senses[idx]
605f52
+        """
605f52
+        >>> N['dog'][0].synset[0] == N['dog'][0]
605f52
+        1
605f52
+        >>> N['dog'][0].synset['dog'] == N['dog'][0]
605f52
+        1
605f52
+        >>> N['dog'][0].synset[N['dog']] == N['dog'][0]
605f52
+        1
605f52
+        >>> N['cat'][6]
605f52
+        'cat' in {noun: big cat, cat}
605f52
+        """
605f52
+        senses = self.getSenses()
605f52
+        if isinstance(idx, Word):
605f52
+            idx = idx.form
605f52
+        if isinstance(idx, str):
605f52
+            idx = _index(idx, [sense.form for sense in senses]) or \
605f52
+                  _index(idx, [sense.form for sense in senses], _equalsIgnoreCase)
605f52
+        return senses[idx]
605f52
     
605f52
     def __getslice__(self, i, j):
605f52
-	return self.getSenses()[i:j]
605f52
+        return self.getSenses()[i:j]
605f52
 
605f52
 
605f52
 class Sense:
605f52
@@ -527,7 +526,7 @@
605f52
           VERB_FRAME_STRINGS. These list the verb frames that this
605f52
           Sense partipates in.  Defined only for verbs.
605f52
 
605f52
-          >>> decide = V['decide'][0].synset	# first synset for 'decide'
605f52
+          >>> decide = V['decide'][0].synset        # first synset for 'decide'
605f52
           >>> decide[0].verbFrames
605f52
           (8, 2, 26, 29)
605f52
           >>> decide[1].verbFrames
605f52
@@ -538,124 +537,124 @@
605f52
     
605f52
     def __init__(sense, synset, senseTuple, verbFrames=None):
605f52
         "Initialize a sense from a synset's senseTuple."
605f52
-	# synset is stored by key (pos, synset) rather than object
605f52
-	# reference, to avoid creating a circular reference between
605f52
-	# Senses and Synsets that will prevent the vm from
605f52
-	# garbage-collecting them.
605f52
-	sense.pos = synset.pos
605f52
+        # synset is stored by key (pos, synset) rather than object
605f52
+        # reference, to avoid creating a circular reference between
605f52
+        # Senses and Synsets that will prevent the vm from
605f52
+        # garbage-collecting them.
605f52
+        sense.pos = synset.pos
605f52
         "part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB"
605f52
-	sense.synsetOffset = synset.offset
605f52
+        sense.synsetOffset = synset.offset
605f52
         "synset key.  This is used to retrieve the sense."
605f52
-	sense.verbFrames = verbFrames
605f52
+        sense.verbFrames = verbFrames
605f52
         """A sequence of integers that index into
605f52
         VERB_FRAME_STRINGS. These list the verb frames that this
605f52
         Sense partipates in.  Defined only for verbs."""
605f52
-	(form, idString) = senseTuple
605f52
-	sense.position = None
605f52
-	if '(' in form:
605f52
-	    index = string.index(form, '(')
605f52
-	    key = form[index + 1:-1]
605f52
-	    form = form[:index]
605f52
-	    if key == 'a':
605f52
-		sense.position = ATTRIBUTIVE
605f52
-	    elif key == 'p':
605f52
-		sense.position = PREDICATIVE
605f52
-	    elif key == 'ip':
605f52
-		sense.position = IMMEDIATE_POSTNOMINAL
605f52
-	    else:
605f52
-		raise "unknown attribute " + key
605f52
-	sense.form = string.replace(form, '_', ' ')
605f52
+        (form, idString) = senseTuple
605f52
+        sense.position = None
605f52
+        if '(' in form:
605f52
+            index = form.index('(')
605f52
+            key = form[index + 1:-1]
605f52
+            form = form[:index]
605f52
+            if key == 'a':
605f52
+                sense.position = ATTRIBUTIVE
605f52
+            elif key == 'p':
605f52
+                sense.position = PREDICATIVE
605f52
+            elif key == 'ip':
605f52
+                sense.position = IMMEDIATE_POSTNOMINAL
605f52
+            else:
605f52
+                raise "unknown attribute " + key
605f52
+        sense.form = form.replace('_', ' ')
605f52
         "orthographic representation of the Word this is a Sense of."
605f52
     
605f52
     def __getattr__(self, name):
605f52
-	# see the note at __init__ about why 'synset' is provided as a
605f52
-	# 'virtual' slot
605f52
-	if name == 'synset':
605f52
-	    return getSynset(self.pos, self.synsetOffset)
605f52
+        # see the note at __init__ about why 'synset' is provided as a
605f52
+        # 'virtual' slot
605f52
+        if name == 'synset':
605f52
+            return getSynset(self.pos, self.synsetOffset)
605f52
         elif name == 'lexname':
605f52
             return self.synset.lexname
605f52
-	else:
605f52
-	    raise AttributeError, name
605f52
+        else:
605f52
+            raise AttributeError(name)
605f52
     
605f52
     def __str__(self):
605f52
-	"""Return a human-readable representation.
605f52
-	
605f52
-	>>> str(N['dog'])
605f52
-	'dog(n.)'
605f52
-	"""
605f52
-	return `self.form` + " in " + str(self.synset)
605f52
+        """Return a human-readable representation.
605f52
+        
605f52
+        >>> str(N['dog'])
605f52
+        'dog(n.)'
605f52
+        """
605f52
+        return repr(self.form) + " in " + str(self.synset)
605f52
     
605f52
     def __repr__(self):
605f52
-	"""If ReadableRepresentations is true, return a human-readable
605f52
-	representation, e.g. 'dog(n.)'.
605f52
-	
605f52
-	If ReadableRepresentations is false, return a machine-readable
605f52
-	representation, e.g. "getWord('dog', 'noun')".
605f52
-	"""
605f52
-	if ReadableRepresentations:
605f52
-	    return str(self)
605f52
-	return "%s[%s]" % (`self.synset`, `self.form`)
605f52
+        """If ReadableRepresentations is true, return a human-readable
605f52
+        representation, e.g. 'dog(n.)'.
605f52
+        
605f52
+        If ReadableRepresentations is false, return a machine-readable
605f52
+        representation, e.g. "getWord('dog', 'noun')".
605f52
+        """
605f52
+        if ReadableRepresentations:
605f52
+            return str(self)
605f52
+        return "%s[%s]" % (repr(self.synset), repr(self.form))
605f52
     
605f52
     def getPointers(self, pointerType=None):
605f52
-	"""Return a sequence of Pointers.
605f52
-	
605f52
+        """Return a sequence of Pointers.
605f52
+        
605f52
         If pointerType is specified, only pointers of that type are
605f52
         returned.  In this case, pointerType should be an element of
605f52
         POINTER_TYPES.
605f52
-	
605f52
-	>>> N['dog'][0].getPointers()[:5]
605f52
-	(hypernym -> {noun: canine, canid}, member meronym -> {noun: Canis, genus Canis}, member meronym -> {noun: pack}, hyponym -> {noun: pooch, doggie, doggy, barker, bow-wow}, hyponym -> {noun: cur, mongrel, mutt})
605f52
-	>>> N['dog'][0].getPointers(HYPERNYM)
605f52
-	(hypernym -> {noun: canine, canid},)
605f52
-	"""
605f52
-	senseIndex = _index(self, self.synset.getSenses())
605f52
-	def pointsFromThisSense(pointer, selfIndex=senseIndex):
605f52
-	    return pointer.sourceIndex == 0 or pointer.sourceIndex - 1 == selfIndex
605f52
-	return filter(pointsFromThisSense, self.synset.getPointers(pointerType))
605f52
+        
605f52
+        >>> N['dog'][0].getPointers()[:5]
605f52
+        (hypernym -> {noun: canine, canid}, member meronym -> {noun: Canis, genus Canis}, member meronym -> {noun: pack}, hyponym -> {noun: pooch, doggie, doggy, barker, bow-wow}, hyponym -> {noun: cur, mongrel, mutt})
605f52
+        >>> N['dog'][0].getPointers(HYPERNYM)
605f52
+        (hypernym -> {noun: canine, canid},)
605f52
+        """
605f52
+        senseIndex = _index(self, self.synset.getSenses())
605f52
+        def pointsFromThisSense(pointer, selfIndex=senseIndex):
605f52
+            return pointer.sourceIndex == 0 or pointer.sourceIndex - 1 == selfIndex
605f52
+        return list(filter(pointsFromThisSense, self.synset.getPointers(pointerType)))
605f52
 
605f52
     pointers = getPointers # backwards compatability
605f52
 
605f52
     def getPointerTargets(self, pointerType=None):
605f52
-	"""Return a sequence of Senses or Synsets.
605f52
-	
605f52
+        """Return a sequence of Senses or Synsets.
605f52
+        
605f52
         If pointerType is specified, only targets of pointers of that
605f52
         type are returned.  In this case, pointerType should be an
605f52
         element of POINTER_TYPES.
605f52
-	
605f52
-	>>> N['dog'][0].getPointerTargets()[:5]
605f52
-	[{noun: canine, canid}, {noun: Canis, genus Canis}, {noun: pack}, {noun: pooch, doggie, doggy, barker, bow-wow}, {noun: cur, mongrel, mutt}]
605f52
-	>>> N['dog'][0].getPointerTargets(HYPERNYM)
605f52
-	[{noun: canine, canid}]
605f52
-	"""
605f52
-	return map(Pointer.target, self.getPointers(pointerType))
605f52
+        
605f52
+        >>> N['dog'][0].getPointerTargets()[:5]
605f52
+        [{noun: canine, canid}, {noun: Canis, genus Canis}, {noun: pack}, {noun: pooch, doggie, doggy, barker, bow-wow}, {noun: cur, mongrel, mutt}]
605f52
+        >>> N['dog'][0].getPointerTargets(HYPERNYM)
605f52
+        [{noun: canine, canid}]
605f52
+        """
605f52
+        return list(map(Pointer.target, self.getPointers(pointerType)))
605f52
 
605f52
     pointerTargets = getPointerTargets # backwards compatability
605f52
     
605f52
     def getSenses(self):
605f52
-	return self,
605f52
+        return self,
605f52
 
605f52
     senses = getSenses # backwards compatability
605f52
 
605f52
     def isTagged(self):
605f52
-	"""Return 1 if any sense is tagged.
605f52
-	
605f52
-	>>> N['dog'][0].isTagged()
605f52
-	1
605f52
-	>>> N['dog'][1].isTagged()
605f52
-	0
605f52
-	"""
605f52
-	word = self.word()
605f52
-	return _index(self, word.getSenses()) < word.taggedSenseCount
605f52
+        """Return 1 if any sense is tagged.
605f52
+        
605f52
+        >>> N['dog'][0].isTagged()
605f52
+        1
605f52
+        >>> N['dog'][1].isTagged()
605f52
+        0
605f52
+        """
605f52
+        word = self.word()
605f52
+        return _index(self, word.getSenses()) < word.taggedSenseCount
605f52
     
605f52
     def getWord(self):
605f52
-	return getWord(self.form, self.pos)
605f52
+        return getWord(self.form, self.pos)
605f52
 
605f52
     word = getWord # backwards compatability
605f52
 
605f52
     def __cmp__(self, other):
605f52
-	def senseIndex(sense, synset=self.synset):
605f52
-	    return _index(sense, synset.getSenses(), testfn=lambda a,b: a.form == b.form)
605f52
-	return _compareInstances(self, other, ('synset',)) or cmp(senseIndex(self), senseIndex(other))
605f52
+        def senseIndex(sense, synset=self.synset):
605f52
+            return _index(sense, synset.getSenses(), testfn=lambda a,b: a.form == b.form)
605f52
+        return _compareInstances(self, other, ('synset',)) or cmp(senseIndex(self), senseIndex(other))
605f52
 
605f52
 
605f52
 class Pointer:
605f52
@@ -670,21 +669,21 @@
605f52
     """
605f52
     
605f52
     _POINTER_TYPE_TABLE = {
605f52
-	'!': ANTONYM,
605f52
+        '!': ANTONYM,
605f52
         '@': HYPERNYM,
605f52
         '~': HYPONYM,
605f52
-	'=': ATTRIBUTE,
605f52
+        '=': ATTRIBUTE,
605f52
         '^': ALSO_SEE,
605f52
         '*': ENTAILMENT,
605f52
         '>': CAUSE,
605f52
-	'$': VERB_GROUP,
605f52
-	'#m': MEMBER_MERONYM,
605f52
+        '$': VERB_GROUP,
605f52
+        '#m': MEMBER_MERONYM,
605f52
         '#s': SUBSTANCE_MERONYM,
605f52
         '#p': PART_MERONYM,
605f52
-	'%m': MEMBER_HOLONYM,
605f52
+        '%m': MEMBER_HOLONYM,
605f52
         '%s': SUBSTANCE_HOLONYM,
605f52
         '%p': PART_HOLONYM,
605f52
-	'&': SIMILAR,
605f52
+        '&': SIMILAR,
605f52
         '<': PARTICIPLE_OF,
605f52
         '\\': PERTAINYM,
605f52
         # New in wn 2.0:
605f52
@@ -698,57 +697,57 @@
605f52
         }
605f52
     
605f52
     def __init__(self, sourceOffset, pointerTuple):
605f52
-	(type, offset, pos, indices) = pointerTuple
605f52
-	# dnaber: try to adapt to WordNet 2.1:
605f52
-	if type == "@i":
605f52
-		type = "@"
605f52
-	if type == "~i":
605f52
-		type = "~"
605f52
-	# /dnaber
605f52
-	self.type = Pointer._POINTER_TYPE_TABLE[type]
605f52
+        (type, offset, pos, indices) = pointerTuple
605f52
+        # dnaber: try to adapt to WordNet 2.1:
605f52
+        if type == "@i":
605f52
+                type = "@"
605f52
+        if type == "~i":
605f52
+                type = "~"
605f52
+        # /dnaber
605f52
+        self.type = Pointer._POINTER_TYPE_TABLE[type]
605f52
         """One of POINTER_TYPES."""
605f52
-	self.sourceOffset = sourceOffset
605f52
-	self.targetOffset = int(offset)
605f52
-	self.pos = _normalizePOS(pos)
605f52
+        self.sourceOffset = sourceOffset
605f52
+        self.targetOffset = int(offset)
605f52
+        self.pos = _normalizePOS(pos)
605f52
         """part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB"""
605f52
-	indices = string.atoi(indices, 16)
605f52
-	self.sourceIndex = indices >> 8
605f52
-	self.targetIndex = indices & 255
605f52
+        indices = int(indices, 16)
605f52
+        self.sourceIndex = indices >> 8
605f52
+        self.targetIndex = indices & 255
605f52
     
605f52
     def getSource(self):
605f52
-	synset = getSynset(self.pos, self.sourceOffset)
605f52
-	if self.sourceIndex:
605f52
-	    return synset[self.sourceIndex - 1]
605f52
-	else:
605f52
-	    return synset
605f52
+        synset = getSynset(self.pos, self.sourceOffset)
605f52
+        if self.sourceIndex:
605f52
+            return synset[self.sourceIndex - 1]
605f52
+        else:
605f52
+            return synset
605f52
 
605f52
     source = getSource # backwards compatability
605f52
 
605f52
     def getTarget(self):
605f52
-	synset = getSynset(self.pos, self.targetOffset)
605f52
-	if self.targetIndex:
605f52
-	    return synset[self.targetIndex - 1]
605f52
-	else:
605f52
-	    return synset
605f52
+        synset = getSynset(self.pos, self.targetOffset)
605f52
+        if self.targetIndex:
605f52
+            return synset[self.targetIndex - 1]
605f52
+        else:
605f52
+            return synset
605f52
 
605f52
     target = getTarget # backwards compatability
605f52
     
605f52
     def __str__(self):
605f52
-	return self.type + " -> " + str(self.target())
605f52
+        return self.type + " -> " + str(self.target())
605f52
     
605f52
     def __repr__(self):
605f52
-	if ReadableRepresentations:
605f52
-	    return str(self)
605f52
-	return "<" + str(self) + ">"
605f52
+        if ReadableRepresentations:
605f52
+            return str(self)
605f52
+        return "<" + str(self) + ">"
605f52
     
605f52
     def __cmp__(self, other):
605f52
-	diff = _compareInstances(self, other, ('pos', 'sourceOffset'))
605f52
-	if diff:
605f52
-	    return diff
605f52
-	synset = self.source()
605f52
-	def pointerIndex(sense, synset=synset):
605f52
-	    return _index(sense, synset.getPointers(), testfn=lambda a,b: not _compareInstances(a, b, ('type', 'sourceIndex', 'targetIndex')))
605f52
-	return cmp(pointerIndex(self), pointerIndex(other))
605f52
+        diff = _compareInstances(self, other, ('pos', 'sourceOffset'))
605f52
+        if diff:
605f52
+            return diff
605f52
+        synset = self.source()
605f52
+        def pointerIndex(sense, synset=synset):
605f52
+            return _index(sense, synset.getPointers(), testfn=lambda a,b: not _compareInstances(a, b, ('type', 'sourceIndex', 'targetIndex')))
605f52
+        return cmp(pointerIndex(self), pointerIndex(other))
605f52
 
605f52
 
605f52
 # Loading the lexnames
605f52
@@ -769,7 +768,7 @@
605f52
 
605f52
 def setupLexnames():
605f52
     for l in open(WNSEARCHDIR+'/lexnames').readlines():
605f52
-        i,name,category = string.split(l)
605f52
+        i,name,category = l.split()
605f52
         Lexname(name,PartsOfSpeech[int(category)-1])
605f52
 
605f52
 setupLexnames()
605f52
@@ -802,59 +801,59 @@
605f52
     """
605f52
     
605f52
     def __init__(self, pos, filenameroot):
605f52
-	self.pos = pos
605f52
+        self.pos = pos
605f52
         """part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB"""
605f52
-	self.indexFile = _IndexFile(pos, filenameroot)
605f52
-	self.dataFile = open(_dataFilePathname(filenameroot), _FILE_OPEN_MODE)
605f52
+        self.indexFile = _IndexFile(pos, filenameroot)
605f52
+        self.dataFile = open(_dataFilePathname(filenameroot), _FILE_OPEN_MODE)
605f52
     
605f52
     def __repr__(self):
605f52
-	dictionaryVariables = {N: 'N', V: 'V', ADJ: 'ADJ', ADV: 'ADV'}
605f52
-	if dictionaryVariables.get(self):
605f52
-	    return self.__module__ + "." + dictionaryVariables[self]
605f52
-	return "<%s.%s instance for %s>" % (self.__module__, "Dictionary", self.pos)
605f52
+        dictionaryVariables = {N: 'N', V: 'V', ADJ: 'ADJ', ADV: 'ADV'}
605f52
+        if dictionaryVariables.get(self):
605f52
+            return self.__module__ + "." + dictionaryVariables[self]
605f52
+        return "<%s.%s instance for %s>" % (self.__module__, "Dictionary", self.pos)
605f52
     
605f52
     def getWord(self, form, line=None):
605f52
-	key = string.replace(string.lower(form), ' ', '_')
605f52
-	pos = self.pos
605f52
-	def loader(key=key, line=line, indexFile=self.indexFile):
605f52
-	    line = line or indexFile.get(key)
605f52
-	    return line and Word(line)
605f52
-	word = _entityCache.get((pos, key), loader)
605f52
-	if word:
605f52
-	    return word
605f52
-	else:
605f52
-	    raise KeyError, "%s is not in the %s database" % (`form`, `pos`)
605f52
+        key = form.lower().replace(' ', '_')
605f52
+        pos = self.pos
605f52
+        def loader(key=key, line=line, indexFile=self.indexFile):
605f52
+            line = line or indexFile.get(key)
605f52
+            return line and Word(line)
605f52
+        word = _entityCache.get((pos, key), loader)
605f52
+        if word != None:
605f52
+            return word
605f52
+        else:
605f52
+            raise KeyError("%s is not in the %s database" % (repr(form), repr(pos)))
605f52
     
605f52
     def getSynset(self, offset):
605f52
-	pos = self.pos
605f52
-	def loader(pos=pos, offset=offset, dataFile=self.dataFile):
605f52
-	    return Synset(pos, offset, _lineAt(dataFile, offset))
605f52
-	return _entityCache.get((pos, offset), loader)
605f52
+        pos = self.pos
605f52
+        def loader(pos=pos, offset=offset, dataFile=self.dataFile):
605f52
+            return Synset(pos, offset, _lineAt(dataFile, offset))
605f52
+        return _entityCache.get((pos, offset), loader)
605f52
     
605f52
     def _buildIndexCacheFile(self):
605f52
-	self.indexFile._buildIndexCacheFile()
605f52
+        self.indexFile._buildIndexCacheFile()
605f52
     
605f52
     #
605f52
     # Sequence protocol (a Dictionary's items are its Words)
605f52
     #
605f52
-    def __nonzero__(self):
605f52
-	"""Return false.  (This is to avoid scanning the whole index file
605f52
-	to compute len when a Dictionary is used in test position.)
605f52
-	
605f52
-	>>> N and 'true'
605f52
-	'true'
605f52
-	"""
605f52
-	return 1
605f52
+    def __bool__(self):
605f52
+        """Return false.  (This is to avoid scanning the whole index file
605f52
+        to compute len when a Dictionary is used in test position.)
605f52
+        
605f52
+        >>> N and 'true'
605f52
+        'true'
605f52
+        """
605f52
+        return 1
605f52
     
605f52
     def __len__(self):
605f52
-	"""Return the number of index entries.
605f52
-	
605f52
-	>>> len(ADJ)
605f52
-	21435
605f52
-	"""
605f52
-	if not hasattr(self, 'length'):
605f52
-	    self.length = len(self.indexFile)
605f52
-	return self.length
605f52
+        """Return the number of index entries.
605f52
+        
605f52
+        >>> len(ADJ)
605f52
+        21435
605f52
+        """
605f52
+        if not hasattr(self, 'length'):
605f52
+            self.length = len(self.indexFile)
605f52
+        return self.length
605f52
     
605f52
     def __getslice__(self, a, b):
605f52
         results = []
605f52
@@ -868,22 +867,22 @@
605f52
         return results
605f52
 
605f52
     def __getitem__(self, index):
605f52
-	"""If index is a String, return the Word whose form is
605f52
-	index.  If index is an integer n, return the Word
605f52
-	indexed by the n'th Word in the Index file.
605f52
-	
605f52
-	>>> N['dog']
605f52
-	dog(n.)
605f52
-	>>> N[0]
605f52
-	'hood(n.)
605f52
-	"""
605f52
-	if isinstance(index, StringType):
605f52
-	    return self.getWord(index)
605f52
-	elif isinstance(index, IntType):
605f52
-	    line = self.indexFile[index]
605f52
-	    return self.getWord(string.replace(line[:string.find(line, ' ')], '_', ' '), line)
605f52
-	else:
605f52
-	    raise TypeError, "%s is not a String or Int" % `index`
605f52
+        """If index is a String, return the Word whose form is
605f52
+        index.  If index is an integer n, return the Word
605f52
+        indexed by the n'th Word in the Index file.
605f52
+        
605f52
+        >>> N['dog']
605f52
+        dog(n.)
605f52
+        >>> N[0]
605f52
+        'hood(n.)
605f52
+        """
605f52
+        if isinstance(index, str):
605f52
+            return self.getWord(index)
605f52
+        elif isinstance(index, int):
605f52
+            line = self.indexFile[index]
605f52
+            return self.getWord(string.replace(line[:string.find(line, ' ')], '_', ' '), line)
605f52
+        else:
605f52
+            raise TypeError("%s is not a String or Int" % repr(index))
605f52
     
605f52
     #
605f52
     # Dictionary protocol
605f52
@@ -892,54 +891,54 @@
605f52
     #
605f52
 
605f52
     def get(self, key, default=None):
605f52
-	"""Return the Word whose form is _key_, or _default_.
605f52
-	
605f52
-	>>> N.get('dog')
605f52
-	dog(n.)
605f52
-	>>> N.get('inu')
605f52
-	"""
605f52
-	try:
605f52
-	    return self[key]
605f52
-	except LookupError:
605f52
-	    return default
605f52
+        """Return the Word whose form is _key_, or _default_.
605f52
+        
605f52
+        >>> N.get('dog')
605f52
+        dog(n.)
605f52
+        >>> N.get('inu')
605f52
+        """
605f52
+        try:
605f52
+            return self[key]
605f52
+        except LookupError:
605f52
+            return default
605f52
     
605f52
     def keys(self):
605f52
-	"""Return a sorted list of strings that index words in this
605f52
-	dictionary."""
605f52
-	return self.indexFile.keys()
605f52
+        """Return a sorted list of strings that index words in this
605f52
+        dictionary."""
605f52
+        return list(self.indexFile.keys())
605f52
     
605f52
     def has_key(self, form):
605f52
-	"""Return true iff the argument indexes a word in this dictionary.
605f52
-	
605f52
-	>>> N.has_key('dog')
605f52
-	1
605f52
-	>>> N.has_key('inu')
605f52
-	0
605f52
-	"""
605f52
-	return self.indexFile.has_key(form)
605f52
+        """Return true iff the argument indexes a word in this dictionary.
605f52
+        
605f52
+        >>> N.has_key('dog')
605f52
+        1
605f52
+        >>> N.has_key('inu')
605f52
+        0
605f52
+        """
605f52
+        return form in self.indexFile
605f52
     
605f52
     #
605f52
     # Testing
605f52
     #
605f52
     
605f52
     def _testKeys(self):
605f52
-	"""Verify that index lookup can find each word in the index file."""
605f52
-	print "Testing: ", self
605f52
-	file = open(self.indexFile.file.name, _FILE_OPEN_MODE)
605f52
-	counter = 0
605f52
-	while 1:
605f52
-	    line = file.readline()
605f52
-	    if line == '': break
605f52
-	    if line[0] != ' ':
605f52
-		key = string.replace(line[:string.find(line, ' ')], '_', ' ')
605f52
-		if (counter % 1000) == 0:
605f52
-		    print "%s..." % (key,),
605f52
-		    import sys
605f52
-		    sys.stdout.flush()
605f52
-		counter = counter + 1
605f52
-		self[key]
605f52
-	file.close()
605f52
-	print "done."
605f52
+        """Verify that index lookup can find each word in the index file."""
605f52
+        print("Testing: ", self)
605f52
+        file = open(self.indexFile.file.name, _FILE_OPEN_MODE)
605f52
+        counter = 0
605f52
+        while 1:
605f52
+            line = file.readline()
605f52
+            if line == '': break
605f52
+            if line[0] != ' ':
605f52
+                key = string.replace(line[:string.find(line, ' ')], '_', ' ')
605f52
+                if (counter % 1000) == 0:
605f52
+                    print("%s..." % (key,), end=' ')
605f52
+                    import sys
605f52
+                    sys.stdout.flush()
605f52
+                counter = counter + 1
605f52
+                self[key]
605f52
+        file.close()
605f52
+        print("done.")
605f52
 
605f52
 
605f52
 class _IndexFile:
605f52
@@ -947,69 +946,69 @@
605f52
     Sequence and Dictionary interface to a sorted index file."""
605f52
     
605f52
     def __init__(self, pos, filenameroot):
605f52
-	self.pos = pos
605f52
-	self.file = open(_indexFilePathname(filenameroot), _FILE_OPEN_MODE)
605f52
-	self.offsetLineCache = {}   # Table of (pathname, offset) -> (line, nextOffset)
605f52
-	self.rewind()
605f52
-	self.shelfname = os.path.join(WNSEARCHDIR, pos + ".pyidx")
605f52
-	try:
605f52
-	    import shelve
605f52
-	    self.indexCache = shelve.open(self.shelfname, 'r')
605f52
-	except:
605f52
-	    pass
605f52
+        self.pos = pos
605f52
+        self.file = open(_indexFilePathname(filenameroot), _FILE_OPEN_MODE)
605f52
+        self.offsetLineCache = {}   # Table of (pathname, offset) -> (line, nextOffset)
605f52
+        self.rewind()
605f52
+        self.shelfname = os.path.join(WNSEARCHDIR, pos + ".pyidx")
605f52
+        try:
605f52
+            import shelve
605f52
+            self.indexCache = shelve.open(self.shelfname, 'r')
605f52
+        except:
605f52
+            pass
605f52
     
605f52
     def rewind(self):
605f52
-	self.file.seek(0)
605f52
-	while 1:
605f52
-	    offset = self.file.tell()
605f52
-	    line = self.file.readline()
605f52
-	    if (line[0] != ' '):
605f52
-		break
605f52
-	self.nextIndex = 0
605f52
-	self.nextOffset = offset
605f52
+        self.file.seek(0)
605f52
+        while 1:
605f52
+            offset = self.file.tell()
605f52
+            line = self.file.readline()
605f52
+            if (line[0] != ' '):
605f52
+                break
605f52
+        self.nextIndex = 0
605f52
+        self.nextOffset = offset
605f52
     
605f52
     #
605f52
     # Sequence protocol (an _IndexFile's items are its lines)
605f52
     #
605f52
-    def __nonzero__(self):
605f52
-	return 1
605f52
+    def __bool__(self):
605f52
+        return 1
605f52
     
605f52
     def __len__(self):
605f52
-	if hasattr(self, 'indexCache'):
605f52
-	    return len(self.indexCache)
605f52
-	self.rewind()
605f52
-	lines = 0
605f52
-	while 1:
605f52
-	    line = self.file.readline()
605f52
-	    if line == "":
605f52
-		break
605f52
-	    lines = lines + 1
605f52
-	return lines
605f52
+        if hasattr(self, 'indexCache'):
605f52
+            return len(self.indexCache)
605f52
+        self.rewind()
605f52
+        lines = 0
605f52
+        while 1:
605f52
+            line = self.file.readline()
605f52
+            if line == "":
605f52
+                break
605f52
+            lines = lines + 1
605f52
+        return lines
605f52
     
605f52
-    def __nonzero__(self):
605f52
-	return 1
605f52
+    def __bool__(self):
605f52
+        return 1
605f52
     
605f52
     def __getitem__(self, index):
605f52
-	if isinstance(index, StringType):
605f52
-	    if hasattr(self, 'indexCache'):
605f52
-		return self.indexCache[index]
605f52
-	    return binarySearchFile(self.file, index, self.offsetLineCache, 8)
605f52
-	elif isinstance(index, IntType):
605f52
-	    if hasattr(self, 'indexCache'):
605f52
-		return self.get(self.keys[index])
605f52
-	    if index < self.nextIndex:
605f52
-		self.rewind()
605f52
-	    while self.nextIndex <= index:
605f52
-		self.file.seek(self.nextOffset)
605f52
-		line = self.file.readline()
605f52
-		if line == "":
605f52
-		    raise IndexError, "index out of range"
605f52
-		self.nextIndex = self.nextIndex + 1
605f52
-		self.nextOffset = self.file.tell()
605f52
-	    return line
605f52
-	else:
605f52
-	    raise TypeError, "%s is not a String or Int" % `index`
605f52
-	
605f52
+        if isinstance(index, str):
605f52
+            if hasattr(self, 'indexCache'):
605f52
+                return self.indexCache[index]
605f52
+            return binarySearchFile(self.file, index, self.offsetLineCache, 8)
605f52
+        elif isinstance(index, int):
605f52
+            if hasattr(self, 'indexCache'):
605f52
+                return self.get(self.keys[index])
605f52
+            if index < self.nextIndex:
605f52
+                self.rewind()
605f52
+            while self.nextIndex <= index:
605f52
+                self.file.seek(self.nextOffset)
605f52
+                line = self.file.readline()
605f52
+                if line == "":
605f52
+                    raise IndexError("index out of range")
605f52
+                self.nextIndex = self.nextIndex + 1
605f52
+                self.nextOffset = self.file.tell()
605f52
+            return line
605f52
+        else:
605f52
+            raise TypeError("%s is not a String or Int" % repr(index))
605f52
+        
605f52
     #
605f52
     # Dictionary protocol
605f52
     #
605f52
@@ -1017,62 +1016,62 @@
605f52
     #
605f52
     
605f52
     def get(self, key, default=None):
605f52
-	try:
605f52
-	    return self[key]
605f52
-	except LookupError:
605f52
-	    return default
605f52
+        try:
605f52
+            return self[key]
605f52
+        except LookupError:
605f52
+            return default
605f52
     
605f52
     def keys(self):
605f52
-	if hasattr(self, 'indexCache'):
605f52
-	    keys = self.indexCache.keys()
605f52
-	    keys.sort()
605f52
-	    return keys
605f52
-	else:
605f52
-	    keys = []
605f52
-	    self.rewind()
605f52
-	    while 1:
605f52
-		line = self.file.readline()
605f52
-		if not line: break
605f52
+        if hasattr(self, 'indexCache'):
605f52
+            keys = list(self.indexCache.keys())
605f52
+            keys.sort()
605f52
+            return keys
605f52
+        else:
605f52
+            keys = []
605f52
+            self.rewind()
605f52
+            while 1:
605f52
+                line = self.file.readline()
605f52
+                if not line: break
605f52
                 key = line.split(' ', 1)[0]
605f52
-		keys.append(key.replace('_', ' '))
605f52
-	    return keys
605f52
+                keys.append(key.replace('_', ' '))
605f52
+            return keys
605f52
     
605f52
     def has_key(self, key):
605f52
-	key = key.replace(' ', '_') # test case: V['haze over']
605f52
-	if hasattr(self, 'indexCache'):
605f52
-	    return self.indexCache.has_key(key)
605f52
-	return self.get(key) != None
605f52
+        key = key.replace(' ', '_') # test case: V['haze over']
605f52
+        if hasattr(self, 'indexCache'):
605f52
+            return key in self.indexCache
605f52
+        return self.get(key) != None
605f52
     
605f52
     #
605f52
     # Index file
605f52
     #
605f52
     
605f52
     def _buildIndexCacheFile(self):
605f52
-	import shelve
605f52
-	import os
605f52
-	print "Building %s:" % (self.shelfname,),
605f52
-	tempname = self.shelfname + ".temp"
605f52
-	try:
605f52
-	    indexCache = shelve.open(tempname)
605f52
-	    self.rewind()
605f52
-	    count = 0
605f52
-	    while 1:
605f52
-		offset, line = self.file.tell(), self.file.readline()
605f52
-		if not line: break
605f52
-		key = line[:string.find(line, ' ')]
605f52
-		if (count % 1000) == 0:
605f52
-		    print "%s..." % (key,),
605f52
-		    import sys
605f52
-		    sys.stdout.flush()
605f52
-		indexCache[key] = line
605f52
-		count = count + 1
605f52
-	    indexCache.close()
605f52
-	    os.rename(tempname, self.shelfname)
605f52
-	finally:
605f52
-	    try: os.remove(tempname)
605f52
-	    except: pass
605f52
-	print "done."
605f52
-	self.indexCache = shelve.open(self.shelfname, 'r')
605f52
+        import shelve
605f52
+        import os
605f52
+        print("Building %s:" % (self.shelfname,), end=' ')
605f52
+        tempname = self.shelfname + ".temp"
605f52
+        try:
605f52
+            indexCache = shelve.open(tempname)
605f52
+            self.rewind()
605f52
+            count = 0
605f52
+            while 1:
605f52
+                offset, line = self.file.tell(), self.file.readline()
605f52
+                if not line: break
605f52
+                key = line[:string.find(line, ' ')]
605f52
+                if (count % 1000) == 0:
605f52
+                    print("%s..." % (key,), end=' ')
605f52
+                    import sys
605f52
+                    sys.stdout.flush()
605f52
+                indexCache[key] = line
605f52
+                count = count + 1
605f52
+            indexCache.close()
605f52
+            os.rename(tempname, self.shelfname)
605f52
+        finally:
605f52
+            try: os.remove(tempname)
605f52
+            except: pass
605f52
+        print("done.")
605f52
+        self.indexCache = shelve.open(self.shelfname, 'r')
605f52
 
605f52
 
605f52
 #
605f52
@@ -1099,20 +1098,20 @@
605f52
 
605f52
 def _requirePointerType(pointerType):
605f52
     if pointerType not in POINTER_TYPES:
605f52
-	raise TypeError, `pointerType` + " is not a pointer type"
605f52
+        raise TypeError(repr(pointerType) + " is not a pointer type")
605f52
     return pointerType
605f52
 
605f52
 def _compareInstances(a, b, fields):
605f52
     """"Return -1, 0, or 1 according to a comparison first by type,
605f52
     then by class, and finally by each of fields.""" # " <- for emacs
605f52
     if not hasattr(b, '__class__'):
605f52
-	return cmp(type(a), type(b))
605f52
+        return cmp(type(a), type(b))
605f52
     elif a.__class__ != b.__class__:
605f52
-	return cmp(a.__class__, b.__class__)
605f52
+        return cmp(a.__class__, b.__class__)
605f52
     for field in fields:
605f52
-	diff = cmp(getattr(a, field), getattr(b, field))
605f52
-	if diff:
605f52
-	    return diff
605f52
+        diff = cmp(getattr(a, field), getattr(b, field))
605f52
+        if diff:
605f52
+            return diff
605f52
     return 0
605f52
 
605f52
 def _equalsIgnoreCase(a, b):
605f52
@@ -1123,21 +1122,21 @@
605f52
     >>> _equalsIgnoreCase('dOg', 'DOG')
605f52
     1
605f52
     """
605f52
-    return a == b or string.lower(a) == string.lower(b)
605f52
+    return a == b or a.lower() == b.lower()
605f52
 
605f52
 #
605f52
 # File utilities
605f52
 #
605f52
 def _dataFilePathname(filenameroot):
605f52
     if os.name in ('dos', 'nt'):
605f52
-	path = os.path.join(WNSEARCHDIR, filenameroot + ".dat")
605f52
+        path = os.path.join(WNSEARCHDIR, filenameroot + ".dat")
605f52
         if os.path.exists(path):
605f52
             return path
605f52
     return os.path.join(WNSEARCHDIR, "data." + filenameroot)
605f52
 
605f52
 def _indexFilePathname(filenameroot):
605f52
     if os.name in ('dos', 'nt'):
605f52
-	path = os.path.join(WNSEARCHDIR, filenameroot + ".idx")
605f52
+        path = os.path.join(WNSEARCHDIR, filenameroot + ".idx")
605f52
         if os.path.exists(path):
605f52
             return path
605f52
     return os.path.join(WNSEARCHDIR, "index." + filenameroot)
605f52
@@ -1154,30 +1153,30 @@
605f52
         #if count > 20:
605f52
         #    raise "infinite loop"
605f52
         lastState = start, end
605f52
-	middle = (start + end) / 2
605f52
-	if cache.get(middle):
605f52
-	    offset, line = cache[middle]
605f52
-	else:
605f52
-	    file.seek(max(0, middle - 1))
605f52
-	    if middle > 0:
605f52
-		file.readline()
605f52
-	    offset, line = file.tell(), file.readline()
605f52
-	    if currentDepth < cacheDepth:
605f52
-		cache[middle] = (offset, line)
605f52
+        middle = (start + end) / 2
605f52
+        if cache.get(middle):
605f52
+            offset, line = cache[middle]
605f52
+        else:
605f52
+            file.seek(max(0, middle - 1))
605f52
+            if middle > 0:
605f52
+                file.readline()
605f52
+            offset, line = file.tell(), file.readline()
605f52
+            if currentDepth < cacheDepth:
605f52
+                cache[middle] = (offset, line)
605f52
         #print start, middle, end, offset, line,
605f52
-	if offset > end:
605f52
-	    assert end != middle - 1, "infinite loop"
605f52
-	    end = middle - 1
605f52
-	elif line[:keylen] == key:# and line[keylen + 1] == ' ':
605f52
-	    return line
605f52
+        if offset > end:
605f52
+            assert end != middle - 1, "infinite loop"
605f52
+            end = middle - 1
605f52
+        elif line[:keylen] == key:# and line[keylen + 1] == ' ':
605f52
+            return line
605f52
         #elif offset == end:
605f52
         #    return None
605f52
-	elif line > key:
605f52
-	    assert end != middle - 1, "infinite loop"
605f52
-	    end = middle - 1
605f52
-	elif line < key:
605f52
-	    start = offset + len(line) - 1
605f52
-	currentDepth = currentDepth + 1
605f52
+        elif line > key:
605f52
+            assert end != middle - 1, "infinite loop"
605f52
+            end = middle - 1
605f52
+        elif line < key:
605f52
+            start = offset + len(line) - 1
605f52
+        currentDepth = currentDepth + 1
605f52
         thisState = start, end
605f52
         if lastState == thisState:
605f52
             # detects the condition where we're searching past the end
605f52
@@ -1206,12 +1205,12 @@
605f52
     """
605f52
     index = 0
605f52
     for element in sequence:
605f52
-	value = element
605f52
-	if keyfn:
605f52
-	    value = keyfn(value)
605f52
-	if (not testfn and value == key) or (testfn and testfn(value, key)):
605f52
-	    return index
605f52
-	index = index + 1
605f52
+        value = element
605f52
+        if keyfn:
605f52
+            value = keyfn(value)
605f52
+        if (not testfn and value == key) or (testfn and testfn(value, key)):
605f52
+            return index
605f52
+        index = index + 1
605f52
     return None
605f52
 
605f52
 def _partition(sequence, size, count):
605f52
@@ -1224,7 +1223,7 @@
605f52
     
605f52
     partitions = []
605f52
     for index in range(0, size * count, size):
605f52
-	partitions.append(sequence[index:index + size])
605f52
+        partitions.append(sequence[index:index + size])
605f52
     return (partitions, sequence[size * count:])
605f52
 
605f52
 
605f52
@@ -1269,49 +1268,49 @@
605f52
       but the two implementations aren't directly comparable."""
605f52
    
605f52
     def __init__(this, capacity):
605f52
-	this.capacity = capacity
605f52
-	this.clear()
605f52
+        this.capacity = capacity
605f52
+        this.clear()
605f52
     
605f52
     def clear(this):
605f52
-	this.values = {}
605f52
-	this.history = {}
605f52
-	this.oldestTimestamp = 0
605f52
-	this.nextTimestamp = 1
605f52
+        this.values = {}
605f52
+        this.history = {}
605f52
+        this.oldestTimestamp = 0
605f52
+        this.nextTimestamp = 1
605f52
     
605f52
     def removeOldestEntry(this):
605f52
-	while this.oldestTimestamp < this.nextTimestamp:
605f52
-	    if this.history.get(this.oldestTimestamp):
605f52
-		key = this.history[this.oldestTimestamp]
605f52
-		del this.history[this.oldestTimestamp]
605f52
-		del this.values[key]
605f52
-		return
605f52
-	    this.oldestTimestamp = this.oldestTimestamp + 1
605f52
+        while this.oldestTimestamp < this.nextTimestamp:
605f52
+            if this.history.get(this.oldestTimestamp):
605f52
+                key = this.history[this.oldestTimestamp]
605f52
+                del this.history[this.oldestTimestamp]
605f52
+                del this.values[key]
605f52
+                return
605f52
+            this.oldestTimestamp = this.oldestTimestamp + 1
605f52
     
605f52
     def setCapacity(this, capacity):
605f52
-	if capacity == 0:
605f52
-	    this.clear()
605f52
-	else:
605f52
-	    this.capacity = capacity
605f52
-	    while len(this.values) > this.capacity:
605f52
-		this.removeOldestEntry()    
605f52
+        if capacity == 0:
605f52
+            this.clear()
605f52
+        else:
605f52
+            this.capacity = capacity
605f52
+            while len(this.values) > this.capacity:
605f52
+                this.removeOldestEntry()    
605f52
     
605f52
     def get(this, key, loadfn=None):
605f52
-	value = None
605f52
-	if this.values:
605f52
-	    pair = this.values.get(key)
605f52
-	    if pair:
605f52
-		(value, timestamp) = pair
605f52
-		del this.history[timestamp]
605f52
-	if value == None:
605f52
-	    value = loadfn and loadfn()
605f52
-	if this.values != None:
605f52
-	    timestamp = this.nextTimestamp
605f52
-	    this.nextTimestamp = this.nextTimestamp + 1
605f52
-	    this.values[key] = (value, timestamp)
605f52
-	    this.history[timestamp] = key
605f52
-	    if len(this.values) > this.capacity:
605f52
-		this.removeOldestEntry()
605f52
-	return value
605f52
+        value = None
605f52
+        if this.values:
605f52
+            pair = this.values.get(key)
605f52
+            if pair:
605f52
+                (value, timestamp) = pair
605f52
+                del this.history[timestamp]
605f52
+        if value == None:
605f52
+            value = loadfn and loadfn()
605f52
+        if this.values != None:
605f52
+            timestamp = this.nextTimestamp
605f52
+            this.nextTimestamp = this.nextTimestamp + 1
605f52
+            this.values[key] = (value, timestamp)
605f52
+            this.history[timestamp] = key
605f52
+            if len(this.values) > this.capacity:
605f52
+                this.removeOldestEntry()
605f52
+        return value
605f52
 
605f52
 
605f52
 class _NullCache:
605f52
@@ -1319,10 +1318,10 @@
605f52
     LRUCache implements), but doesn't store any values."""
605f52
     
605f52
     def clear():
605f52
-	pass
605f52
+        pass
605f52
     
605f52
     def get(this, key, loadfn=None):
605f52
-	return loadfn and loadfn()
605f52
+        return loadfn and loadfn()
605f52
 
605f52
 
605f52
 DEFAULT_CACHE_CAPACITY = 1000
605f52
@@ -1335,7 +1334,7 @@
605f52
 def enableCache():
605f52
     """Enable the entity cache."""
605f52
     if not isinstance(_entityCache, LRUCache):
605f52
-	_entityCache = _LRUCache(size)
605f52
+        _entityCache = _LRUCache(size)
605f52
 
605f52
 def clearCache():
605f52
     """Clear the entity cache."""
605f52
@@ -1373,36 +1372,36 @@
605f52
     _POSNormalizationTable = {}
605f52
     _POStoDictionaryTable = {}
605f52
     for pos, abbreviations in (
605f52
-	    (NOUN, "noun n n."),
605f52
-	    (VERB, "verb v v."),
605f52
-	    (ADJECTIVE, "adjective adj adj. a s"),
605f52
-	    (ADVERB, "adverb adv adv. r")):
605f52
-	tokens = string.split(abbreviations)
605f52
-	for token in tokens:
605f52
-	    _POSNormalizationTable[token] = pos
605f52
-	    _POSNormalizationTable[string.upper(token)] = pos
605f52
+            (NOUN, "noun n n."),
605f52
+            (VERB, "verb v v."),
605f52
+            (ADJECTIVE, "adjective adj adj. a s"),
605f52
+            (ADVERB, "adverb adv adv. r")):
605f52
+        tokens = abbreviations.split()
605f52
+        for token in tokens:
605f52
+            _POSNormalizationTable[token] = pos
605f52
+            _POSNormalizationTable[token.upper()] = pos
605f52
     for dict in Dictionaries:
605f52
-	_POSNormalizationTable[dict] = dict.pos
605f52
-	_POStoDictionaryTable[dict.pos] = dict
605f52
+        _POSNormalizationTable[dict] = dict.pos
605f52
+        _POStoDictionaryTable[dict.pos] = dict
605f52
 
605f52
 _initializePOSTables()
605f52
 
605f52
 def _normalizePOS(pos):
605f52
     norm = _POSNormalizationTable.get(pos)
605f52
     if norm:
605f52
-	return norm
605f52
-    raise TypeError, `pos` + " is not a part of speech type"
605f52
+        return norm
605f52
+    raise TypeError(repr(pos) + " is not a part of speech type")
605f52
 
605f52
 def _dictionaryFor(pos):
605f52
     pos = _normalizePOS(pos)
605f52
     dict = _POStoDictionaryTable.get(pos)
605f52
     if dict == None:
605f52
-	raise RuntimeError, "The " + `pos` + " dictionary has not been created"
605f52
+        raise RuntimeError("The " + repr(pos) + " dictionary has not been created")
605f52
     return dict
605f52
 
605f52
 def buildIndexFiles():
605f52
     for dict in Dictionaries:
605f52
-	dict._buildIndexCacheFile()
605f52
+        dict._buildIndexCacheFile()
605f52
 
605f52
 
605f52
 #
605f52
@@ -1412,7 +1411,7 @@
605f52
 def _testKeys():
605f52
     #This is slow, so don't do it as part of the normal test procedure.
605f52
     for dictionary in Dictionaries:
605f52
-	dictionary._testKeys()
605f52
+        dictionary._testKeys()
605f52
 
605f52
 def _test(reset=0):
605f52
     import doctest, wordnet