Exemplo n.º 1
0
    def interpret(self, match):
        entity = HasKeyword(match.entity.tokens)
        target_type = HasKeyword(match.target.lemmas)
        target = HasType(target_type) + IsRelatedTo(entity)
        label = LabelOf(target)

        return label, "enum"
Exemplo n.º 2
0
    def interpret(self, match):
        expr = None

        for word in match.words:
            if expr is not None:
                expr += HasKeyword(word.token)
            else:
                expr = HasKeyword(word.token)

        return expr
Exemplo n.º 3
0
    def test_has_keyword(self):

        HasKeyword.relation = u"uranium:keyword"
        keywordinstance = HasKeyword(u"soplete")

        head = keywordinstance.get_head()
        edges = list(keywordinstance.iter_edges(head))
        self.assertEqual(len(edges), 1)
        self.assertIsInstance(edges[0][0], unicode)
        self.assertEqual(edges[0][0], u"uranium:keyword")
        self.assertIsInstance(edges[0][1], unicode)
        self.assertEqual(edges[0][1], u'soplete')

        # With language
        HasKeyword.language = "en"
        keywordinstance = HasKeyword("soplete")

        head = keywordinstance.get_head()
        edges = list(keywordinstance.iter_edges(head))
        self.assertEqual(len(edges), 1)
        self.assertIsInstance(edges[0][1], unicode)
        self.assertEqual(edges[0][1], u'"soplete"@en')

        # With sanitize
        HasKeyword.sanitize = staticmethod(lambda x: x.upper())
        keywordinstance = HasKeyword(u"soplete")

        head = keywordinstance.get_head()
        edges = list(keywordinstance.iter_edges(head))
        self.assertEqual(len(edges), 1)
        self.assertIsInstance(edges[0][1], unicode)
        self.assertEqual(edges[0][1], u'"SOPLETE"@en')
Exemplo n.º 4
0
    def interpret(self, match):
        """ Define the interpret method by using the dsl module to convert this into a sql query. """

        thing = match.target.tokens
        target = HasKeyword(thing)
        definition = IsDefinedIn(target)
        return definition
Exemplo n.º 5
0
    def interpret(self, match):
        employee_name = match.target.tokens

        # reset the HasKeyword relation
        HasKeyword.relation = "proatt:firstname"
        emp_id = HasKeyword(employee_name)

        solution = Hiredate(emp_id)

        return solution
Exemplo n.º 6
0
    def interpret(self, match):
        thing = match.target.tokens

        # reset the HasKeyword relation
        HasKeyword.relation = "proatt:firstname"
        pro_id = HasKeyword(thing)

        # find the position of those matched people
        solution = Position(pro_id)

        # return the so constructed pattern:
        return solution
Exemplo n.º 7
0
 def interpret(self, match):
     return HasKeyword(match.words.tokens)
Exemplo n.º 8
0
 def interpret(self, match):
     name = match.species.tokens
     species = IsSpecies() + HasKeyword(name)
     fat = FatOf(species)
     return fat, "enum"
Exemplo n.º 9
0
 def interpret(self, match):
     city = HasKeyword(match.city.tokens)
     restaurants = IsRestaurant() + CityOf(city)
     return NameOf(restaurants), "enum"
Exemplo n.º 10
0
    def interpret(self, match):
        thing = HasKeyword(match.thing.tokens)
        location = LocationOf(thing)
        location_name = LabelOf(location)

        return location_name, "enum"
Exemplo n.º 11
0
 def interpret(self, match):
     name = match.species.tokens
     species = IsSpecies() + HasKeyword(name)
     carbs = CarbsOf(species)
     return carbs, "enum"
Exemplo n.º 12
0
 def interpret(self, match):
     name = match.words.tokens
     return IsRestaurant() + HasKeyword(name)
Exemplo n.º 13
0
 def interpret(self, match):
     name = match.words.tokens
     return IsCountry() + HasKeyword(name)
Exemplo n.º 14
0
 def interpret(self, match):
     name = match.words.tokens
     return IsUniversity() + HasKeyword(name)
Exemplo n.º 15
0
 def interpret(self, match):
     name = match.species.tokens
     species = IsSpecies() + HasKeyword(name)
     protein = ProteinOf(species)
     return protein, "enum"
Exemplo n.º 16
0
 def interpret(self, match):
     name = match.words.tokens
     return IsManager() + HasKeyword(name)
Exemplo n.º 17
0
 def interpret(self, match):
     return HasKeyword(match.words[0].token), "<user data>"
Exemplo n.º 18
0
    def interpret(self, match):
        print('match')
        print(match.__dict__)

        print('match._match')
        print(match._match.__dict__)

        print('match.target')
        print(match.target.__dict__)

        # match.target exists just because of the Group(Movie(), "target")
        print('match.target.tokens')
        print(match.target.tokens)

        print('haskeyword')
        print(HasKeyword(match.target.tokens).__dict__)

        movie = IsMovie()
        movie_name = NameOf(movie)
        """
        {'nodes': [[(u'rdf:type', u'dbpedia-owl:Film'), ('foaf:name', 1)]], 'fixedtyperelation': u'rdf:type', 'head': 0, 'fixedtype': u'dbpedia-owl:Film'}
        """
        print('movie (ismovie)')
        print(movie.__dict__)
        """
        {'nodes': [[(u'rdf:type', u'dbpedia-owl:Film'), ('foaf:name', 1)], []], 'head': 1}
        """
        print('moviename (nameof(ismovie))')
        print(movie_name.__dict__)

        print('words are classes, not just simple texts')
        first_word = match.words[
            0]  # {'lemma': u'list', 'token': u'list', 'pos': u'NN', 'prob': None}
        second_word = match.words[
            1]  # {'lemma': u'movie', 'token': u'movies', 'pos': u'NNS', 'prob': None}
        print('first word')
        print(first_word.__dict__)
        print('second word')
        print(second_word.__dict__)

        print(match.target.tokens)

        matched_lemmas = [k.lemma for k in match.words]
        recent = u"recent" in matched_lemmas
        popular = u"popular" in matched_lemmas

        select_expressions = ["title"]

        if hasattr(match, 'genre'):
            tables = [u"genres"]
            condition_cols = [u"genre"]
            condition_values = [
                ''.join(match.genre.nodes[0][1][1].split('"')[:-1])
            ]
        else:
            tables = [u"title"]
            condition_cols = []
            condition_values = []
        generate_nodes_tables(movie_name,
                              tables,
                              select_expressions,
                              condition_cols=condition_cols,
                              condition_values=condition_values,
                              popular=popular,
                              recent=recent)
        movie_name.nodes[0] += " limit 10"  #[u'title like "'+match.movie+'"']
        print "nodes", movie_name.nodes
        print movie_name
        return movie_name, ("enum", "ListMoviesQuestion")
Exemplo n.º 19
0
 def interpret(self, match):
     name = match.words.tokens
     exp = IsPerson()
     exp.tables = ["directors"]
     return exp + HasKeyword(name)
Exemplo n.º 20
0
    def interpret(self, match):
        place = HasKeyword(match.place.lemmas.title()) + IsPlace()
        utc_offset = UTCof(place)

        return utc_offset, "time"
Exemplo n.º 21
0
 def interpret(self, match):
     name = match.words.tokens.title()
     return IsBand() + HasKeyword(name)
Exemplo n.º 22
0
 def interpret(self, match):
     name = match.words.tokens
     pronouns.his = name
     pronouns.her = name
     return IsPerson() + HasKeyword(name)
Exemplo n.º 23
0
    def test_has_keyword(self):

        HasKeyword.relation = u"uranium:keyword"
        keywordinstance = HasKeyword(u"soplete")

        head = keywordinstance.get_head()
        edges = list(keywordinstance.iter_edges(head))
        self.assertEqual(len(edges), 1)
        self.assertIsInstance(edges[0][0], unicode)
        self.assertEqual(edges[0][0], u"uranium:keyword")
        self.assertIsInstance(edges[0][1], unicode)
        self.assertEqual(edges[0][1], u'soplete')

        # With language
        HasKeyword.language = "en"
        keywordinstance = HasKeyword("soplete")

        head = keywordinstance.get_head()
        edges = list(keywordinstance.iter_edges(head))
        self.assertEqual(len(edges), 1)
        self.assertIsInstance(edges[0][1], unicode)
        self.assertEqual(edges[0][1], u'"soplete"@en')

        # With sanitize
        HasKeyword.sanitize = staticmethod(lambda x: x.upper())
        keywordinstance = HasKeyword(u"soplete")

        head = keywordinstance.get_head()
        edges = list(keywordinstance.iter_edges(head))
        self.assertEqual(len(edges), 1)
        self.assertIsInstance(edges[0][1], unicode)
        self.assertEqual(edges[0][1], u'"SOPLETE"@en')
Exemplo n.º 24
0
 def interpret(self, match):
     name = match.words.tokens
     return HasKeyword(name)
Exemplo n.º 25
0
 def interpret(self, match):
     thing = match.target.tokens
     target = HasKeyword(thing)
     definition = DefinitionOf(target)
     return definition, "define"
Exemplo n.º 26
0
 def interpret(self, match):
     name = match.words.tokens
     return IsLeague() + HasKeyword(name)
Exemplo n.º 27
0
 def interpret(self, match):
     name = match.words.tokens.title()
     return IsPopulatedPlace() + HasKeyword(name)
Exemplo n.º 28
0
 def interpret(self, match):
     name = match.words.tokens
     return dsl.IsVocab() + HasKeyword(name)
Exemplo n.º 29
0
 def interpret(self, match):
     name = match.words.tokens
     person = IsPerson()
     hasname = HasKeyword(name)
     person_hasname = person + hasname
     return person_hasname
Exemplo n.º 30
0
 def interpret(self, match):
     name = match.words.tokens
     return IsPerson() + HasKeyword(name)
Exemplo n.º 31
0
 def interpret(self, match):
     name = match.species.tokens
     species = IsSpecies() + HasKeyword(name)
     fiber = FiberOf(species)
     return fiber, "enum"