def get_word_list_view(self, user: User) -> WordListView: # query = """ # optional match (u:User{email:"%s"})-[:Seen]->(wSeen:Word) # optional match (u)-[:Forgotten]->(wForgotten:Word) # optional match (u)-[:Learnt]->(wLearnt:Word) # return wSeen, wForgotten, wLearnt # """ % user.email query = """ match (u:User{email:"%s"})-[:Seen]->(wSeen:Word) return wSeen """ % user.email results = self._db.query(query) seen_list = WordModel.parse_words(results) query = """ match (u:User{email:"%s"})-[:Forgotten]->(wForgotten:Word) return wForgotten """ % user.email results = self._db.query(query) forgotten_list = WordModel.parse_words(results) query = """ match (u:User{email:"%s"})-[:Learnt]->(wLearnt:Word) return wLearnt """ % user.email results = self._db.query(query) learnt_list = WordModel.parse_words(results) # for element in results.elements: # seen_list.append(element[0]) # forgotten_list.append(element[1]) # learnt_list.append(element[2]) return WordListView(seen_list, learnt_list, forgotten_list)
def get_forgotten_words(self, user: User) -> list: try: query = """ MATCH (u:User{email:"%s"})-[:Forgotten]->(forgottenWords:Word) RETURN forgottenWords LIMIT %d """ % (user.email, self.word_set * 4) results = self._db.query(query) return WordModel.parse_words(results) except Exception as e: print(e) return []
def get_random_recommendation(self) -> list: try: query = """ MATCH (w:Word) WHERE rand() < 0.5 return w limit %d """ % (self.word_set * 4) results = self._db.query(query) return WordModel.parse_words(results) except Exception as e: print(e) return []
def get_recommended_words(self, user: User) -> list: try: query = """ MATCH (u:User{email:"%s"})-[:Seen]->(w)<-[:Seen]-(colleges:User), (colleges)-[:Seen]->(recW:Word) WHERE NOT (u)-[:Seen]->(recW) AND NOT (w)-[:Learnt]->(recW) AND NOT (w)-[:Forgotten]->(recW) RETURN recW LIMIT %d """ % (user.email, self.word_set * 4) results = self._db.query(query) return WordModel.parse_words(results) except Exception as e: print(e) return []