'Returns the similarity score for two ngrams.
:param ngram1: first ngram to compare
:type ngram1: C{string}
:param ngram2: second ngram to compare
:type ngram2: C{string}
:param fileid: thesaurus fileid to search in. If None, search all fileids.
:type fileid: C{string}
:return: If fileid is specified, just the score for the two ngrams; otherwise,
list of tuples of fileids and scores.'

def similarity(self, ngram1, ngram2, fileid=None):

    if (ngram1 == ngram2):
        if fileid:
            return 1.0
        else:
            return [(fid, 1.0) for fid in self._fileids]
    elif fileid:
        return (self._thesaurus[fileid][ngram1][ngram2] if (ngram2 in self._thesaurus[fileid][ngram1]) else self._badscore)
    else:
        return [(fid, (self._thesaurus[fid][ngram1][ngram2] if (ngram2 in self._thesaurus[fid][ngram1]) else self._badscore)) for fid in self._fileids]
