当前位置: 首页>>代码示例>>Python>>正文


Python models.Entity类代码示例

本文整理汇总了Python中opencontext_py.apps.entities.entity.models.Entity的典型用法代码示例。如果您正苦于以下问题:Python Entity类的具体用法?Python Entity怎么用?Python Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: id_summary

def id_summary(request, identifier):
    """ Returns JSON data for entities
        limited by certain criteria
    """
    lequiv = LinkEquivalence()
    id_list = lequiv.get_identifier_list_variants(identifier)
    entity_obj = False
    for test_id in id_list:
        ent = Entity()
        ent.get_stable_ids = True
        found = ent.dereference(test_id)
        if found:
            entity_obj = LastUpdatedOrderedDict()
            entity_obj['id'] = ent.uri
            entity_obj['label'] = ent.label
            entity_obj['uuid'] = ent.uuid
            entity_obj['slug'] = ent.slug
            entity_obj['item_type'] = ent.item_type
            entity_obj['class_uri'] = ent.class_uri
            entity_obj['data_type'] = ent.data_type
            entity_obj['vocab_uri'] = ent.vocab_uri
            entity_obj['project_uuid'] = ent.project_uuid
            entity_obj['stable_id_uris'] = ent.stable_id_uris
            break
    if entity_obj is not False:
        json_output = json.dumps(entity_obj,
                                 indent=4,
                                 ensure_ascii=False)
        return HttpResponse(json_output,
                            content_type='application/json; charset=utf8')
    else:
        raise Http404
开发者ID:ekansa,项目名称:open-context-py,代码行数:32,代码来源:views.py

示例2: make_trinomial_from_site_labels

 def make_trinomial_from_site_labels(self,
                                     project_uuid,
                                     state_prefix=''):
     """ makes trinomial identifiers from a site label """
     ent = Entity()
     found = ent.dereference(project_uuid)
     if found:
         proj_label = ent.label
         sites = Manifest.objects\
                         .filter(project_uuid=project_uuid,
                                 class_uri='oc-gen:cat-site')
         for site in sites:
             trinomial = str(state_prefix) + site.label
             if '*' in trinomial:
                 # for North Carolina, only the part before the '*' is a trinomial
                 tr_ex = trinomial.split('*')
                 trinomial = tr_ex[0]
             print('working on (' + site.uuid + '): ' + trinomial)
             parts = self.parse_trinomial(trinomial)
             if 'Tennessee' in proj_label:
                 trinomial = parts['state'] + parts['county'] + str(parts['site'])
             dt = Trinomial()
             dt.uri = URImanagement.make_oc_uri(site.uuid, site.item_type)
             dt.uuid = site.uuid
             dt.label = site.label
             dt.project_label = proj_label
             dt.trinomial = trinomial
             dt.state = parts['state']
             dt.county = parts['county']
             dt.site = parts['site']
             try:
                 dt.save()
                 print('Trinomial: ' + trinomial + ', from: ' + site.label)
             except:
                 print('Trinomial: ' + trinomial + ' not valid as a trinomial')
开发者ID:ekansa,项目名称:open-context-py,代码行数:35,代码来源:manage.py

示例3: get_parent_slug_by_slug

 def get_parent_slug_by_slug(self, child_slug):
     """ gets the slug for a parent item
         from a child item's slug
     """
     self.recurse_count = 0
     self.contexts_list = []
     self.contexts = {}
     output = False
     ent = Entity()
     found = ent.dereference(child_slug)
     if found:
         self.get_parents_by_child_uuid(ent.uuid, False)
         if len(self.contexts_list) > 0:
             parent_uuid = self.contexts_list[0]
             # clear class so we can use this again
             self.contexts_list = []
             self.contexts = {}
             self.recurse_count = 0
             ent_p = Entity()
             found_p = ent_p.dereference(parent_uuid)
             if found_p:
                 output = ent_p.slug
             else:
                 print('Cannot dereference parent_uuid: ' + parent_uuid)
         else:
             # print('No parent item found. (Root Context)')
             pass
     else:
         print('Cannot find the item for slug: ' + child_slug)
     return output
开发者ID:ekansa,项目名称:open-context-py,代码行数:30,代码来源:containment.py

示例4: get_identifier_list_variants

 def get_identifier_list_variants(self, id_list):
     """ makes different variants of identifiers
         for a list of identifiers
     """
     output_list = []
     if not isinstance(id_list, list):
         id_list = [str(id_list)]
     for identifier in id_list:
         output_list.append(identifier)
         if(identifier[:7] == 'http://' or identifier[:8] == 'https://'):
             oc_uuid = URImanagement.get_uuid_from_oc_uri(identifier)
             if oc_uuid is not False:
                 output_list.append(oc_uuid)
             else:
                 prefix_id = URImanagement.prefix_common_uri(identifier)
                 output_list.append(prefix_id)
         elif ':' in identifier:
             full_uri = URImanagement.convert_prefix_to_full_uri(identifier)
             output_list.append(full_uri)
         else:
             # probably an open context uuid or a slug
             ent = Entity()
             found = ent.dereference(identifier)
             if found:
                 full_uri = ent.uri
                 output_list.append(full_uri)
                 prefix_uri = URImanagement.prefix_common_uri(full_uri)
                 if prefix_uri != full_uri:
                     output_list.append(prefix_uri)
     return output_list
开发者ID:portableant,项目名称:open-context-py,代码行数:30,代码来源:equivalence.py

示例5: make_trinomial_from_site_labels

 def make_trinomial_from_site_labels(self,
                                     project_uuid,
                                     state_prefix=''):
     """ makes trinomial identifiers from a site label """
     ent = Entity()
     found = ent.dereference(project_uuid)
     if found:
         proj_label = ent.label
         sites = Manifest.objects\
                         .filter(project_uuid=project_uuid,
                                 class_uri='oc-gen:cat-site')
         for site in sites:
             trinomial = str(state_prefix) + site.label
             parts = self.parse_trinomial(trinomial)
             dt = Trinomial()
             dt.uri = URImanagement.make_oc_uri(site.uuid, site.item_type)
             dt.uuid = site.uuid
             dt.label = site.label
             dt.project_label = proj_label
             dt.trinomial = trinomial
             dt.state = parts['state']
             dt.county = parts['county']
             dt.site = parts['site']
             dt.save()
             print('Trinomial: ' + trinomial + ', from: ' + site.label)
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:25,代码来源:manage.py

示例6: set_project_label

 def set_project_label(self):
     """ sets the project label """
     if self.project_uuid is not False and self.project_label is False:
         ent = Entity()
         found = ent.dereference(self.project_uuid)
         if found:
             self.project_label = ent.label
开发者ID:ekansa,项目名称:open-context-py,代码行数:7,代码来源:navtemplate.py

示例7: make_dict_from_field_obj

 def make_dict_from_field_obj(self, field_obj):
     """ returns an ordered dict for a field_obj """
     field_dict = LastUpdatedOrderedDict()
     field_dict['field_num'] = field_obj.field_num
     field_dict['label'] = field_obj.label
     field_dict['ref_name'] = field_obj.ref_name
     field_dict['field_type'] = field_obj.field_type
     field_dict['field_data_type'] = field_obj.field_data_type
     field_dict['field_value_cat'] = field_obj.field_value_cat
     field_dict['obs_num'] = field_obj.obs_num
     field_dict['value_prefix'] = field_obj.value_prefix
     field_dict['unique_count'] = field_obj.unique_count
     field_dict['f_uuid'] = field_obj.f_uuid
     if self.get_examples:
         field_dict['examples'] = self.get_example_entities(field_obj.field_num,
                                                            field_obj.value_prefix)
         field_dict['ex_csv'] = ', '.join(field_dict['examples'])
         if len(field_obj.field_value_cat) > 0:
             ent = Entity()
             ent.get_icon = True
             found = ent.dereference(field_obj.field_value_cat)
             if found:
                 field_dict['field_value_cat_label'] = ent.label
                 field_dict['field_value_cat_icon'] = ent.icon
     return field_dict
开发者ID:ekansa,项目名称:open-context-py,代码行数:25,代码来源:templating.py

示例8: get_jsonldish_parents

    def get_jsonldish_parents(self, uuid, add_original=True):
        """
        Gets parent projects for a project.
        Returns a list of dictionary objects similar to JSON-LD expectations
        This is useful for faceted search

        If add_original is true, add the original UUID for the entity
        that's the childmost item, at the bottom of the hierarchy
        """
        output = False
        raw_parents = self.get_parents(uuid)
        if(add_original):
            # add the original identifer to the list of parents, at lowest rank
            raw_parents.insert(0, uuid)
        if len(raw_parents) > 0:
            # reverse the order of the list, to make top most concept
            # first
            output = []
            parents = raw_parents[::-1]
            for par_id in parents:
                ent = Entity()
                found = ent.dereference(par_id)
                if(found):
                    p_item = LastUpdatedOrderedDict()
                    p_item['id'] = ent.uri
                    p_item['slug'] = ent.slug
                    p_item['label'] = ent.label
                    if(ent.data_type is not False):
                        p_item['type'] = ent.data_type
                    else:
                        p_item['type'] = '@id'
                    output.append(p_item)
        return output
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:33,代码来源:metadata.py

示例9: get_subject_type_fields

 def get_subject_type_fields(self, field_num_list=False):
     """ Gets a list of subject-type field objects,
         limited by a list of field_num if not false
     """
     self.get_examples = True
     if field_num_list is not False:
         imp_fields = ImportField.objects\
                                 .filter(source_id=self.source_id,
                                         field_type__in=self.DEFAULT_SUBJECT_TYPE_FIELDS,
                                         field_num__in=field_num_list)
     else:
         imp_fields = ImportField.objects\
                                 .filter(source_id=self.source_id,
                                         field_type__in=self.DEFAULT_SUBJECT_TYPE_FIELDS)
     for field_obj in imp_fields:
         if field_obj.field_type == 'media':
             self.has_media_field = True
         if field_obj.field_type == 'documents':
             self.has_doc_field = True
         if field_obj.field_type == 'complex-description':
             self.has_complex_des_field = True
         field_obj.examples = self.get_example_entities(field_obj.field_num,
                                                        field_obj.value_prefix)
         field_obj.ex_csv = ', '.join(field_obj.examples)
         if len(field_obj.field_value_cat) > 0:
             ent = Entity()
             ent.get_icon = True
             found = ent.dereference(field_obj.field_value_cat)
             if found:
                 field_obj.field_value_cat_label = ent.label
                 field_obj.field_value_cat_icon = ent.icon
         else:
             field_obj.field_value_cat_icon = False
             field_obj.field_value_cat_label = ''
         self.fields.append(field_obj)
开发者ID:ekansa,项目名称:open-context-py,代码行数:35,代码来源:templating.py

示例10: create_template_for_entity

 def create_template_for_entity(self, entity):
     """ creates a template for diplaying a
         concept or vocabulary entity, either in
         HTML or in JSON
     """
     self.entity = entity
     self.uri = entity.uri
     self.vocab_uri = entity.vocab_uri
     self.project_uuid = entity.project_uuid
     # add the version control uri
     for vocab_key, version_uri in self.VERSION_CONTROL_LINKS.items():
         if vocab_key == self.vocab_uri:
             self.version_control_uri = version_uri
             break
     self.get_comments()  # always get comments for the entity
     if self.uri == self.vocab_uri:
         # we have a vocabulary so do vocab methods
         self.vocab_entity = entity
         self.get_root_entities()
     else:
         # we have a concept in a vocabulary, so do
         # concept methods
         ent_voc = Entity()
         vocab_found = ent_voc.dereference(self.vocab_uri)
         if vocab_found:
             # found the parent vocab entity
             self.vocab_entity = ent_voc
         self.get_entity_parents()
         self.get_entity_children()
开发者ID:ekansa,项目名称:open-context-py,代码行数:29,代码来源:templating.py

示例11: contain_children

def contain_children(request, identifier):
    """ Returns JSON data with
        spatial containment for a given
        uuid identiffied entity
    """
    ent = Entity()
    found = ent.dereference(identifier)
    if found:
        depth = 1
        recursive = False
        if 'depth' in request.GET:
            try:
                depth = int(float(request.GET['depth']))
            except:
                depth = 1
        et = EntityTemplate()
        children = et.get_containment_children(ent,
                                               depth)
        json_output = json.dumps(children,
                                 indent=4,
                                 ensure_ascii=False)
        return HttpResponse(json_output,
                            content_type='application/json; charset=utf8')
    else:
        raise Http404
开发者ID:ekansa,项目名称:open-context-py,代码行数:25,代码来源:views.py

示例12: get_entity_db

 def get_entity_db(self, identifier, context_id, is_path=False):
     """ returns an entity object
         via database calls
     """
     output = False
     found = False
     entity = Entity()
     if is_path:
         found = entity.context_dereference(identifier)
     else:
         found = entity.dereference(identifier)
         if found is False:
             # case of linked data slugs
             found = entity.dereference(identifier, identifier)
     if found:
         if is_path:
             self.entities[context_id] = entity
         else:
             self.entities[identifier] = entity
         if entity.uuid is not False:
             self.entities[entity.uuid] = entity
         if entity.slug is not False:
             self.entities[entity.slug] = entity
         output = entity
     return output
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:25,代码来源:memorycache.py

示例13: project_annotations_ttl

def project_annotations_ttl(request, identifier):
    """ Returns RDF open annotation assertions conforming to
        Pelagios specifications that link
        Open Context resources with place entities in
        gazetteers, in the turtle format
    """
    ent = Entity()
    found = ent.dereference(identifier)
    if found:
        if ent.item_type == 'projects':
            pp = ProjectPermissions(ent.uuid)
            permitted = pp.view_allowed(request)
            if permitted:
                pelagios = PelagiosGraph()
                pelagios.project_uuids = [ent.uuid]
                pelagios.test_limit = None
                pelagios.make_graph()
                # default to outputting in turtle
                output = pelagios.g.serialize(format='turtle')
                return HttpResponse(output,
                                    content_type='text/turtle; charset=utf8')
            else:
                return HttpResponse('Not authorized to get this resource',
                                    content_type='text/html; charset=utf8',
                                    status=401)
        else:
            found = False
    if found is False:
        raise Http404
开发者ID:mfindeisen,项目名称:open-context-py,代码行数:29,代码来源:views.py

示例14: make_dict_from_anno_obj

 def make_dict_from_anno_obj(self, anno_obj):
     """ returns an ordered dict for an import field annotation object """
     anno_dict = LastUpdatedOrderedDict()
     anno_dict['id'] = anno_obj.id
     sub_field_obj = self.get_field_object(anno_obj.field_num)
     if sub_field_obj is not False:
         anno_dict['subject'] = self.make_dict_from_field_obj(sub_field_obj)
         anno_dict['subject']['id'] = anno_obj.field_num
     else:
         anno_dict['subject'] = False
     if anno_obj.predicate_field_num > 0:
         pred_field_obj = self.get_field_object(anno_obj.predicate_field_num)
         anno_dict['predicate'] = self.make_dict_from_field_obj(pred_field_obj)
         anno_dict['predicate']['id'] = anno_obj.predicate_field_num
         anno_dict['predicate']['type'] = 'import-field'
     else:
         anno_dict['predicate'] = LastUpdatedOrderedDict()
         anno_dict['predicate']['id'] = anno_obj.predicate
         ent = Entity()
         found = ent.dereference(anno_obj.predicate)
         if found:
             anno_dict['predicate']['label'] = ent.label
             anno_dict['predicate']['type'] = ent.item_type
         elif anno_obj.predicate == ImportFieldAnnotation.PRED_CONTAINED_IN:
             anno_dict['predicate']['label'] = 'Contained in'
         elif anno_obj.predicate == ImportFieldAnnotation.PRED_DESCRIBES:
             anno_dict['predicate']['label'] = 'Describes'
         elif anno_obj.predicate == ImportFieldAnnotation.PRED_VALUE_OF:
             anno_dict['predicate']['label'] = 'Value of'
         elif anno_obj.predicate == ImportFieldAnnotation.PRED_MEDIA_PART_OF:
             anno_dict['predicate']['label'] = 'Media part of'
         elif anno_obj.predicate == ImportFieldAnnotation.PRED_DOC_Text:
             anno_dict['predicate']['label'] = 'Has document text'
         elif anno_obj.predicate == ImportFieldAnnotation.PRED_DRAFT_CONTAINS:
             anno_dict['predicate']['label'] = 'Contains (part. hierarchy)'
         elif anno_obj.predicate == ImportFieldAnnotation.PRED_COMPLEX_DES:
             anno_dict['predicate']['label'] = 'Has Complex Description'
         elif anno_obj.predicate == ImportFieldAnnotation.PRED_OBS_NUM:
             anno_dict['predicate']['label'] = 'Is Observation Number Of'
         else:
             anno_dict['predicate']['label'] = False
             anno_dict['predicate']['type'] = False
     if anno_obj.object_field_num > 0:
         obj_field_obj = self.get_field_object(anno_obj.object_field_num)
         anno_dict['object'] = self.make_dict_from_field_obj(obj_field_obj)
         anno_dict['object']['id'] = anno_obj.object_field_num
         anno_dict['object']['type'] = 'import-field'
     else:
         anno_dict['object'] = LastUpdatedOrderedDict()
         anno_dict['object']['id'] = anno_obj.object_uuid
         ent = Entity()
         found = ent.dereference(anno_obj.object_uuid)
         if found:
             anno_dict['object']['label'] = ent.label
             anno_dict['object']['type'] = ent.item_type
         else:
             anno_dict['object']['label'] = False
             anno_dict['object']['type'] = False
     return anno_dict
开发者ID:ekansa,项目名称:open-context-py,代码行数:59,代码来源:templating.py

示例15: augment_projects

 def augment_projects(self):
     """ adds some additional informaiton about projects
         to make them easier to display
     """
     uuids = []
     for proj_r in self.raw_records:
         uuids.append(proj_r.uuid)
     # now query the database for all the records with these uuids
     proj_objs = Project.objects\
                        .filter(uuid__in=uuids)
     # now make a dict object to easily get project info by a UUID key
     proj_obj_dict = {}
     for proj_obj in proj_objs:
         proj_obj_dict[proj_obj.uuid] = proj_obj
     # now query the database for all of the dc related predicates
     le = LinkEquivalence()
     subjects = le.get_identifier_list_variants(uuids)
     predicates = le.get_identifier_list_variants(self.DC_META_PREDS)
     dc_annos = LinkAnnotation.objects\
                              .filter(subject__in=subjects,
                                      predicate_uri__in=predicates)
     # now make a dict object to easily get annotations by UUID key
     dc_anno_dict = {}
     for dc_anno in dc_annos:
         dc_pred = URImanagement.prefix_common_uri(dc_anno.predicate_uri)
         dc_pred = dc_pred.replace('dc-terms:', '')  # remove namespace prefix
         if dc_anno.subject not in dc_anno_dict:
             dc_anno_dict[dc_anno.subject] = {}
         if dc_pred not in dc_anno_dict[dc_anno.subject]:
             dc_anno_dict[dc_anno.subject][dc_pred] = []
         if dc_anno.object_uri not in dc_anno_dict[dc_anno.subject][dc_pred]:
             dc_anno_dict[dc_anno.subject][dc_pred].append(dc_anno.object_uri)
     # now add information we got from queries and organized into dicts
     # to the project response objects
     for proj_r in self.raw_records:
         if proj_r.uuid in proj_obj_dict:
             # add projects objects from the database
             proj_r.extra = proj_obj_dict[proj_r.uuid]
         if proj_r.uuid in dc_anno_dict:
             # add annotations from the database
             proj_r.dc = {'meta': []}
             for pred, object_uris in dc_anno_dict[proj_r.uuid].items():
                 proj_r.dc[pred] = []
                 for object_uri in object_uris:
                     ent = Entity()
                     found = ent.dereference(object_uri)
                     if found:
                         obj_obj = {'id': object_uri,
                                    'label': ent.label}
                         if ent.item_type == 'uri':
                             obj_obj['href'] = ent.uri
                         else:
                             obj_obj['href'] = self.base_url \
                                               + '/' + ent.item_type \
                                               + '/' + ent.uuid
                         proj_r.dc[pred].append(obj_obj)
                         if pred != 'creator' and pred != 'temporal':
                             proj_r.dc['meta'].append(obj_obj)
         self.records.append(proj_r)  # now append the augmented record   
开发者ID:ekansa,项目名称:open-context-py,代码行数:59,代码来源:projtemplating.py


注:本文中的opencontext_py.apps.entities.entity.models.Entity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。