Example #1
0
    def get_cooccurrences(self, token1, token2):
        token1 = deeputil.xcode(token1) if isinstance(token1, unicode) else token1
        token2 = deeputil.xcode(token2) if isinstance(token2, unicode) else token2

        token1 = str(token1)
        token2 = str(token2)

        res = dict(token1=token1, token2=token2)

        index1 = self._vocab.get(token1)
        index2 = self._vocab.get(token2)

        if (index1 is None) or (index2 is None):
            res.update(coccurrences=0)
            return res

        docs1 = self._get_docs(index1)

        docs2 = self._get_docs(index2)

        docs = np.intersect1d(docs1, docs2)
        res.update(cooccurrences=len(docs))

        return res
Example #2
0
    def authenticate(self, req):
        auth = super().authenticate(req)
        auth.username, auth.password = \
            base64.b64decode(xcode(auth.header_info)).decode('utf-8').split(':')

        auth_info = self.user_store.get(auth.username, None)
        if not auth_info:
            return auth

        if auth_info.get('password', None) != auth.password:
            return auth

        auth.is_authenticated = True
        auth.update(auth_info)

        return auth
Example #3
0
    def get_num_docs(self, token):
        token = deeputil.xcode(token) if isinstance(token, unicode) else token

        token = str(token)
        res = dict(token=token)

        index = self._vocab.get(token)

        if index is None:
            res.update(occurrences=0)
            return res

        doc_size = (self._indices[index+1] - self._indices[index]).item()

        res.update(occurrences=doc_size)

        return res
Example #4
0
 def __init__(self, bearer_token):
     self.bearer_token = xcode(bearer_token)
Example #5
0
 def __init__(self, username, password):
     self.username = xcode(username)
     self.password = xcode(password)
     self.encoded_key = b"%s:%s" % (self.username, self.password)
     self.encoded_key = base64.b64encode(self.encoded_key)