Пример #1
0
def add_contrast(request, task_id):
    '''add_contrast is the function called when the user submits a set of conditions and an operator to specify
    a new contrast.
    :param task_id: the id of the task, to return to the correct page after submission
    '''
    if request.method == "POST":
        relation_type = "HASCONTRAST"  #condition --HASCONTRAST-> contrast

        # Get fields from post
        post = dict(request.POST)
        #pickle.dump(post,open('result.pkl','wb'))
        contrast_name = post.get('contrast_name', '')
        skip = ["contrast_name", "csrfmiddlewaretoken"]

        # Get dictionary with new conditions with nonzero weights
        conditions = dict()
        condition_ids = [x for x in post.keys() if x not in skip]
        for condition_id in condition_ids:
            weight = int(post.get(condition_id, 0)[0])
            if weight != 0:
                conditions[condition_id] = weight

        if contrast_name != "" and len(conditions) > 0:
            node = Contrast.create(name=contrast_name)

            # Make a link between contrast and conditions, specify side as property of relation
            for condition_id, weight in conditions.items():
                properties = {"weight": weight}
                Condition.link(condition_id,
                               node["id"],
                               relation_type,
                               endnode_type="contrast",
                               properties=properties)

    return view_task(request, task_id)
Пример #2
0
 def setUp(self):
     self.task = Task()
     self.node_name = "test_name"
     self.node_properties = {'test_key': 'test_value'}
     self.graph = Graph("http://graphdb:7474/db/data/")
     self.task1 = self.task.create(
         name=self.node_name,
         properties=self.node_properties)
     self.task2 = self.task.create(
         name=self.node_name,
         properties=self.node_properties)
     condition = Condition()
     self.cond = condition.create(
         name=self.node_name,
         properties=self.node_properties)
     contrast = Contrast()
     self.cont = contrast.create(
         name=self.node_name,
         properties=self.node_properties)
     concept = Concept()
     self.con = concept.create(
         name=self.node_name,
         properties=self.node_properties)
     self.task.link(
         self.task1.properties['id'],
         self.cond.properties['id'],
         "HASCONDITION",
         endnode_type='condition')
     self.task.link(
         self.task1.properties['id'],
         self.con.properties['id'],
         "ASSERTS",
         endnode_type='concept')
     condition.link(
         self.cond.properties['id'],
         self.cont.properties['id'],
         "HASCONTRAST",
         endnode_type='contrast')
     concept.link(
         self.con.properties['id'],
         self.cont.properties['id'],
         "MEASUREDBY",
         endnode_type='contrast')