Returns the similarity score between two words.

         The type of similarity scoring method used depends on the currently active
         method and clustering type.

        :param unit1: Unit object corresponding to the first word.
        :type unit1: Unit
        :param unit2: Unit object corresponding to the second word.
        :type unit2: Unit
        :return: Number indicating degree of similarity of the two input words.
            The maximum value is 1, and a higher value indicates that the words
            are more similar.
        :rtype : Float

        The similarity method used depends both on the type of test being performed
        (SEMANTIC or PHONETIC) and the similarity method currently assigned to the
        self.current_similarity_measure property of the VFClustEngine object.  The
        similarity measures used are the following:
            - PHONETIC/"phone": the phonetic similarity score (PSS) is calculated
                between the phonetic representations of the input units. It is equal
                to 1 minus the Levenshtein distance between two strings, normalized
                to the length of the longer string. The strings should be compact
                phonetic representations of the two words.
                (This method is a modification of a Levenshtein distance function
                available at http://hetland.org/coding/python/levenshtein.py.)
            - PHONETIC/"biphone": the binary common-biphone score (CBS) depends
                on whether two words share their initial and/or final biphone
                (i.e., set of two phonemes). A score of 1 indicates that two words
                have the same intial and/or final biphone; a score of 0 indicates
                that two words have neither the same initial nor final biphone.
                This is also calculated using the phonetic representation of the
                two words.
            - SEMANTIC/"lsa": a semantic relatedness score (SRS) is calculated
                as the COSINE of the respective term vectors for the first and
                second word in an LSA space of the specified clustering_parameter.
                Unlike the PHONETIC methods, this method uses the .text property
                of the input Unit objects.

def compute_similarity_score(self, unit1, unit2):
        """ Returns the similarity score between two words.

         The type of similarity scoring method used depends on the currently active
         method and clustering type.

        :param unit1: Unit object corresponding to the first word.
        :type unit1: Unit
        :param unit2: Unit object corresponding to the second word.
        :type unit2: Unit
        :return: Number indicating degree of similarity of the two input words.
            The maximum value is 1, and a higher value indicates that the words
            are more similar.
        :rtype : Float

        The similarity method used depends both on the type of test being performed
        (SEMANTIC or PHONETIC) and the similarity method currently assigned to the
        self.current_similarity_measure property of the VFClustEngine object.  The
        similarity measures used are the following:
            - PHONETIC/"phone": the phonetic similarity score (PSS) is calculated
                between the phonetic representations of the input units. It is equal
                to 1 minus the Levenshtein distance between two strings, normalized
                to the length of the longer string. The strings should be compact
                phonetic representations of the two words.
                (This method is a modification of a Levenshtein distance function
                available at http://hetland.org/coding/python/levenshtein.py.)
            - PHONETIC/"biphone": the binary common-biphone score (CBS) depends
                on whether two words share their initial and/or final biphone
                (i.e., set of two phonemes). A score of 1 indicates that two words
                have the same intial and/or final biphone; a score of 0 indicates
                that two words have neither the same initial nor final biphone.
                This is also calculated using the phonetic representation of the
                two words.
            - SEMANTIC/"lsa": a semantic relatedness score (SRS) is calculated
                as the COSINE of the respective term vectors for the first and
                second word in an LSA space of the specified clustering_parameter.
                Unlike the PHONETIC methods, this method uses the .text property
                of the input Unit objects.

        """

        if self.type == "PHONETIC":
            word1 = unit1.phonetic_representation
            word2 = unit2.phonetic_representation
            if self.current_similarity_measure == "phone":
                word1_length, word2_length = len(word1), len(word2)
                if word1_length > word2_length:
                    # Make sure n <= m, to use O(min(n,m)) space
                    word1, word2 = word2, word1
                    word1_length, word2_length = word2_length, word1_length
                current = range(word1_length + 1)
                for i in range(1, word2_length + 1):
                    previous, current = current, [i] + [0] * word1_length
                    for j in range(1, word1_length + 1):
                        add, delete = previous[j] + 1, current[j - 1] + 1
                        change = previous[j - 1]
                        if word1[j - 1] != word2[i - 1]:
                            change += 1
                        current[j] = min(add, delete, change)
                phonetic_similarity_score = 1 - current[word1_length] / word2_length
                return phonetic_similarity_score

            elif self.current_similarity_measure == "biphone":
                if word1[:2] == word2[:2] or word1[-2:] == word2[-2:]:
                    common_biphone_score = 1
                else:
                    common_biphone_score = 0
                return common_biphone_score

        elif self.type == "SEMANTIC":
            word1 = unit1.text
            word2 = unit2.text
            if self.current_similarity_measure == "lsa":
                w1_vec = self.term_vectors[word1]
                w2_vec = self.term_vectors[word2]
                # semantic_relatedness_score = (numpy.dot(w1_vec, w2_vec) /
                #                               numpy.linalg.norm(w1_vec) /
                #                               numpy.linalg.norm(w2_vec))
                dot = sum([w1*w2 for w1,w2 in zip(w1_vec, w2_vec)])
                norm1 = sqrt(sum([w*w for w in w1_vec]))
                norm2 = sqrt(sum([w*w for w in w2_vec]))
                semantic_relatedness_score =  dot/(norm1 * norm2)
                return semantic_relatedness_score
            elif self.current_similarity_measure == "custom":
                #look it up in dict
                try:
                    similarity = self.custom_similarity_scores[(word1,word2)]
                except KeyError:
                    try:
                        similarity = self.custom_similarity_scores[(word2,word1)]
                    except KeyError:
                        if word1 == word2:
                            return self.same_word_similarity
                            #if they're the same word, they pass.  This should only happen when checking with
                            # non-adjacent words in the same cluster
                        else:
                            return 0 #if words aren't found, they are defined as dissimilar
                return similarity

        return None