def score(query, profile, data=None):
        if not len(profile.description):
            return [-1]

        vectorspace = VectorSpace([])

        tokenized_description = LowerTokenizer.tokenize(profile.description)
        description_vector = vectorspace.vector_for_document(
            tokenized_document=tokenized_description,
            update=True)

        ddg_description = DuckDuckDescription.query(query.lower())

        ddg_vector = []
        if ddg_description:
            ddg_text = ddg_description['description']['text']
            ddg_tokenized = LowerTokenizer.tokenize(ddg_text)
            ddg_vector = vectorspace.vector_for_document(
                tokenized_document=ddg_tokenized,
                update=True)

        if not len(ddg_vector):
            return [-1]

        return [cossim(description_vector, ddg_vector)]
Exemple #2
0
    def get(self, name):
        """Handles GET requests, taking in a company's name and
        returning a description for that company from DuckDuckGo."""
        if not name:
            self.write({})
            self.finish()

        ddg_result = DuckDuckDescription.query(name)
        if ddg_result:
            self.write({
                'name': ddg_result['name'],
                'description': ddg_result['description']
            })
            self.finish()
            return

        self.write({})
        self.finish()