Esempio n. 1
0
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))
Esempio n. 2
0
    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()))
Esempio n. 3
0
    def add_fact(self, title, tags, text):
        user = self.find()
        fact = Node(
            'Fact',
            id = str(uuid.uuid4()),
            title = title,
            text = text,
            timestamp = timestamp(),
            date = date()
        )

        rel = Relationship(user, 'PUBLISHED', fact)
        graph.create(rel)

        tags = [x.strip() for x in tags.lower().split(',')]
        for name in set(tags):
            tag = Node('Tag', name=name)
            graph.merge(tag, 'Tag', 'name')
            rel = Relationship(tag, 'TAGGED', fact)
            graph.merge(rel)
Esempio n. 4
0
    def edit_fact(self, fact_id, title, tags, text):
        user = self.find()
        fact = Node(
            'Fact',
            id = fact_id,
            title = title,
            text = text,
            timestamp = timestamp(),
            date = date()
        )

        rel = Relationship(user, 'EDITED', fact)
        graph.merge(rel, 'Fact', 'id')

        tags = [x.strip() for x in tags.lower().split(',')]
        for name in set(tags):
            tag = Node('Tag', name=name)
            graph.merge(tag, 'Tag', 'name')
            rel = Relationship(tag, 'TAGGED', fact)
            graph.merge(rel)
Esempio n. 5
0
    def edit_question(self, question_id, title, tags, text, answer):
        user = self.find()
        question = Node(
            'Question',
            id = question_id,
            title = title,
            text = text,
            answer = answer,
            timestamp = timestamp(),
            date = date()
        )

        rel = Relationship(user, 'EDITED', question)
        graph.merge(rel, 'Question', 'id')

        tags = [x.strip() for x in tags.lower().split(',')]
        for name in set(tags):
            tag = Node('Tag', name=name)
            graph.merge(tag, 'Tag', 'name')
            rel = Relationship(tag, 'TAGGED', question)
            graph.merge(rel)
Esempio n. 6
0
 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()))
Esempio n. 7
0
 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))
Esempio n. 8
0
    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()))
Esempio n. 9
0
 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()))