# Path: src/backend/math_utils.py
# def hellinger_distance(sqrt_doca, sqrt_docb, axis=1):
#     """
#     Returns the (squared) Hellinger Distance between documents.
# 
#     @para doca: is expected to be a 1d array (ie., a single document),
#     @param docb: is expected to be a 2d array(ie., the rest of the documents in the
#     corpus).
# 
#     Note that this expects to be given proper probability distributions.
#     """
#     return np.sum((sqrt_doca - sqrt_docb)**2, axis=axis)
# 
# Path: src/backend/tma_utils.py
# def slugify(value):
#     """
#     Normalizes string, converts to lowercase, removes non-alpha characters,
#     and converts spaces to hyphens.
#     """
#     import unicodedata 
#     value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
#     value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
#     return re.sub('[-\s]+', '-', value)    


from os import path
from src.backend.math_utils import hellinger_distance
from src.backend.tma_utils import slugify
import cPickle as pickle
import math
import pdb
import numpy as np
        return (self.id, self.title) == (other.id, other.title)


    def get_term(self, rank): # TODO this may be unneeded  and possibly inaccurate
        """
        obtain the rank-th most likely term for the given topic
        """
        if self.terms == {} or rank >= len(self.ranked_terms):
            self.terms = self.rel.get_topic_terms(self)
            self.ranked_terms = sorted(self.terms, key=self.terms.get, reverse=True)
        
        if rank >= len(self.ranked_terms):
            return None
        
        return self.ranked_terms[rank]


    def get_terms(self, cutoff=-1):
        """
        Obtain the top cutoff terms for the given topic (default=all terms)
        @param cutoff: the number of terms to return
        @return: the top cutoff terms for the given topic (default=all terms)
        """
        if self.terms == {}:
            self.terms = self.rel.get_topic_terms(self, cutoff)
            self.ranked_terms = sorted(self.terms, key=self.terms.get, reverse=True)  
        return self.ranked_terms[:cutoff]


    def get_safe_title(self):

# Path: src/backend/math_utils.py
# def hellinger_distance(sqrt_doca, sqrt_docb, axis=1):
#     """
#     Returns the (squared) Hellinger Distance between documents.
# 
#     @para doca: is expected to be a 1d array (ie., a single document),
#     @param docb: is expected to be a 2d array(ie., the rest of the documents in the
#     corpus).
# 
#     Note that this expects to be given proper probability distributions.
#     """
#     return np.sum((sqrt_doca - sqrt_docb)**2, axis=axis)
# 
# Path: src/backend/tma_utils.py
# def slugify(value):
#     """
#     Normalizes string, converts to lowercase, removes non-alpha characters,
#     and converts spaces to hyphens.
#     """
#     import unicodedata 
#     value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
#     value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
#     return re.sub('[-\s]+', '-', value)    


# Path: src/backend/relations.py
from os import path
from src.backend.math_utils import hellinger_distance
from src.backend.tma_utils import slugify
import cPickle as pickle
import math
import pdb
import numpy as np

        return (self.id, self.title) == (other.id, other.title)


    def get_term(self, rank): # TODO this may be unneeded  and possibly inaccurate
        """
        obtain the rank-th most likely term for the given topic
        """
        if self.terms == {} or rank >= len(self.ranked_terms):
            self.terms = self.rel.get_topic_terms(self)
            self.ranked_terms = sorted(self.terms, key=self.terms.get, reverse=True)
        
        if rank >= len(self.ranked_terms):
            return None
        
        return self.ranked_terms[rank]


    def get_terms(self, cutoff=-1):
        """
        Obtain the top cutoff terms for the given topic (default=all terms)
        @param cutoff: the number of terms to return
        @return: the top cutoff terms for the given topic (default=all terms)
        """
        if self.terms == {}:
            self.terms = self.rel.get_topic_terms(self, cutoff)
            self.ranked_terms = sorted(self.terms, key=self.terms.get, reverse=True)  
        return self.ranked_terms[:cutoff]


    def get_safe_title(self):

        safe_title = slugify(self.title)