Struct stam::AnnotationDataSet

source ·
pub struct AnnotationDataSet { /* private fields */ }
Expand description

An AnnotationDataSet stores the keys DataKey and values AnnotationData (which in turn encapsulates DataValue) that are used by annotations. It effectively defines a certain vocabulary, i.e. key/value pairs. The AnnotationDataSet does not store the crate::annotation::Annotation instances themselves, those are in the AnnotationStore. The datasets themselves are also held by the AnnotationStore.

Implementations§

source§

impl AnnotationDataSet

source

pub fn new(config: Config) -> Self

source

pub fn builder<'a>() -> AnnotationDataSetBuilder<'a>

Returns an Annotation dataset builder to build new annotation datasets

source

pub fn with_file( self, filename: &str, config: Config ) -> Result<Self, StamError>

Loads an AnnotationDataSet from file (STAM JSON or other supported format) and merges it into the current one. For STAM JSON, the file must contain a single object which has “@type”: “AnnotationDataSet” The ID will be ignored (existing one takes precendence).

source

pub fn from_file(filename: &str, config: Config) -> Result<Self, StamError>

Loads an AnnotationDataSet from file (STAM JSON or other supported format). For STAM JSON, the file must contain a single object which has “@type”: “AnnotationDataSet”

source

pub fn merge_from_builder( &mut self, builder: AnnotationDataSetBuilder<'_> ) -> Result<&mut Self, StamError>

Merge another AnnotationDataSet, represented by an AnnotationDataSetBuilder, into this one. It’s a fairly low-level function which you often don’t need directly, use AnnotationDataSet.with_file() instead.

source

pub fn with_data( self, id: Item<'_, AnnotationData>, key: Item<'_, DataKey>, value: DataValue ) -> Result<Self, StamError>

Adds new AnnotationData to the dataset, this should be Note: if you don’t want to set an ID (first argument), you can just just pass “”.into()

source

pub fn data_by_value( &self, key: Item<'_, DataKey>, value: &DataValue ) -> Option<&AnnotationData>

Finds the [AnnotationData'] in the annotation dataset. Returns one match. This is a low level method, use the similar [WrappedItem.find_data()`] for a higher level version.

source

pub fn insert_data<'a>( &mut self, id: Item<'a, AnnotationData>, key: Item<'a, DataKey>, value: DataValue, safety: bool ) -> Result<AnnotationDataHandle, StamError>

Adds new AnnotationData to the dataset. Use [Self.with_data()] instead if you are using a regular builder pattern. If the data already exists, this returns a handle to the existing data and inserts nothing new. If the data is new, it returns a handle to the new data.

Note: if you don’t want to set an ID (first argument), you can just pass AnyId::None or “”.into()

source

pub fn build_insert_data( &mut self, dataitem: AnnotationDataBuilder<'_>, safety: bool ) -> Result<AnnotationDataHandle, StamError>

Build and insert data into the dataset, similar to [Self.insert_data()] and [Self.with_data()], but takes a prepared AnnotationDataBuilder instead.

source

pub fn data(&self) -> StoreIter<'_, AnnotationData>

Returns an iterator over all the data (AnnotationData) in this set, the iterator returns references as [WrappedItem<AnnotationData].

source

pub fn keys(&self) -> StoreIter<'_, DataKey>

Returns an iterator over all the keys (DataKey) in this set, the iterator in returns references as WrappedItem<DataKey>

source

pub fn key(&self, key: &Item<'_, DataKey>) -> Option<WrappedItem<'_, DataKey>>

Retrieve a key in this set

source

pub fn annotationdata<'a>( &'a self, annotationdata: &Item<'_, AnnotationData> ) -> Option<WrappedItem<'a, AnnotationData>>

Retrieve a AnnotationData in this set

Returns a reference to AnnotationData that is wrapped in a fat pointer (WrappedItem<AnnotationData>) that also contains reference to the store and which is immediately implements various methods for working with the type. If you need a more performant low-level method, use StoreFor<T>::get() instead.

source

pub fn data_by_key( &self, key: &Item<'_, DataKey> ) -> Option<&Vec<AnnotationDataHandle>>

Returns data by key, does a lookup in the reverse index and returns a reference to it. This is a low-level method. use [WrappedItem<DataKey>.data()] instead.

source

pub fn with_id(self, id: String) -> Self

Sets the ID of the dataset in a builder pattern

source

pub fn keys_len(&self) -> usize

Writes a //Returns the number of keys in the store (deletions are not substracted)

source

pub fn data_len(&self) -> usize

Trait Implementations§

source§

impl AssociatedFile for AnnotationDataSet

source§

fn filename(&self) -> Option<&str>

Get the filename for stand-off file specified using @include (if any)

source§

fn set_filename(&mut self, filename: &str) -> &mut Self

Get the filename for stand-off file specified using @include (if any)

source§

fn with_filename(self, filename: &str) -> Selfwhere Self: Sized,

source§

fn filename_without_extension(&self) -> Option<&str>

Returns the filename without (known!) extension. The extension must be a known extension used by STAM for this to work.
source§

fn filename_without_workdir(&self) -> Option<&str>

Serializes the filename ready for use with STAM JSON’s @include or STAM CSV. It basically only strips the workdir component, if any.
source§

impl Clone for AnnotationDataSet

source§

fn clone(&self) -> AnnotationDataSet

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Configurable for AnnotationDataSet

source§

fn config(&self) -> &Config

source§

fn config_mut(&mut self) -> &mut Config

source§

fn set_config(&mut self, config: Config) -> &mut Self

Setter to associate a configuration
source§

fn with_config(self, config: Config) -> Self

Builder pattern to associate a configuration
source§

impl Debug for AnnotationDataSet

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for AnnotationDataSet

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for AnnotationDataSet

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'j> FromJson<'j> for AnnotationDataSet

source§

fn from_json_file(filename: &str, config: Config) -> Result<Self, StamError>

Loads an AnnotationDataSet from a STAM JSON file The file must contain a single object which has “@type”: “AnnotationDataSet” If workdir is set, the file will be searched for in the workdir if needed

source§

fn from_json_str(string: &str, config: Config) -> Result<Self, StamError>

Loads an AnnotationDataSet from a STAM JSON string The string must contain a single object which has “@type”: “AnnotationDataSet”

source§

impl PartialEq<AnnotationDataSet> for AnnotationDataSet

source§

fn eq(&self, other: &AnnotationDataSet) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl SelfSelector for AnnotationDataSet

source§

fn selector(&self) -> Result<Selector, StamError>

Returns a selector to this resource

source§

impl Serialize for AnnotationDataSet

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Storable for AnnotationDataSet

source§

fn bound(&mut self)

Sets the ownership of all items in the store This ensure the part_of_set relation (backreference) is set right.

§

type HandleType = AnnotationDataSetHandle

§

type StoreType = AnnotationStore

source§

fn id(&self) -> Option<&str>

Get the public ID
source§

fn with_id(self, id: String) -> Self

Builder pattern to set the public Id
source§

fn handle(&self) -> Option<Self::HandleType>

Retrieve the internal (numeric) id. For any type T uses in StoreFor<T>, this may be None only in the initial stage when it is still unbounded to a store.
source§

fn set_handle(&mut self, handle: AnnotationDataSetHandle)

Set the internal ID. May only be called once (though currently not enforced).
source§

fn carries_id() -> bool

Does this type support an ID?
source§

fn handle_or_err(&self) -> Result<Self::HandleType, StamError>

Like Self::handle() but returns a StamError::Unbound error if there is no internal id.
source§

fn id_or_err(&self) -> Result<&str, StamError>

Like Self::id() but returns a StamError::NoIdError error if there is no internal id.
source§

fn wrap_in<'store>( &'store self, store: &'store Self::StoreType ) -> Result<WrappedItem<'store, Self>, StamError>where Self: Sized,

Returns a wrapped reference to this item and the store that owns it. This allows for some more introspection on the part of the item. reverse of StoreFor<T>::wrap()
source§

fn wrap_owned_in<'store>( self, store: &'store Self::StoreType ) -> Result<WrappedItem<'store, Self>, StamError>where Self: Sized,

Returns a wrapped reference to this item and the store that owns it. This allows for some more introspection on the part of the item. reverse of StoreFor<T>::wrap_owned()
source§

fn generate_id(self, idmap: Option<&mut IdMap<Self::HandleType>>) -> Selfwhere Self: Sized,

Generate a random ID in a given idmap (adds it to the map and assigns it to the item)
source§

impl StoreFor<AnnotationData> for AnnotationDataSet

source§

fn preremove(&mut self, handle: AnnotationDataHandle) -> Result<(), StamError>

called before the item is removed from the store updates the relation maps, no need to call manually

source§

fn store(&self) -> &Store<AnnotationData>

Get a reference to the entire store for the associated type
source§

fn store_mut(&mut self) -> &mut Store<AnnotationData>

Get a mutable reference to the entire store for the associated type
source§

fn idmap(&self) -> Option<&IdMap<AnnotationDataHandle>>

Get a reference to the id map for the associated type, mapping global ids to internal ids
source§

fn idmap_mut(&mut self) -> Option<&mut IdMap<AnnotationDataHandle>>

Get a mutable reference to the id map for the associated type, mapping global ids to internal ids
source§

fn owns(&self, item: &AnnotationData) -> Option<bool>

Tests if the item is owner by the store, returns None if ownership is unknown
source§

fn store_typeinfo() -> &'static str

source§

fn inserted(&mut self, handle: AnnotationDataHandle) -> Result<(), StamError>

Called after an item was inserted to the store Allows the store to do further bookkeeping like updating relation maps
source§

fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>

Adds an item to the store. Returns a handle to it upon success.
source§

fn preinsert(&self, item: &mut T) -> Result<(), StamError>

Called prior to inserting an item into to the store If it returns an error, the insert will be cancelled. Allows for bookkeeping such as inheriting configuration parameters from parent to the item
source§

fn add(self, item: T) -> Result<Self, StamError>where Self: Sized,

source§

fn has<'a, 'b>(&'a self, item: &Item<'b, T>) -> bool

Returns true if the store has the item
source§

unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>

Get a reference to an item from the store, by handle, without checking validity. Read more
source§

fn get<'a, 'b>(&'a self, item: &Item<'b, T>) -> Result<&'a T, StamError>

Get a reference to an item from the store
source§

fn get_mut<'a, 'b>(&mut self, item: &Item<'b, T>) -> Result<&mut T, StamError>

Get a mutable reference to an item from the store by internal ID
source§

fn remove(&mut self, handle: T::HandleType) -> Result<(), StamError>

Removes an item by handle, returns an error if the item has dependencies and can’t be removed
source§

fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>

Resolves an ID to a handle You usually don’t want to call this directly
source§

fn iter<'a>(&'a self) -> StoreIter<'a, T> where T: Storable<StoreType = Self>,

Iterate over the store
source§

fn iter_mut<'a>(&'a mut self) -> StoreIterMut<'a, T>

Iterate over the store, mutably
source§

fn next_handle(&self) -> T::HandleType

Return the internal id that will be assigned for the next item to the store
source§

fn last_handle(&self) -> T::HandleType

Return the internal id that was assigned to last inserted item
source§

fn bind(&mut self, item: T) -> Result<T, StamError>

This binds an item to the store PRIOR to it being actually added You should never need to call this directly (it can only be called once per item anyway).
source§

fn wrap<'a>(&'a self, item: &'a T) -> Result<WrappedItem<'_, T>, StamError>where T: Storable<StoreType = Self>,

Wraps the item in a smart pointer that also holds a reference to this store This method performs some extra checks to verify if the item is indeed owned by the store and returns an error if not.
source§

fn wrap_owned<'a>(&'a self, item: T) -> Result<WrappedItem<'_, T>, StamError>where T: Storable<StoreType = Self>,

Wraps the item in a smart pointer that also holds a reference to this store Ownership is retained with this method, i.e. the store does NOT own the item.
source§

fn wrap_store<'a>(&'a self) -> WrappedStore<'_, T, Self>where Self: Sized,

Wraps the entire store along with a reference to self Low-level method that you won’t need
source§

impl StoreFor<AnnotationDataSet> for AnnotationStore

source§

fn preinsert(&self, item: &mut AnnotationDataSet) -> Result<(), StamError>

Called prior to inserting an item into to the store If it returns an error, the insert will be cancelled. Allows for bookkeeping such as inheriting configuration parameters from parent to the item

source§

fn preremove( &mut self, handle: AnnotationDataSetHandle ) -> Result<(), StamError>

called before the item is removed from the store updates the relation maps, no need to call manually

source§

fn store(&self) -> &Store<AnnotationDataSet>

Get a reference to the entire store for the associated type
source§

fn store_mut(&mut self) -> &mut Store<AnnotationDataSet>

Get a mutable reference to the entire store for the associated type
source§

fn idmap(&self) -> Option<&IdMap<AnnotationDataSetHandle>>

Get a reference to the id map for the associated type, mapping global ids to internal ids
source§

fn idmap_mut(&mut self) -> Option<&mut IdMap<AnnotationDataSetHandle>>

Get a mutable reference to the id map for the associated type, mapping global ids to internal ids
source§

fn store_typeinfo() -> &'static str

source§

fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>

Adds an item to the store. Returns a handle to it upon success.
source§

fn inserted(&mut self, handle: T::HandleType) -> Result<(), StamError>

Called after an item was inserted to the store Allows the store to do further bookkeeping like updating relation maps
source§

fn add(self, item: T) -> Result<Self, StamError>where Self: Sized,

source§

fn has<'a, 'b>(&'a self, item: &Item<'b, T>) -> bool

Returns true if the store has the item
source§

unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>

Get a reference to an item from the store, by handle, without checking validity. Read more
source§

fn get<'a, 'b>(&'a self, item: &Item<'b, T>) -> Result<&'a T, StamError>

Get a reference to an item from the store
source§

fn get_mut<'a, 'b>(&mut self, item: &Item<'b, T>) -> Result<&mut T, StamError>

Get a mutable reference to an item from the store by internal ID
source§

fn remove(&mut self, handle: T::HandleType) -> Result<(), StamError>

Removes an item by handle, returns an error if the item has dependencies and can’t be removed
source§

fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>

Resolves an ID to a handle You usually don’t want to call this directly
source§

fn owns(&self, item: &T) -> Option<bool>

Tests if the item is owner by the store, returns None if ownership is unknown
source§

fn iter<'a>(&'a self) -> StoreIter<'a, T> where T: Storable<StoreType = Self>,

Iterate over the store
source§

fn iter_mut<'a>(&'a mut self) -> StoreIterMut<'a, T>

Iterate over the store, mutably
source§

fn next_handle(&self) -> T::HandleType

Return the internal id that will be assigned for the next item to the store
source§

fn last_handle(&self) -> T::HandleType

Return the internal id that was assigned to last inserted item
source§

fn bind(&mut self, item: T) -> Result<T, StamError>

This binds an item to the store PRIOR to it being actually added You should never need to call this directly (it can only be called once per item anyway).
source§

fn wrap<'a>(&'a self, item: &'a T) -> Result<WrappedItem<'_, T>, StamError>where T: Storable<StoreType = Self>,

Wraps the item in a smart pointer that also holds a reference to this store This method performs some extra checks to verify if the item is indeed owned by the store and returns an error if not.
source§

fn wrap_owned<'a>(&'a self, item: T) -> Result<WrappedItem<'_, T>, StamError>where T: Storable<StoreType = Self>,

Wraps the item in a smart pointer that also holds a reference to this store Ownership is retained with this method, i.e. the store does NOT own the item.
source§

fn wrap_store<'a>(&'a self) -> WrappedStore<'_, T, Self>where Self: Sized,

Wraps the entire store along with a reference to self Low-level method that you won’t need
source§

impl StoreFor<DataKey> for AnnotationDataSet

source§

fn preremove(&mut self, handle: DataKeyHandle) -> Result<(), StamError>

called before the item is removed from the store updates the relation maps, no need to call manually

source§

fn store(&self) -> &Store<DataKey>

Get a reference to the entire store for the associated type
source§

fn store_mut(&mut self) -> &mut Store<DataKey>

Get a mutable reference to the entire store for the associated type
source§

fn idmap(&self) -> Option<&IdMap<DataKeyHandle>>

Get a reference to the id map for the associated type, mapping global ids to internal ids
source§

fn idmap_mut(&mut self) -> Option<&mut IdMap<DataKeyHandle>>

Get a mutable reference to the id map for the associated type, mapping global ids to internal ids
source§

fn owns(&self, item: &DataKey) -> Option<bool>

Tests if the item is owner by the store, returns None if ownership is unknown
source§

fn store_typeinfo() -> &'static str

source§

fn inserted(&mut self, handle: DataKeyHandle) -> Result<(), StamError>

Called after an item was inserted to the store Allows the store to do further bookkeeping like updating relation maps
source§

fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>

Adds an item to the store. Returns a handle to it upon success.
source§

fn preinsert(&self, item: &mut T) -> Result<(), StamError>

Called prior to inserting an item into to the store If it returns an error, the insert will be cancelled. Allows for bookkeeping such as inheriting configuration parameters from parent to the item
source§

fn add(self, item: T) -> Result<Self, StamError>where Self: Sized,

source§

fn has<'a, 'b>(&'a self, item: &Item<'b, T>) -> bool

Returns true if the store has the item
source§

unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>

Get a reference to an item from the store, by handle, without checking validity. Read more
source§

fn get<'a, 'b>(&'a self, item: &Item<'b, T>) -> Result<&'a T, StamError>

Get a reference to an item from the store
source§

fn get_mut<'a, 'b>(&mut self, item: &Item<'b, T>) -> Result<&mut T, StamError>

Get a mutable reference to an item from the store by internal ID
source§

fn remove(&mut self, handle: T::HandleType) -> Result<(), StamError>

Removes an item by handle, returns an error if the item has dependencies and can’t be removed
source§

fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>

Resolves an ID to a handle You usually don’t want to call this directly
source§

fn iter<'a>(&'a self) -> StoreIter<'a, T> where T: Storable<StoreType = Self>,

Iterate over the store
source§

fn iter_mut<'a>(&'a mut self) -> StoreIterMut<'a, T>

Iterate over the store, mutably
source§

fn next_handle(&self) -> T::HandleType

Return the internal id that will be assigned for the next item to the store
source§

fn last_handle(&self) -> T::HandleType

Return the internal id that was assigned to last inserted item
source§

fn bind(&mut self, item: T) -> Result<T, StamError>

This binds an item to the store PRIOR to it being actually added You should never need to call this directly (it can only be called once per item anyway).
source§

fn wrap<'a>(&'a self, item: &'a T) -> Result<WrappedItem<'_, T>, StamError>where T: Storable<StoreType = Self>,

Wraps the item in a smart pointer that also holds a reference to this store This method performs some extra checks to verify if the item is indeed owned by the store and returns an error if not.
source§

fn wrap_owned<'a>(&'a self, item: T) -> Result<WrappedItem<'_, T>, StamError>where T: Storable<StoreType = Self>,

Wraps the item in a smart pointer that also holds a reference to this store Ownership is retained with this method, i.e. the store does NOT own the item.
source§

fn wrap_store<'a>(&'a self) -> WrappedStore<'_, T, Self>where Self: Sized,

Wraps the entire store along with a reference to self Low-level method that you won’t need
source§

impl ToCsv for AnnotationDataSet

source§

fn to_csv_writer<W>(&self, writer: W, _table: CsvTable) -> Result<(), StamError>where W: Write,

Writes CSV output, for the specified table, to the writer

source§

fn to_csv_file( &self, filename: &str, config: &Config, table: CsvTable ) -> Result<(), StamError>

Writes this structure to a file The actual dataformat can be set via config, the default is STAM JSON. Note: This only writes a single table! Just use [AnnotationStore.save()] to write everything.
source§

fn to_csv_string(&self, table: Option<CsvTable>) -> Result<String, StamError>

source§

impl ToJson for AnnotationDataSet

source§

fn to_json_writer<W>(&self, writer: W, compact: bool) -> Result<(), StamError>where W: Write,

Writes a serialisation (choose a dataformat) to any writer Lower-level function
source§

fn to_json_file(&self, filename: &str, config: &Config) -> Result<(), StamError>

Writes this structure to a file The actual dataformat can be set via config, the default is STAM JSON.
source§

fn to_json_string(&self, config: &Config) -> Result<String, StamError>

Serializes this structure to one string. The actual dataformat can be set via config, the default is STAM JSON. If config not not specified, an attempt to fetch the AnnotationStore’s initial config is made
source§

impl<'a> TryFrom<AnnotationDataSetBuilder<'a>> for AnnotationDataSet

§

type Error = StamError

The type returned in the event of a conversion error.
source§

fn try_from(builder: AnnotationDataSetBuilder<'a>) -> Result<Self, StamError>

Performs the conversion.
source§

impl TypeInfo for AnnotationDataSet

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,