Skip to content

Commit

Permalink
Improved documentation of dlite.Instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Oct 28, 2024
1 parent ad881be commit fb21ce3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 31 deletions.
45 changes: 32 additions & 13 deletions bindings/python/dlite-entity-python.i
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,38 @@ def get_instance(
f'"{self.uri if self.uri else self.meta.uri}"'
)
meta = property(get_meta, doc="Reference to the metadata of this instance.")
dimensions = property(
lambda self: dict((d.name, int(v))
for d, v in zip(self.meta['dimensions'],
self.get_dimensions())),
doc='Dictionary with dimensions name-value pairs.')
properties = property(lambda self:
{p.name: self[p.name] for p in self.meta['properties']},
doc='Dictionary with property name-value pairs.')
is_data = property(_is_data, doc='Whether this is a data instance.')
is_meta = property(_is_meta, doc='Whether this is a metadata instance.')
is_metameta = property(_is_metameta,
doc='Whether this is a meta-metadata instance.')
@property
def meta(self):
"""Reference to the metadata of this instance."""
return self.get_meta()
@property
def dimensions(self):
"""Dictionary with dimensions name-value pairs."""
return dict(
(d.name, int(v))
for d, v in zip(self.meta['dimensions'], self.get_dimensions())
)
@property
def properties(self):
"""Dictionary with property name-value pairs."""
return {p.name: self[p.name] for p in self.meta['properties']}
@property
def is_data(self):
"""Whether this is a data instance."""
return self._is_data()
@property
def is_meta(self):
"""Whether this is a metadata instance."""
return self._is_meta()
@property
def is_metameta(self):
"""Whether this is a meta-metadata instance."""
return self._is_metameta()
@classmethod
def from_metaid(cls, metaid, dimensions, id=None):
Expand Down
34 changes: 16 additions & 18 deletions bindings/python/dlite-entity.i
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,22 @@ struct _Triple {
* Instance
* -------- */
%feature("docstring", "\
Returns a new instance.

Instance(metaid=None, dims=None, id=None, url=None, storage=None, driver=None,
location=None, options=None, dimensions=None, properties=None,
description=None)

Is called from one of the following class methods defined in dlite.py:

- from_metaid(cls, metaid, dimensions, id=None)
- from_url(cls, url, metaid=None)
- from_storage(cls, storage, id=None, metaid=None)
- from_location(cls, driver, location, options=None, id=None)
- from_json(cls, jsoninput, id=None, metaid=None)
- from_bson(cls, bsoninput)
- from_dict(cls, d, id=None, single=None, check_storages=True)
- create_metadata(cls, uri, dimensions, properties, description)

For details, see the documentation for the class methods.
Represents a DLite instance.

This is the most central class in DLite. It has a complex `__init__()`
method and is intended to be instantiated with one of the following class
methods:

- from_metaid(cls, metaid, dimensions, id=None)
- from_url(cls, url, metaid=None)
- from_storage(cls, storage, id=None, metaid=None)
- from_location(cls, driver, location, options=None, id=None)
- from_json(cls, jsoninput, id=None, metaid=None)
- from_bson(cls, bsoninput)
- from_dict(cls, d, id=None, single=None, check_storages=True)
- create_metadata(cls, uri, dimensions, properties, description)

For details, see the documentation of the individual class methods.

") _DLiteInstance;
%apply(int *IN_ARRAY1, int DIM1) {(int *dims, int ndims)};
Expand Down

0 comments on commit fb21ce3

Please sign in to comment.