Returns a new linked data element for the given resource object.

        :returns: object implementing :class:`ILinkedDataElement`.
173228
def create_linked_data_element_from_resource(self, resource):
        
        mp = self.__mp_reg.find_or_create_mapping(Link)
        return mp.data_element_class.create_from_resource(resource)
758142
def get_linked_metadata(obj, name=None, context=None, site=None, language=None):
    
    # XXX Check that 'modelinstance' and 'model' metadata are installed in backends
    # I believe that get_model() would return None if not
    Metadata = _get_metadata_model(name)
    InstanceMetadata = Metadata._meta.get_model('modelinstance')
    ModelMetadata = Metadata._meta.get_model('model')
    content_type = ContentType.objects.get_for_model(obj)
    instances = []
    if InstanceMetadata is not None:
        try:
            instance_md = InstanceMetadata.objects.get(_content_type=content_type, _object_id=obj.pk)
        except InstanceMetadata.DoesNotExist:
            instance_md = InstanceMetadata(_content_object=obj)
        instances.append(instance_md)
    if ModelMetadata is not None:
        try:
            model_md = ModelMetadata.objects.get(_content_type=content_type)
        except ModelMetadata.DoesNotExist:
            model_md = ModelMetadata(_content_type=content_type)
        instances.append(model_md)    
    return FormattedMetadata(Metadata, instances, '', site, language)
1037421
def element_from_dom_node(obj, identifier_string = nil)
      element_class = Util.htmlunit2celerity(obj.class) || Element
      element = element_class.new(self, :object, obj)

      element.identifier_string = identifier_string
      element.extend(ClickableElement) unless element.is_a?(ClickableElement)

      element
    end
1285091
def extract_links_from_reference(self, short_id):
        
        logging.debug('Gathering resource URLs for short_id <%s>.', short_id)

        try:
            dom = get_page(self._session, OPENCOURSE_REFERENCE_ITEM_URL,
                           json=True,
                           course_id=self._course_id,
                           short_id=short_id)

            resource_content = {}

            # Supplement content has structure as follows:
            # 'linked' {
            #   'openCourseAssets.v1' [ {
            #       'definition' {
            #           'value'

            for asset in dom['linked']['openCourseAssets.v1']:
                value = asset['definition']['value']
                # Supplement lecture types are known to contain both <asset> tags
                # and <a href> tags (depending on the course), so we extract
                # both of them.
                extend_supplement_links(
                    resource_content, self._extract_links_from_text(value))

                instructions = (IN_MEMORY_MARKER + self._markup_to_html(value),
                                'resources')
                extend_supplement_links(
                    resource_content, {IN_MEMORY_EXTENSION: [instructions]})

            return resource_content
        except requests.exceptions.HTTPError as exception:
            logging.error('Could not download supplement %s: %s',
                          short_id, exception)
            if is_debug_run():
                logging.exception('Could not download supplement %s: %s',
                                  short_id, exception)
            return None
74462
def create(self):
        

        # In the header.location there is the newly created object so get the id out of the url
        created_id = self._post_request(
            data=self.element_to_string(self.encode())
        ).headers.get('Location').split('/')[-1]
        return self.get(created_id)
74130
def element( i )
      sources, table = @sources, @table
      if sources.any? { |source| source.dimension > 0 }
        sources = sources.
          collect { |source| source.dimension > 0 ? source.element( i ) : source }
        self.class.new *( sources + [ table ] )
      elsif table.dimension > sources.size
        n = sources.size
        self.class.new *( sources + [ table.unroll( n ).element( i ).roll( n ) ] )
      else
        super i
      end
    end
416224
def resource_to_rdf(resource, dataset=None, graph=None):
    '''
    
    '''
    graph = graph or Graph(namespace_manager=namespace_manager)
    if dataset and dataset.id:
        id = URIRef(url_for('datasets.show_redirect', dataset=dataset.id,
                            _external=True,
                            _anchor='resource-{0}'.format(resource.id)))
    else:
        id = BNode(resource.id)
    permalink = url_for('datasets.resource', id=resource.id, _external=True)
    r = graph.resource(id)
    r.set(RDF.type, DCAT.Distribution)
    r.set(DCT.identifier, Literal(resource.id))
    r.add(DCT.title, Literal(resource.title))
    r.add(DCT.description, Literal(resource.description))
    r.add(DCAT.downloadURL, URIRef(resource.url))
    r.add(DCAT.accessURL, URIRef(permalink))
    r.add(DCT.issued, Literal(resource.published))
    r.add(DCT.modified, Literal(resource.modified))
    if dataset and dataset.license:
        r.add(DCT.rights, Literal(dataset.license.title))
        if dataset.license.url:
            r.add(DCT.license, URIRef(dataset.license.url))
    if resource.filesize is not None:
        r.add(DCAT.bytesSize, Literal(resource.filesize))
    if resource.mime:
        r.add(DCAT.mediaType, Literal(resource.mime))
    if resource.format:
        r.add(DCT.term('format'), Literal(resource.format))
    if resource.checksum:
        checksum = graph.resource(BNode())
        checksum.set(RDF.type, SPDX.Checksum)
        algorithm = 'checksumAlgorithm_{0}'.format(resource.checksum.type)
        checksum.add(SPDX.algorithm, getattr(SPDX, algorithm))
        checksum.add(SPDX.checksumValue, Literal(resource.checksum.value))
        r.add(SPDX.checksum, checksum)
    return r
408816
def get_link(self, rel):
        
        if rel in self.links:
            return self.links[rel]
        raise ResourceNotFound('Resource requested: %r is not available '
            'on this element.' % rel)
623703
function resourceToJsonObject (resource) {
    var result = {};

    for (var prop in resource) {

      if (prop === '_links') {
        if (Object.keys(resource._links).length > 0) {
          // Note: we need to copy data to remove "rel" property without corrupting original Link object
          result._links = Object.keys(resource._links).reduce(function (links, rel) {
            if (Array.isArray(resource._links[rel])) {
              links[rel] = new Array()
              for (var i=0; i < resource._links[rel].length; i++)
                links[rel].push(resource._links[rel][i].toJSON())
            } else {
              var link = resource._links[rel].toJSON();
              links[rel] = link;
              delete link.rel;
            }
            return links;
          }, {});
        }

      } else if (prop === '_embedded') {
        if (Object.keys(resource._embedded).length > 0) {
          // Note that we do not reformat _embedded
          // which means we voluntarily DO NOT RESPECT the following constraint:
          // > Relations with one corresponding Resource/Link have a single object
          // > value, relations with multiple corresponding HAL elements have an
          // > array of objects as their value.
          // Come on, resource one is *really* dumb.
          result._embedded = {};
          for (var rel in resource._embedded) {
            result._embedded[rel] = resource._embedded[rel].map(resourceToJsonObject);
          }
        }

      } else if (resource.hasOwnProperty(prop)) {
        result[prop] = resource[prop];
      }
    }

    return result;
  }
1359713
def get_resource_attributes(ref_key, ref_id, type_id=None, **kwargs):
    

    user_id = kwargs.get('user_id')

    resource_attr_qry = db.DBSession.query(ResourceAttr).filter(
        ResourceAttr.ref_key == ref_key,
        or_(
            ResourceAttr.network_id==ref_id,
            ResourceAttr.node_id==ref_id,
            ResourceAttr.link_id==ref_id,
            ResourceAttr.group_id==ref_id
        ))

    if type_id is not None:
        attr_ids = []
        rs = db.DBSession.query(TypeAttr).filter(TypeAttr.type_id==type_id).all()
        for r in rs:
            attr_ids.append(r.attr_id)

        resource_attr_qry = resource_attr_qry.filter(ResourceAttr.attr_id.in_(attr_ids))

    resource_attrs = resource_attr_qry.all()

    return resource_attrs
1172139
def referenced_by(self):
        
        href = fetch_entry_point('references_by_element')
        return [Element.from_meta(**ref)
                for ref in self.make_request(
                    method='create',
                    href=href,
                    json={'value': self.href})]
506079
function toLink( data ) {
	if ( data && typeof data === 'object' ) {
		if ( data.constructor.name === 'ObjectID' || data.constructor.name === 'ObjectId' ) {
			return { _id: data } ;
		}

		data._id = toObjectId( data._id ) ;
	}
	else if ( typeof data === 'string' ) {
		try {
			data = { _id: mongodb.ObjectID( data ) } ;
		}
		catch ( error ) {}
	}

	return data ;
}
215056
def provides_member_resource(obj):
    
    if isinstance(obj, type):
        obj = object.__new__(obj)
    return IMemberResource in provided_by(obj)
246926
def fetch_as_element(self, **kw):
        
        clone = self.copy()
        clone.format.field_format('id')
        for custom_field in ['field_ids', 'field_names']:
            clone.format.data.pop(custom_field, None)

        for list_of_results in clone.fetch_raw(**kw):
            for entry in list_of_results:
                yield Connection(**entry)
384573
def _get_element(name, element_type, server=None, with_properties=True):
    '''
    
    '''
    element = {}
    name = quote(name, safe='')
    data = _api_get('{0}/{1}'.format(element_type, name), server)

    # Format data, get properties if asked, and return the whole thing
    if any(data['extraProperties']['entity']):
        for key, value in data['extraProperties']['entity'].items():
            element[key] = value
        if with_properties:
            element['properties'] = _get_element_properties(name, element_type)
        return element
    return None
1276158
def _buildElementTree(self,):
        
        t_binder = ctree.Element(self.name)

        for k,v in self.__dict__.items():
            if k not in ('name', 'urls', 'inputs', 'paging') and v :
                t_binder.set(k,v)

        self.etree = t_binder
        return t_binder
726230
def xpathNewNodeSet(self):
        
        ret = libxml2mod.xmlXPathNewNodeSet(self._o)
        if ret is None:raise xpathError('xmlXPathNewNodeSet() failed')
        return xpathObjectRet(ret)