예제 #1
0
    def save_layer_categories(self, newLayer, categories):
        for lc in categories:
            newLayerCategories = Layers_Categories()
            newLayerCategories.layer_id = newLayer
            theCategory = Categories.objects.get(pk=lc['id'])
            theCategory = get_object_or_404(Categories,
                                            pk=get_value_or_none('id', lc))
            active_obj_or_raise_exeption(theCategory)

            if theCategory is not None:
                newLayerCategories.category_id = theCategory
                newLayerCategories.was_default = theCategory.is_default
                newLayerCategories.shortcut_key = get_value_or_none(
                    'shortcut_key', lc)
                newLayerCategories.save()
예제 #2
0
    def save_derived_categories(self, newLayer, categories):
        if newLayer.type == Constants.LAYER_TYPES_JSON['REFINEMENT']:
            for dlcc in categories:
                # save the derived_layer_category_category
                newDerivedLayerCategories = Derived_Layers_Categories_Categories(
                )
                newDerivedLayerCategories.layer_id = newLayer

                if dlcc['parent'] is not None and dlcc['parent'][
                        'id'] is not None:
                    parent_category = get_object_or_404(Categories,
                                                        id=get_value_or_none(
                                                            'id',
                                                            dlcc['parent']))
                    active_obj_or_raise_exeption(parent_category)

                if self.is_category_exsists_in_parent_layer(
                        parent_category, newLayer.parent_layer_id):
                    newDerivedLayerCategories.parent_category_id = parent_category

                    child_category = get_object_or_404(Categories,
                                                       id=get_value_or_none(
                                                           'id', dlcc))
                    active_obj_or_raise_exeption(child_category)

                    newDerivedLayerCategories.category_id = child_category
                    newDerivedLayerCategories.save()

        elif newLayer.type == Constants.LAYER_TYPES_JSON['COARSENING']:
            for dlcc in categories:
                # for parent_c_id in dlcc['parent_category']:
                newDerivedLayerCategories = Derived_Layers_Categories_Categories(
                )
                newDerivedLayerCategories.layer_id = newLayer

                if dlcc['parent'] is not None and dlcc['parent'][
                        'id'] is not None:
                    parent_category = get_object_or_404(
                        Categories, id=dlcc['parent']['id'])

                if self.is_category_exsists_in_parent_layer(
                        parent_category, newLayer.parent_layer_id):
                    newDerivedLayerCategories.parent_category_id = parent_category

                    category = get_object_or_404(Categories, id=dlcc['id'])
                    newDerivedLayerCategories.category_id = category

                    newDerivedLayerCategories.save()
예제 #3
0
    def create(self, validated_data):
        ownerUser = self.initial_data['created_by']
        validated_data['created_by'] = ownerUser

        source = get_object_or_404(Sources, pk= get_value_or_none('id',self.initial_data['source']) )

        active_obj_or_raise_exeption(source)
        validated_data['source'] = source

        texts_array = validated_data['text'].split("<DELIMITER>")

        for text in texts_array:
          validated_data['text'] = text
          newPassage = Passages.objects.create(**validated_data)

        return newPassage
예제 #4
0
    def create(self, validated_data):
        ownerUser = self.initial_data['created_by']
        validated_data['created_by'] = ownerUser
        project = get_object_or_404(Projects, pk=self.initial_data['project']['id'])
        annotator = get_object_or_404(Users, pk=get_value_or_none('id',get_value_or_none('user',self.initial_data))) # todo: when coarsening layer task - no need of annotator - check which one to set default?

        parent = None
        if self.initial_data['parent']:
            parent = get_object_or_404(Tasks, pk=get_value_or_none('id', self.initial_data['parent']))
            active_obj_or_raise_exeption(parent)

        newTask = Tasks()
        newTask.created_by = ownerUser
        newTask.parent_task = parent
        newTask.status = Constants.TASK_STATUS_JSON['NOT_STARTED']
        newTask.type = validated_data['type']
        newTask.is_demo = validated_data['is_demo']
        newTask.manager_comment = validated_data['manager_comment']
        newTask.user_comment = validated_data.get('user_comment','')
        
        # Omri Abend (Sep 13)
        # tasks cannot be created with is_active=True if their parent is not submitted
        if (newTask.parent_task and newTask.parent_task.status != Constants.TASK_STATUS_JSON['SUBMITTED']):
            newTask.is_active = False
        else:
            newTask.is_active = validated_data['is_active']

        newTask.project = project
        newTask.annotator = annotator

        if (newTask.type == Constants.TASK_TYPES_JSON['TOKENIZATION']):
            passage = get_object_or_404(Passages, pk=get_value_or_none('id',get_value_or_none('passage',self.initial_data)))
        else:
            passage = self.get_passage_by_parent_task(parent)

        newTask.passage = passage
        newTask.created_at = timezone.now()

        active_obj_or_raise_exeption(project)
        active_obj_or_raise_exeption(annotator)
        active_obj_or_raise_exeption(passage)

        if(newTask.type == Constants.TASK_TYPES_JSON['TOKENIZATION']):
            newTask.save()
            self.generate_and_save_tokens(newTask)
        elif(newTask.type == Constants.TASK_TYPES_JSON['ANNOTATION'] or (newTask.type == Constants.TASK_TYPES_JSON['REVIEW'])):
            if(self.has_parent_task(newTask) and self.parent_task_layer_is_my_parent_layer(newTask)): # and self.is_parent_task_submitted(newTask)):
                self.save_task_by_layer_type(newTask)

        return newTask