Skip to content

Commit 6fbdb9e

Browse files
committed
webanno: added parameter to allow skipping context output
1 parent 2267168 commit 6fbdb9e

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/api/webanno.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ pub struct WebAnnoConfig {
154154
/// In the template, you should use the variables {resource} (which is the resource IRI), {begin}, and {end} , they will be substituted accordingly.
155155
/// A common value is {resource}/{begin}/{end} .
156156
pub extra_target_template: Option<String>,
157+
158+
/// Do not output @context (useful if already done at an earlier stage)
159+
pub skip_context: bool,
157160
}
158161

159162
impl Default for WebAnnoConfig {
@@ -166,6 +169,7 @@ impl Default for WebAnnoConfig {
166169
extra_context: Vec::new(),
167170
auto_generated: true,
168171
auto_generator: true,
172+
skip_context: false,
169173
context_namespaces: Vec::new(),
170174
extra_target_template: None,
171175
}
@@ -257,17 +261,21 @@ impl<'store> ResultItem<'store, Annotation> {
257261
return String::new();
258262
}
259263
let mut ann_out = String::with_capacity(1024);
260-
ann_out += "{ \"@context\": ";
261-
ann_out += &config.serialize_context();
262-
ann_out += ",";
263-
if let Some(iri) = self.iri(&config.default_annotation_iri) {
264-
ann_out += &format!(" \"id\": \"{}\",", iri);
265-
} else if config.generate_annotation_iri {
266-
let id = nanoid!();
267-
ann_out += &format!(
268-
" \"id\": \"{}\",",
269-
into_iri(&id, &config.default_annotation_iri)
270-
)
264+
if config.skip_context {
265+
ann_out += "{ "
266+
} else {
267+
ann_out += "{ \"@context\": ";
268+
ann_out += &config.serialize_context();
269+
ann_out += ",";
270+
if let Some(iri) = self.iri(&config.default_annotation_iri) {
271+
ann_out += &format!(" \"id\": \"{}\",", iri);
272+
} else if config.generate_annotation_iri {
273+
let id = nanoid!();
274+
ann_out += &format!(
275+
" \"id\": \"{}\",",
276+
into_iri(&id, &config.default_annotation_iri)
277+
)
278+
}
271279
}
272280
ann_out += " \"type\": \"Annotation\",";
273281

0 commit comments

Comments
 (0)