Example #1
0
def get_todays_recent_facts():
    query = '''
        MATCH (user:User)-[:PUBLISHED]->(fact:Fact)<-[:TAGGED]-(tag:Tag)
        WHERE fact.date = {today}
        RETURN user.username AS username, fact, COLLECT(tag.name) AS tags
        ORDER BY fact.timestamp DESC LIMIT 5
        '''
    return graph.run(query, today=date())
Example #2
0
def get_todays_recent_questions():
    query = '''
        MATCH (user:User)-[:PUBLISHED]->(question:Question)<-[:TAGGED]-(tag:Tag)
        WHERE question.date = {today}
        RETURN user.username AS username, question, COLLECT(tag.name) AS tags
        ORDER BY question.timestamp DESC LIMIT 5
        '''
    return graph.run(query, today=date())
Example #3
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)
Example #4
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)
Example #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)
Example #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()))
Example #7
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()))
Example #8
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))
Example #9
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()))
Example #10
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()))