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"
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
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')
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
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
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
def interpret(self, match): return HasKeyword(match.words.tokens)
def interpret(self, match): name = match.species.tokens species = IsSpecies() + HasKeyword(name) fat = FatOf(species) return fat, "enum"
def interpret(self, match): city = HasKeyword(match.city.tokens) restaurants = IsRestaurant() + CityOf(city) return NameOf(restaurants), "enum"
def interpret(self, match): thing = HasKeyword(match.thing.tokens) location = LocationOf(thing) location_name = LabelOf(location) return location_name, "enum"
def interpret(self, match): name = match.species.tokens species = IsSpecies() + HasKeyword(name) carbs = CarbsOf(species) return carbs, "enum"
def interpret(self, match): name = match.words.tokens return IsRestaurant() + HasKeyword(name)
def interpret(self, match): name = match.words.tokens return IsCountry() + HasKeyword(name)
def interpret(self, match): name = match.words.tokens return IsUniversity() + HasKeyword(name)
def interpret(self, match): name = match.species.tokens species = IsSpecies() + HasKeyword(name) protein = ProteinOf(species) return protein, "enum"
def interpret(self, match): name = match.words.tokens return IsManager() + HasKeyword(name)
def interpret(self, match): return HasKeyword(match.words[0].token), "<user data>"
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")
def interpret(self, match): name = match.words.tokens exp = IsPerson() exp.tables = ["directors"] return exp + HasKeyword(name)
def interpret(self, match): place = HasKeyword(match.place.lemmas.title()) + IsPlace() utc_offset = UTCof(place) return utc_offset, "time"
def interpret(self, match): name = match.words.tokens.title() return IsBand() + HasKeyword(name)
def interpret(self, match): name = match.words.tokens pronouns.his = name pronouns.her = name return IsPerson() + HasKeyword(name)
def interpret(self, match): name = match.words.tokens return HasKeyword(name)
def interpret(self, match): thing = match.target.tokens target = HasKeyword(thing) definition = DefinitionOf(target) return definition, "define"
def interpret(self, match): name = match.words.tokens return IsLeague() + HasKeyword(name)
def interpret(self, match): name = match.words.tokens.title() return IsPopulatedPlace() + HasKeyword(name)
def interpret(self, match): name = match.words.tokens return dsl.IsVocab() + HasKeyword(name)
def interpret(self, match): name = match.words.tokens person = IsPerson() hasname = HasKeyword(name) person_hasname = person + hasname return person_hasname
def interpret(self, match): name = match.words.tokens return IsPerson() + HasKeyword(name)
def interpret(self, match): name = match.species.tokens species = IsSpecies() + HasKeyword(name) fiber = FiberOf(species) return fiber, "enum"