Exemplo n.º 1
0
 def get_triples_from_sub_type(cls,
                               subject_id,
                               gt_or_rt_name_or_id,
                               status=None):
     '''
     getting triples from SUBject and TYPE (attribute_type or relation_type)
     '''
     triple_node_mapping_dict = {
         'GAttribute': 'AttributeType',
         'GRelation': 'RelationType'
     }
     triple_class_field_mapping_dict = {
         'GAttribute': 'attribute_type',
         'GRelation': 'relation_type'
     }
     gr_or_rt_name, gr_or_rt_id = Node.get_name_id_from_type(
         gt_or_rt_name_or_id, triple_node_mapping_dict[get_model_name(cls)])
     status = [status] if status else ['PUBLISHED', 'DELETED']
     return triple_collection.find({
         '_type':
         get_model_name(cls),
         'subject':
         ObjectId(subject_id),
         triple_class_field_mapping_dict[get_model_name(cls)]:
         gr_or_rt_id,
         'status': {
             '$in': status
         }
     })
Exemplo n.º 2
0
    def get_triples_from_sub_type_list(cls,
                                       subject_id,
                                       gt_or_rt_name_or_id_list,
                                       status=None,
                                       get_obj=True):
        '''
        getting triples from SUBject and TYPE (attribute_type or relation_type)
        '''
        triple_node_mapping_dict = {
            'GAttribute': 'AttributeType',
            'GRelation': 'RelationType'
        }
        triple_class_field_mapping_dict = {
            'GAttribute': 'attribute_type',
            'GRelation': 'relation_type'
        }
        triple_class_field_mapping_key_dict = {
            'GAttribute': 'object_value',
            'GRelation': 'right_subject'
        }

        if not isinstance(gt_or_rt_name_or_id_list, list):
            gt_or_rt_name_or_id_list = [gt_or_rt_name_or_id_list]

        gt_or_rt_id_name_dict = {}
        for each_gr_or_rt in gt_or_rt_name_or_id_list:
            gr_or_rt_name, gr_or_rt_id = Node.get_name_id_from_type(
                each_gr_or_rt, triple_node_mapping_dict[get_model_name(cls)])
            gt_or_rt_id_name_dict.update({gr_or_rt_id: gr_or_rt_name})

        status = [status] if status else ['PUBLISHED', 'DELETED']

        tr_cur = triple_collection.find({
            '_type': get_model_name(cls),
            'subject': ObjectId(subject_id),
            triple_class_field_mapping_dict[get_model_name(cls)]: {
                '$in': gt_or_rt_id_name_dict.keys()
            },
            'status': {
                '$in': status
            }
        })

        gt_or_rt_name_value_or_obj_dict = {
            gt_or_rt: ''
            for gt_or_rt in gt_or_rt_name_or_id_list
        }
        for each_tr in tr_cur:
            gt_or_rt_name_value_or_obj_dict[gt_or_rt_id_name_dict[each_tr[
                triple_class_field_mapping_dict[get_model_name(
                    cls)]]]] = each_tr if get_obj else each_tr[
                        triple_class_field_mapping_key_dict[get_model_name(
                            cls)]]
        return gt_or_rt_name_value_or_obj_dict
Exemplo n.º 3
0
 def get_triples_from_sub_type(cls, subject_id, gt_or_rt_name_or_id, status=None):
       '''
       getting triples from SUBject and TYPE (attribute_type or relation_type)
       '''
       triple_node_mapping_dict = {
           'GAttribute': 'AttributeType',
           'GRelation': 'RelationType'
       }
       triple_class_field_mapping_dict = {
           'GAttribute': 'attribute_type',
           'GRelation': 'relation_type'
       }
       gr_or_rt_name, gr_or_rt_id = Node.get_name_id_from_type(gt_or_rt_name_or_id,
           triple_node_mapping_dict[get_model_name(cls) ])
       status = [status] if status else ['PUBLISHED', 'DELETED']
       return triple_collection.find({
                                   '_type': get_model_name(cls),
                                   'subject': ObjectId(subject_id),
                                   triple_class_field_mapping_dict[get_model_name(cls)]: gr_or_rt_id,
                                   'status': {'$in': status}
                               })
Exemplo n.º 4
0
  def get_triples_from_sub_type_list(cls, subject_id, gt_or_rt_name_or_id_list, status=None, get_obj=True):
        '''
        getting triples from SUBject and TYPE (attribute_type or relation_type)
        '''
        triple_node_mapping_dict = {
            'GAttribute': 'AttributeType',
            'GRelation': 'RelationType'
        }
        triple_class_field_mapping_dict = {
            'GAttribute': 'attribute_type',
            'GRelation': 'relation_type'
        }
        triple_class_field_mapping_key_dict = {
            'GAttribute': 'object_value',
            'GRelation': 'right_subject'
        }

        if not isinstance(gt_or_rt_name_or_id_list, list):
            gt_or_rt_name_or_id_list = [gt_or_rt_name_or_id_list]

        gt_or_rt_id_name_dict = {}
        for each_gr_or_rt in gt_or_rt_name_or_id_list:
            gr_or_rt_name, gr_or_rt_id = Node.get_name_id_from_type(each_gr_or_rt,
                triple_node_mapping_dict[get_model_name(cls)])
            gt_or_rt_id_name_dict.update({gr_or_rt_id: gr_or_rt_name})

        status = [status] if status else ['PUBLISHED', 'DELETED']

        tr_cur = triple_collection.find({
                                    '_type': get_model_name(cls),
                                    'subject': ObjectId(subject_id),
                                    triple_class_field_mapping_dict[get_model_name(cls)]: {'$in': gt_or_rt_id_name_dict.keys()},
                                    'status': {'$in': status}
                                })

        gt_or_rt_name_value_or_obj_dict = {gt_or_rt: '' for gt_or_rt in gt_or_rt_name_or_id_list}
        for each_tr in tr_cur:
            gt_or_rt_name_value_or_obj_dict[gt_or_rt_id_name_dict[each_tr[triple_class_field_mapping_dict[get_model_name(cls)]]]] = each_tr if get_obj else each_tr[triple_class_field_mapping_key_dict[get_model_name(cls)]]
        return gt_or_rt_name_value_or_obj_dict