Update database.py
Browse files37 unmodified lines3839404142434461 unmodified lines10610710810911011137 unmodified lines}def query(self, domain: str, state: dict, topk: int, ignore_open=False, soft_contraints=(), fuzzy_match_ratio=60) -> list:"""return a list of topk entities (dict containing slot-value pairs) for a given domain based on the dialogue state."""# query the dbif domain == 'taxi':return [{'taxi_colors': random.choice(self.dbs[domain]['taxi_colors']),61 unmodified linesdb = Database()assert issubclass(Database, BaseDatabase)assert isinstance(db, BaseDatabase)res = db.query("restaurant", [['price range', 'expensive']], topk=3)print(res, len(res))# print(db.query("hotel", [['price range', 'moderate'], ['stars','4'], ['type', 'guesthouse'], ['internet', 'yes'], ['parking', 'no'], ['area', 'east']]))37 unmodified lines3839404142434445464748495061 unmodified lines11211311411511611711811912037 unmodified lines}def query(self, domain: str, state: dict, topk: int, ignore_open=False, soft_contraints=(), fuzzy_match_ratio=60) -> list:"""return a list of topk entities (dict containing slot-value pairs) for a given domain based on the dialogue state.:param state: support two formats: 1) [[slot,value], [slot,value]...]; 2) {domain: {slot: value, slot: value...}} (the same as belief state)"""if isinstance(state, dict):assert domain in state, print(f"domain {domain} not in state {state}")state = state[domain].items()# query the dbif domain == 'taxi':return [{'taxi_colors': random.choice(self.dbs[domain]['taxi_colors']),61 unmodified linesdb = Database()assert issubclass(Database, BaseDatabase)assert isinstance(db, BaseDatabase)# both calls will be okres1 = db.query("restaurant", [['price range', 'expensive']], topk=3)res2 = db.query("restaurant", {'restaurant':{'price range': 'expensive'}}, topk=3)assert res1 == res2print(res1, len(res1))# print(db.query("hotel", [['price range', 'moderate'], ['stars','4'], ['type', 'guesthouse'], ['internet', 'yes'], ['parking', 'no'], ['area', 'east']]))
database.py+13-4