Skip to content

Commit eb094d6

Browse files
committed
webanno: added no_auto_context parameter for WebAnnoConfig
1 parent a33ee5f commit eb094d6

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/annotation.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ impl PyAnnotation {
479479
#[pyo3(signature = (kwargs=None))]
480480
fn webannotation<'py>(&self, kwargs: Option<&Bound<'py, PyDict>>) -> PyResult<String> {
481481
let mut config = WebAnnoConfig::default();
482+
let mut auto_context = true;
482483
if let Some(kwargs) = kwargs {
483484
if let Ok(Some(v)) = kwargs.get_item("default_annotation_iri") {
484485
config.default_annotation_iri = v.extract()?;
@@ -501,6 +502,10 @@ impl PyAnnotation {
501502
if let Ok(Some(v)) = kwargs.get_item("skip_context") {
502503
config.skip_context = v.extract()?;
503504
}
505+
if let Ok(Some(v)) = kwargs.get_item("no_auto_context") {
506+
let no_auto_context = v.extract()?;
507+
let auto_context = !no_auto_context;
508+
}
504509
if let Ok(Some(v)) = kwargs.get_item("context_namespaces") {
505510
config.context_namespaces = {
506511
let mut namespaces = Vec::new();
@@ -518,7 +523,12 @@ impl PyAnnotation {
518523
}
519524
}
520525
}
521-
self.map(|annotation| Ok(annotation.to_webannotation(&config)))
526+
self.map(|annotation| {
527+
if auto_context {
528+
config = config.auto_extra_context(annotation.store());
529+
}
530+
Ok(annotation.to_webannotation(&config))
531+
})
522532
}
523533

524534
fn test_textselection(

stam.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,15 +859,18 @@ class Annotation:
859859
`default_resource_iri`: `str`
860860
IRI prefix for Text Resources. Will be prepended if the resource public ID is not an IRI yet.
861861
862-
'extra_context`: `[str]`
862+
`extra_context`: `[str]`
863863
Extra JSON-LD context to export, these must be URLs to JSONLD files.
864864
The contexts you provide also double as possible STAM dataset IDs.
865865
Any keys in these sets that are not full IRIs will
866866
be copied as-is to the output (as alias rather than joined with the set ID to form a
867867
full IRI ), leaving interpretation it up to the JSON-LD context.
868868
869-
'skip_context`: `bool`
869+
`skip_context`: `bool`
870870
Do not output @context when outputting web annotations (useful if already done at an earlier stage)
871+
872+
`no_auto_context`: `bool`
873+
Do not automatically add any used STAM datasets ending in `.jsonld` or `.json` to the `extra_context` list. (default: false)
871874
872875
`auto_generated`: `bool`
873876
Automatically add a 'generated' triple for each annotation, with the timestamp of serialisation

0 commit comments

Comments
 (0)