def connect_nodes(id1, label1, id2, label2): node1 = graph.find_one(label1, 'id', id1) node1.__primarylabel__ = label1 node1.__primarykey__ = 'id' node2 = graph.find_one(label2, 'id', id2) node2.__primarylabel__ = label2 node2.__primarykey__ = 'id' graph.merge(Relationship(node1, 'RELATED_TO', node2))
def give_feedback(self, primary_label, node_id, feedback): feedback_options = [ 'LIKE', 'DISLIKE', 'EASY', 'HARD', 'HELPFUL', 'UNHELPFUL', 'RELEVANT', 'IRRELEVANT' ] if feedback not in feedback_options: raise ValueError else: user = self.find() node = graph.find_one(primary_label, 'id', node_id) graph.merge(Relationship(user, feedback, node, timestamp=timestamp(), date=date()))
def view_fact(self, fact_id): user = self.find() fact = graph.find_one('Fact', 'id', fact_id) graph.merge(Relationship(user, 'VIEWED', fact, timestamp=timestamp(), date=date()))
def answer_question(self, question_id, answer): user = self.find() question = graph.find_one('Question', 'id', question_id) graph.merge(Relationship(user, 'ANSWERED', question, timestamp=timestamp(), date=date(), answer=answer))
def answer_incorrect(self, question_id): user = self.find() question = graph.find_one('Question', 'id', question_id) graph.merge(Relationship(user, 'ANSWERED_INCORRECTLY', question, timestamp=timestamp(), date=date()))
def view_question(self, question_id): user = self.find() question = graph.find_one('Question', 'id', question_id) graph.merge(Relationship(user, 'VIEWED', question, timestamp=timestamp(), date=date()))
def find(self): user = graph.find_one("User", "username", self.username) return user