Skip to content

Commit 0dcd8e4

Browse files
committed
implemented split() from stam-tools
1 parent 084d8c7 commit 0dcd8e4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/annotationstore.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::resources::PyTextResource;
1414
use crate::selector::PySelector;
1515
use crate::textselection::PyTextSelection;
1616
use stam::*;
17+
use stamtools::split::{split, SplitMode};
1718
use stamtools::view::{AnsiWriter, Highlight, HtmlWriter};
1819

1920
#[pyclass(dict, module = "stam", name = "AnnotationStore")]
@@ -556,6 +557,23 @@ impl PyAnnotationStore {
556557
)),
557558
}
558559
}
560+
561+
#[pyo3(signature = (querystrings, retain))]
562+
fn split<'py>(&mut self, querystrings: Vec<&str>, retain: bool) -> PyResult<()> {
563+
let mode = if retain {
564+
SplitMode::Retain
565+
} else {
566+
SplitMode::Delete
567+
};
568+
let mut queries: Vec<Query> = Vec::new();
569+
for querystring in querystrings {
570+
let query: Query = querystring
571+
.try_into()
572+
.map_err(|err| PyStamError::new_err(format!("{}", err)))?;
573+
queries.push(query);
574+
}
575+
self.map_store_mut(|store| Ok(split(store, queries, mode, false)))
576+
}
559577
}
560578

561579
pub(crate) trait MapStore {

stam.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ class AnnotationStore:
365365
Collapse all tags on initial view (html only)
366366
"""
367367

368+
def split(self, queries: List[str], retain: bool):
369+
"""
370+
Splits an annotation store by either retaining (if `retain == True`) or removing (if `retain == False`) the items selected by the queries.
371+
Queries must be STAMQL queries that select annotations, resources or datasets.
372+
This deletes items from the store along with all their dependencies and comes with a reasonable performance overhead.
373+
"""
368374

369375

370376

0 commit comments

Comments
 (0)