Package nltk :: Package wordnet :: Module frequency
[hide private]
[frames] | no frames]

Source Code for Module nltk.wordnet.frequency

 1  # Natural Language Toolkit: Wordnet Interface: Sense frequency 
 2  # 
 3  # Copyright (C) 2001-2008 NLTK Project 
 4  # Author: Steven Bird <[email protected]> 
 5  # URL: <http://nltk.org> 
 6  # For license information, see LICENSE.TXT 
 7   
 8  # Count of a tagged sense in a semantic concordance 
 9   
10  import types 
11   
12  import nltk.data 
13   
14  from util import * 
15   
16 -class SenseCount(object):
17
18 - def __init__(self):
19 self._loaded = False
20
21 - def load(self):
22 if not self._loaded: 23 path = nltk.data.find('corpora/wordnet/cntlist.rev') 24 self._file = open(path, FILE_OPEN_MODE) 25 self._loaded = True
26
27 - def __call__(self, key):
28 self.load() 29 line = binarySearchFile(self._file, key) 30 if line: 31 return int(line.rsplit(' ', 1)[-1])
32 33 senseCount = SenseCount() 34