Coverage for nltk.cluster.api : 36%
![](keybd_closed.png)
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Natural Language Toolkit: Clusterer Interfaces # # Copyright (C) 2001-2012 NLTK Project # Author: Trevor Cohn <tacohn@cs.mu.oz.au> # Porting: Steven Bird <sb@csse.unimelb.edu.au> # URL: <http://www.nltk.org/> # For license information, see LICENSE.TXT
""" Interface covering basic clustering functionality. """
""" Assigns the vectors to clusters, learning the clustering parameters from the data. Returns a cluster identifier for each vector. """ raise NotImplementedError()
""" Classifies the token into a cluster, setting the token's CLUSTER parameter to that cluster identifier. """ raise NotImplementedError()
""" Returns the likelihood (a float) of the token having the corresponding cluster. """ if self.classify(vector) == label: return 1.0 else: return 0.0
""" Classifies the token into a cluster, returning a probability distribution over the cluster identifiers. """ likelihoods = {} sum = 0.0 for cluster in self.cluster_names(): likelihoods[cluster] = self.likelihood(vector, cluster) sum += likelihoods[cluster] for cluster in self.cluster_names(): likelihoods[cluster] /= sum return DictionaryProbDist(likelihoods)
""" Returns the number of clusters. """ raise NotImplementedError()
""" Returns the names of the clusters. """ return list(range(self.num_clusters()))
""" Returns the names of the cluster at index. """ return index |