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 Annotation instances, those are in
the AnnotationStore. The datasets themselves are also held by the AnnotationStore.
See the top-level documentation for AnnotationStore for a complete usage example on instantiating a data set.
Implementations§
source§impl AnnotationDataSet
impl AnnotationDataSet
pub fn new(config: Config) -> Self
sourcepub fn from_file(filename: &str, config: Config) -> Result<Self, StamError>
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”
sourcepub fn with_file(self, filename: &str) -> Result<Self, StamError>
pub fn with_file(self, filename: &str) -> Result<Self, StamError>
Merge another AnnotationDataSet from file (STAM JSON or other supported format). Note: The ID and filename of the set will not be overwritten if already set, reserialising the store will produce a single new set.
sourcepub fn with_data<'a>(
self,
key: impl Into<BuildItem<'a, DataKey>>,
value: impl Into<DataValue> + Debug
) -> Result<Self, StamError>
pub fn with_data<'a>( self, key: impl Into<BuildItem<'a, DataKey>>, value: impl Into<DataValue> + Debug ) -> Result<Self, StamError>
Adds new AnnotationData to the dataset, this should be
sourcepub fn with_data_with_id<'a>(
self,
key: impl Into<BuildItem<'a, DataKey>>,
value: impl Into<DataValue> + Debug,
id: impl Into<BuildItem<'a, AnnotationData>>
) -> Result<Self, StamError>
pub fn with_data_with_id<'a>( self, key: impl Into<BuildItem<'a, DataKey>>, value: impl Into<DataValue> + Debug, id: impl Into<BuildItem<'a, AnnotationData>> ) -> Result<Self, StamError>
Adds new AnnotationData to the dataset, this should be
sourcepub fn data_by_value(
&self,
key: impl Request<DataKey>,
value: &DataValue
) -> Option<&AnnotationData>
pub fn data_by_value( &self, key: impl Request<DataKey>, value: &DataValue ) -> Option<&AnnotationData>
Finds the AnnotationData in the annotation dataset. Returns one match.
This is a low level method, use the similar [crate::ResultItem<AnnotationDataSet>.data_by_value()] for a higher level version.
sourcepub fn insert_data<'a>(
&mut self,
id: impl Into<BuildItem<'a, AnnotationData>>,
key: impl Into<BuildItem<'a, DataKey>>,
value: impl Into<DataValue> + Debug,
safety: bool
) -> Result<AnnotationDataHandle, StamError>
pub fn insert_data<'a>( &mut self, id: impl Into<BuildItem<'a, AnnotationData>>, key: impl Into<BuildItem<'a, DataKey>>, value: impl Into<DataValue> + Debug, 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.
The safety parameter should be set to true in normal circumstances, it will check if the data already exists
if it has no ID, and reuse that. If set to false, data will be inserted as a duplicate.
Note: if you don’t want to set an ID (first argument), you can just pass AnyId::None or “”.into()
sourcepub fn build_insert_data(
&mut self,
dataitem: AnnotationDataBuilder<'_>,
safety: bool
) -> Result<AnnotationDataHandle, StamError>
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.
sourcepub fn data(&self) -> StoreIter<'_, AnnotationData>
pub fn data(&self) -> StoreIter<'_, AnnotationData>
Returns an iterator over all the data (AnnotationData) in this set, the iterator returns references to AnnotationData.
sourcepub fn annotationdata(
&self,
annotationdata: impl Request<AnnotationData>
) -> Option<&AnnotationData>
pub fn annotationdata( &self, annotationdata: impl Request<AnnotationData> ) -> Option<&AnnotationData>
Retrieve a AnnotationData in this set
sourcepub fn data_by_key(
&self,
key: impl Request<DataKey>
) -> Option<&Vec<AnnotationDataHandle>>
pub fn data_by_key( &self, key: impl Request<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 [ResultItem<DataKey>.data()] instead.
sourcepub fn with_id(self, id: impl Into<String>) -> Self
pub fn with_id(self, id: impl Into<String>) -> Self
Sets the ID of the dataset in a builder pattern
sourcepub fn keys_len(&self) -> usize
pub fn keys_len(&self) -> usize
Writes a //Returns the number of keys in the store (deletions are not substracted)
pub fn data_len(&self) -> usize
pub fn meminfo(&self) -> usize
pub fn shrink_to_fit(&mut self)
sourcepub fn strip_data_ids(&mut self)
pub fn strip_data_ids(&mut self)
Strip public identifiers from annotation data This will not affect any internal references but will render any references from external sources impossible.
Trait Implementations§
source§impl AssociatedFile for AnnotationDataSet
impl AssociatedFile for AnnotationDataSet
source§fn filename(&self) -> Option<&str>
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
fn set_filename(&mut self, filename: &str) -> &mut Self
Get the filename for stand-off file specified using @include (if any)
fn with_filename(self, filename: &str) -> Selfwhere
Self: Sized,
source§fn filename_without_extension(&self) -> Option<&str>
fn filename_without_extension(&self) -> Option<&str>
source§fn filename_without_workdir(&self) -> Option<&str>
fn filename_without_workdir(&self) -> Option<&str>
source§impl Clone for AnnotationDataSet
impl Clone for AnnotationDataSet
source§fn clone(&self) -> AnnotationDataSet
fn clone(&self) -> AnnotationDataSet
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Configurable for AnnotationDataSet
impl Configurable for AnnotationDataSet
source§impl DataSize for AnnotationDataSet
impl DataSize for AnnotationDataSet
source§const IS_DYNAMIC: bool = true
const IS_DYNAMIC: bool = true
true, the type has a heap size that can vary at runtime, depending on the actual value.source§const STATIC_HEAP_SIZE: usize = 0usize
const STATIC_HEAP_SIZE: usize = 0usize
IS_DYNAMIC is false, this is
the total amount of heap memory occupied by the value. Otherwise this is a lower bound.source§fn estimate_heap_size(&self) -> usize
fn estimate_heap_size(&self) -> usize
source§impl Debug for AnnotationDataSet
impl Debug for AnnotationDataSet
source§impl<'bytes, Ctx> Decode<'bytes, Ctx> for AnnotationDataSet
impl<'bytes, Ctx> Decode<'bytes, Ctx> for AnnotationDataSet
source§impl<Ctx> Encode<Ctx> for AnnotationDataSet
impl<Ctx> Encode<Ctx> for AnnotationDataSet
source§impl FromCsv for AnnotationDataSet
impl FromCsv for AnnotationDataSet
source§impl FromJson for AnnotationDataSet
impl FromJson for AnnotationDataSet
source§fn from_json_file(filename: &str, config: Config) -> Result<Self, StamError>
fn from_json_file(filename: &str, config: Config) -> Result<Self, StamError>
Loads an AnnotationDataSet from a STAM JSON file, as a builder
The file must contain a single object which has “@type”: “AnnotationDataSet”
If include is true, the file will be included via the @include mechanism, and is kept external upon serialization
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>
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 for AnnotationDataSet
impl PartialEq for AnnotationDataSet
source§fn eq(&self, other: &AnnotationDataSet) -> bool
fn eq(&self, other: &AnnotationDataSet) -> bool
self and other values to be equal, and is used
by ==.source§impl<'a> Request<AnnotationDataSet> for AnnotationDataSetHandle
impl<'a> Request<AnnotationDataSet> for AnnotationDataSetHandle
source§fn to_handle<'store, S>(
&self,
_store: &'store S
) -> Option<AnnotationDataSetHandle>where
S: StoreFor<AnnotationDataSet>,
fn to_handle<'store, S>(
&self,
_store: &'store S
) -> Option<AnnotationDataSetHandle>where
S: StoreFor<AnnotationDataSet>,
source§fn requested_id(&self) -> Option<&str>
fn requested_id(&self) -> Option<&str>
source§fn requested_id_owned(self) -> Option<String>
fn requested_id_owned(self) -> Option<String>
source§fn requested_handle(&self) -> Option<T::HandleType>
fn requested_handle(&self) -> Option<T::HandleType>
source§impl<'a> Request<AnnotationDataSet> for Option<AnnotationDataSetHandle>
impl<'a> Request<AnnotationDataSet> for Option<AnnotationDataSetHandle>
source§fn to_handle<'store, S>(
&self,
_store: &'store S
) -> Option<AnnotationDataSetHandle>where
S: StoreFor<AnnotationDataSet>,
fn to_handle<'store, S>(
&self,
_store: &'store S
) -> Option<AnnotationDataSetHandle>where
S: StoreFor<AnnotationDataSet>,
source§fn requested_id(&self) -> Option<&str>
fn requested_id(&self) -> Option<&str>
source§fn requested_id_owned(self) -> Option<String>
fn requested_id_owned(self) -> Option<String>
source§fn requested_handle(&self) -> Option<T::HandleType>
fn requested_handle(&self) -> Option<T::HandleType>
source§impl SelfSelector for AnnotationDataSet
impl SelfSelector for AnnotationDataSet
source§impl Serialize for AnnotationDataSet
impl Serialize for AnnotationDataSet
source§impl Storable for AnnotationDataSet
impl Storable for AnnotationDataSet
type HandleType = AnnotationDataSetHandle
type StoreHandleType = ()
type FullHandleType = <AnnotationDataSet as Storable>::HandleType
type StoreType = AnnotationStore
source§fn handle(&self) -> Option<Self::HandleType>
fn handle(&self) -> Option<Self::HandleType>
StoreFor<T>, this may return None only in the initial
stage when it is still unbounded to a store, so this is almost always safe to unwrap when used in the public API.source§fn with_handle(self, handle: AnnotationDataSetHandle) -> Self
fn with_handle(self, handle: AnnotationDataSetHandle) -> Self
source§fn carries_id() -> bool
fn carries_id() -> bool
fn fullhandle( _storehandle: Self::StoreHandleType, handle: Self::HandleType ) -> Self::FullHandleType
source§fn merge(&mut self, other: Self) -> Result<(), StamError>
fn merge(&mut self, other: Self) -> Result<(), StamError>
source§fn unbind(self) -> Self
fn unbind(self) -> Self
source§fn handle_or_err(&self) -> Result<Self::HandleType, StamError>
fn handle_or_err(&self) -> Result<Self::HandleType, StamError>
Self::handle() but returns a StamError::Unbound error if there is no internal id.source§fn temp_id(&self) -> Result<String, StamError>
fn temp_id(&self) -> Result<String, StamError>
source§fn as_resultitem<'store>(
&'store self,
store: &'store Self::StoreType,
rootstore: &'store AnnotationStore
) -> ResultItem<'store, Self>where
Self: Sized,
fn as_resultitem<'store>(
&'store self,
store: &'store Self::StoreType,
rootstore: &'store AnnotationStore
) -> ResultItem<'store, Self>where
Self: Sized,
T as a ResultItem<T>, i.e. a wrapped reference that includes a reference to
both this item as well as the store that owns it. All high-level API functions are implemented
on such Result types. You should not need to invoke this yourself.source§fn generate_id(self, idmap: Option<&mut IdMap<Self::HandleType>>) -> Selfwhere
Self: Sized,
fn generate_id(self, idmap: Option<&mut IdMap<Self::HandleType>>) -> Selfwhere
Self: Sized,
source§impl StoreFor<AnnotationData> for AnnotationDataSet
impl StoreFor<AnnotationData> for AnnotationDataSet
source§fn store(&self) -> &Store<AnnotationData>
fn store(&self) -> &Store<AnnotationData>
source§fn store_mut(&mut self) -> &mut Store<AnnotationData>
fn store_mut(&mut self) -> &mut Store<AnnotationData>
source§fn idmap(&self) -> Option<&IdMap<AnnotationDataHandle>>
fn idmap(&self) -> Option<&IdMap<AnnotationDataHandle>>
source§fn idmap_mut(&mut self) -> Option<&mut IdMap<AnnotationDataHandle>>
fn idmap_mut(&mut self) -> Option<&mut IdMap<AnnotationDataHandle>>
fn store_typeinfo() -> &'static str
source§fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>
fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>
source§fn add(self, item: T) -> Result<Self, StamError>where
Self: Sized,
fn add(self, item: T) -> Result<Self, StamError>where
Self: Sized,
source§unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>
unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>
source§fn get(&self, item: impl Request<T>) -> Result<&T, StamError>
fn get(&self, item: impl Request<T>) -> Result<&T, StamError>
AnnotationStore::annotation() instead.source§fn get_mut(&mut self, item: impl Request<T>) -> Result<&mut T, StamError>
fn get_mut(&mut self, item: impl Request<T>) -> Result<&mut T, StamError>
source§fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>
fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>
source§fn iter(&self) -> StoreIter<'_, T>where
T: Storable<StoreType = Self>,
fn iter(&self) -> StoreIter<'_, T>where
T: Storable<StoreType = Self>,
annotations(), resources() instead. source§fn iter_mut(&mut self) -> StoreIterMut<'_, T>
fn iter_mut(&mut self) -> StoreIterMut<'_, T>
source§fn next_handle(&self) -> T::HandleType
fn next_handle(&self) -> T::HandleType
source§fn last_handle(&self) -> T::HandleType
fn last_handle(&self) -> T::HandleType
source§impl StoreFor<AnnotationDataSet> for AnnotationStore
impl StoreFor<AnnotationDataSet> for AnnotationStore
source§fn store(&self) -> &Store<AnnotationDataSet>
fn store(&self) -> &Store<AnnotationDataSet>
source§fn store_mut(&mut self) -> &mut Store<AnnotationDataSet>
fn store_mut(&mut self) -> &mut Store<AnnotationDataSet>
source§fn idmap(&self) -> Option<&IdMap<AnnotationDataSetHandle>>
fn idmap(&self) -> Option<&IdMap<AnnotationDataSetHandle>>
source§fn idmap_mut(&mut self) -> Option<&mut IdMap<AnnotationDataSetHandle>>
fn idmap_mut(&mut self) -> Option<&mut IdMap<AnnotationDataSetHandle>>
fn store_typeinfo() -> &'static str
source§fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>
fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>
source§fn add(self, item: T) -> Result<Self, StamError>where
Self: Sized,
fn add(self, item: T) -> Result<Self, StamError>where
Self: Sized,
source§unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>
unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>
source§fn get(&self, item: impl Request<T>) -> Result<&T, StamError>
fn get(&self, item: impl Request<T>) -> Result<&T, StamError>
AnnotationStore::annotation() instead.source§fn get_mut(&mut self, item: impl Request<T>) -> Result<&mut T, StamError>
fn get_mut(&mut self, item: impl Request<T>) -> Result<&mut T, StamError>
source§fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>
fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>
source§fn iter(&self) -> StoreIter<'_, T>where
T: Storable<StoreType = Self>,
fn iter(&self) -> StoreIter<'_, T>where
T: Storable<StoreType = Self>,
annotations(), resources() instead. source§fn iter_mut(&mut self) -> StoreIterMut<'_, T>
fn iter_mut(&mut self) -> StoreIterMut<'_, T>
source§fn next_handle(&self) -> T::HandleType
fn next_handle(&self) -> T::HandleType
source§fn last_handle(&self) -> T::HandleType
fn last_handle(&self) -> T::HandleType
source§impl StoreFor<DataKey> for AnnotationDataSet
impl StoreFor<DataKey> for AnnotationDataSet
source§fn store(&self) -> &Store<DataKey>
fn store(&self) -> &Store<DataKey>
source§fn store_mut(&mut self) -> &mut Store<DataKey>
fn store_mut(&mut self) -> &mut Store<DataKey>
source§fn idmap(&self) -> Option<&IdMap<DataKeyHandle>>
fn idmap(&self) -> Option<&IdMap<DataKeyHandle>>
source§fn idmap_mut(&mut self) -> Option<&mut IdMap<DataKeyHandle>>
fn idmap_mut(&mut self) -> Option<&mut IdMap<DataKeyHandle>>
fn store_typeinfo() -> &'static str
source§fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>
fn insert(&mut self, item: T) -> Result<T::HandleType, StamError>
source§fn add(self, item: T) -> Result<Self, StamError>where
Self: Sized,
fn add(self, item: T) -> Result<Self, StamError>where
Self: Sized,
source§unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>
unsafe fn get_unchecked(&self, handle: T::HandleType) -> Option<&T>
source§fn get(&self, item: impl Request<T>) -> Result<&T, StamError>
fn get(&self, item: impl Request<T>) -> Result<&T, StamError>
AnnotationStore::annotation() instead.source§fn get_mut(&mut self, item: impl Request<T>) -> Result<&mut T, StamError>
fn get_mut(&mut self, item: impl Request<T>) -> Result<&mut T, StamError>
source§fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>
fn resolve_id(&self, id: &str) -> Result<T::HandleType, StamError>
source§fn iter(&self) -> StoreIter<'_, T>where
T: Storable<StoreType = Self>,
fn iter(&self) -> StoreIter<'_, T>where
T: Storable<StoreType = Self>,
annotations(), resources() instead. source§fn iter_mut(&mut self) -> StoreIterMut<'_, T>
fn iter_mut(&mut self) -> StoreIterMut<'_, T>
source§fn next_handle(&self) -> T::HandleType
fn next_handle(&self) -> T::HandleType
source§fn last_handle(&self) -> T::HandleType
fn last_handle(&self) -> T::HandleType
source§impl ToCsv for AnnotationDataSet
impl ToCsv for AnnotationDataSet
source§fn to_csv_writer<W>(&self, writer: W, _table: CsvTable) -> Result<(), StamError>where
W: Write,
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>
fn to_csv_file( &self, filename: &str, config: &Config, table: CsvTable ) -> Result<(), StamError>
config, the default is STAM JSON.
Note: This only writes a single table! Just use [AnnotationStore.save()] to write everything.fn to_csv_string(&self, table: Option<CsvTable>) -> Result<String, StamError>
source§impl ToJson for AnnotationDataSet
impl ToJson for AnnotationDataSet
source§fn to_json_writer<W>(&self, writer: W, compact: bool) -> Result<(), StamError>where
W: Write,
fn to_json_writer<W>(&self, writer: W, compact: bool) -> Result<(), StamError>where
W: Write,
Auto Trait Implementations§
impl Freeze for AnnotationDataSet
impl RefUnwindSafe for AnnotationDataSet
impl Send for AnnotationDataSet
impl Sync for AnnotationDataSet
impl Unpin for AnnotationDataSet
impl UnwindSafe for AnnotationDataSet
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more