annatto 0.49.0

Converts linguistic data formats based on the graphANNIS data model as intermediate representation and can apply consistency tests.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
use std::{
    collections::{BTreeMap, btree_map::Entry},
    ops::Bound,
    path::Path,
};

use anyhow::{anyhow, bail};
use facet::Facet;
use graphannis::{
    AnnotationGraph,
    graph::{AnnoKey, Edge, NodeID},
    model::{AnnotationComponent, AnnotationComponentType},
};
use graphannis_core::{
    annostorage::EdgeAnnotationStorage,
    dfs::CycleSafeDFS,
    graph::{ANNIS_NS, NODE_NAME_KEY},
    util::join_qname,
};
use itertools::Itertools;
use linked_hash_set::LinkedHashSet;
use serde::{Deserialize, Serialize};

use super::Exporter;

use crate::{progress::ProgressReporter, util::token_helper::TOKEN_KEY};

/// This module exports all ordered nodes and nodes connected by coverage edges of any name into a table.
#[derive(Facet, Deserialize, Serialize, Clone, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct ExportTable {
    /// The provided annotation key defines which nodes within the part-of component define a document. All nodes holding said annotation
    /// will be exported to a file with the name according to the annotation value. Therefore annotation values must not contain path
    /// delimiters.
    ///
    /// Example:
    /// ```toml
    /// [export.config]
    /// doc_anno = "my_namespace::document"
    /// ```
    ///
    /// The default is `annis::doc`.
    #[serde(default = "default_doc_anno", with = "crate::estarde::anno_key")]
    doc_anno: AnnoKey,
    /// The provided character defines the column delimiter. The default value is tab.
    ///
    /// Example:
    /// ```toml
    /// [export.config]
    /// delimiter = ";"
    /// ```
    #[serde(default = "default_delimiter")]
    delimiter: char,
    /// The provided character will be used for quoting values. If nothing is provided, all columns will contain bare values. If a character is provided,
    /// all values will be quoted.
    ///
    /// Example:
    /// ```toml
    /// [export.config]
    /// quote_char = "\""
    /// ```
    #[serde(default)]
    quote_char: Option<char>,
    /// Provides the string sequence used for n/a. Default is the empty string.
    ///
    /// Example:
    /// ```toml
    /// [export.config]
    /// no_value = "n/a"
    /// ```
    #[serde(default)]
    no_value: String,
    /// By listing annotation components, the ingoing edges of that component and their annotations
    /// will be exported as well. Multiple ingoing edges will be separated by a ";". Each exported
    /// node will be checked for ingoing edges in the respective components.
    ///
    /// Example:
    /// ```toml
    /// [export.config]
    /// ingoing = [{ ctype = "Pointing", layer = "", ns = "dep"}]
    /// ```
    #[serde(default, with = "crate::estarde::annotation_component::in_sequence")]
    ingoing: Vec<AnnotationComponent>,
    /// By listing annotation components, the ingoing edges of that component and their annotations
    /// will be exported as well. Multiple outgoing edges will be separated by a ";". Each exported
    /// node will be checked for outgoing edges in the respective components.
    ///
    /// Example:
    /// ```toml
    /// [export.config]
    /// outgoing = [{ ctype = "Pointing", layer = "", ns = "reference"}]
    /// ```
    #[serde(default, with = "crate::estarde::annotation_component::in_sequence")]
    outgoing: Vec<AnnotationComponent>,
    /// If `true` (the default), always output a column with the ID of the node.
    #[serde(default = "default_id_column")]
    id_column: bool,
    /// Export the given columns (qualified annotation names) in the given order.
    #[serde(default)]
    column_names: Vec<String>,
    /// If true, do not output the first line with the column names.
    #[serde(default)]
    skip_header: bool,
    /// If true, do not output the `annis:tok` column
    #[serde(default)]
    skip_token: bool,
}

fn default_id_column() -> bool {
    true
}

impl Default for ExportTable {
    fn default() -> Self {
        Self {
            doc_anno: default_doc_anno(),
            delimiter: default_delimiter(),
            quote_char: Default::default(),
            no_value: Default::default(),
            ingoing: Default::default(),
            outgoing: Default::default(),
            id_column: default_id_column(),
            column_names: Default::default(),
            skip_header: Default::default(),
            skip_token: Default::default(),
        }
    }
}

fn default_doc_anno() -> AnnoKey {
    AnnoKey {
        name: "doc".into(),
        ns: ANNIS_NS.into(),
    }
}

fn default_delimiter() -> char {
    '\t'
}

const FILE_EXTENSION: &str = "csv";

impl Exporter for ExportTable {
    fn export_corpus(
        &self,
        graph: &graphannis::AnnotationGraph,
        output_path: &std::path::Path,
        step_id: crate::StepID,
        tx: Option<crate::workflow::StatusSender>,
    ) -> Result<(), Box<dyn std::error::Error>> {
        let progress = ProgressReporter::new_unknown_total_work(tx.clone(), step_id.clone())?;

        let base_ordering = AnnotationComponent::new(
            AnnotationComponentType::Ordering,
            ANNIS_NS.into(),
            "".into(),
        );
        let storage = graph
            .get_graphstorage(&base_ordering)
            .ok_or(anyhow!("Storage of base ordering unavailable"))?;
        let part_of_storage = graph
            .get_graphstorage(&AnnotationComponent::new(
                AnnotationComponentType::PartOf,
                ANNIS_NS.into(),
                "".into(),
            ))
            .ok_or(anyhow!("Part-of storage unavailbale."))?;
        let coverage_storages = graph
            .get_all_components(Some(AnnotationComponentType::Coverage), None)
            .iter()
            .filter_map(|c| graph.get_graphstorage(c))
            .collect_vec();
        if coverage_storages.is_empty() {
            progress.warn("No coverage storages available")?;
        }
        let mut doc_node_to_start = BTreeMap::new();
        for node in storage.source_nodes().flatten().filter(|n| {
            !storage.has_ingoing_edges(*n).unwrap_or_default()
                && !coverage_storages
                    .iter()
                    .any(|s| s.has_outgoing_edges(*n).unwrap_or_default())
        }) {
            let dfs = CycleSafeDFS::new(
                part_of_storage.as_edgecontainer(),
                node,
                0,
                NodeID::MAX as usize,
            );
            for nxt in dfs {
                let n = nxt?.node;
                if graph
                    .get_node_annos()
                    .has_value_for_item(&n, &self.doc_anno)
                    .unwrap_or_default()
                {
                    if let Entry::Vacant(e) = doc_node_to_start.entry(n) {
                        e.insert(node);
                        break;
                    } else {
                        let doc_node_name = graph
                            .get_node_annos()
                            .get_value_for_item(&n, &NODE_NAME_KEY)?
                            .unwrap_or_default();
                        return Err(anyhow!(
                            "Document {doc_node_name} has more than one start node for base ordering."
                        )
                        .into());
                    }
                }
            }
        }
        let progress = ProgressReporter::new(tx, step_id, doc_node_to_start.len())?;
        progress.info(format!("Exporting {} documents", doc_node_to_start.len()))?;
        doc_node_to_start
            .into_iter()
            .try_for_each(move |(doc, start)| -> anyhow::Result<()> {
                self.export_document(graph, output_path, doc, start)?;
                progress.worked(1)?;
                Ok(())
            })?;
        Ok(())
    }

    fn file_extension(&self) -> &str {
        FILE_EXTENSION
    }
}

type Data = BTreeMap<usize, String>;
type EdgeData = BTreeMap<usize, LinkedHashSet<String>>; // insertion order is critical
type SingleEdgeData<'a> = (String, &'a AnnotationComponent, Vec<(String, String)>);

impl ExportTable {
    fn export_document(
        &self,
        graph: &AnnotationGraph,
        corpus_path: &Path,
        doc_node: NodeID,
        start_node: NodeID,
    ) -> Result<(), anyhow::Error> {
        let node_annos = graph.get_node_annos();
        let doc_node_name = node_annos
            .get_value_for_item(&doc_node, &self.doc_anno)?
            .ok_or(anyhow!("Could not determine document node name."))?;
        let ordering_storage = graph
            .get_graphstorage(&AnnotationComponent::new(
                AnnotationComponentType::Ordering,
                ANNIS_NS.into(),
                "".into(),
            ))
            .ok_or(anyhow!("Storage of ordering component unavailable."))?;
        let ordered_nodes = ordering_storage
            .find_connected(start_node, 0, std::ops::Bound::Excluded(usize::MAX))
            .flatten()
            .collect_vec();
        let mut table_data: Vec<Data> = Vec::with_capacity(ordered_nodes.len());
        let coverage_components =
            graph.get_all_components(Some(AnnotationComponentType::Coverage), None);
        let coverage_storages = coverage_components
            .iter()
            .filter_map(|c| graph.get_graphstorage(c))
            .collect_vec();
        let mut index_map = BTreeMap::default();
        for c in &self.column_names {
            index_map.insert(c.to_string(), index_map.len());
            if self.id_column {
                let id_name = format!("id_{c}");
                index_map.insert(id_name.to_string(), index_map.len());
            }
        }

        let follow_edges = !self.outgoing.is_empty() || !self.ingoing.is_empty();
        for node in ordered_nodes {
            let reachable_nodes = coverage_storages
                .iter()
                .flat_map(|s| {
                    s.find_connected_inverse(node, 0, std::ops::Bound::Excluded(usize::MAX))
                })
                .flatten();
            let mut data = Data::default();
            let mut edge_column_data = EdgeData::default();
            for rn in reachable_nodes {
                // reachable nodes contains the start node
                let node_name = node_annos
                    .get_value_for_item(&rn, &NODE_NAME_KEY)?
                    .ok_or(anyhow!("Node has no name"))?;
                for anno_key in node_annos.get_all_keys_for_item(&rn, None, None)? {
                    if anno_key.ns.as_str() != ANNIS_NS
                        || (!self.skip_token && anno_key.as_ref() == TOKEN_KEY.as_ref())
                    {
                        let qname = join_qname(anno_key.ns.as_str(), anno_key.name.as_str());
                        let id_name = format!("id_{qname}");
                        let index = if let Some(index) = index_map.get(&qname) {
                            *index
                        } else if self.id_column {
                            index_map.insert(qname.to_string(), index_map.len());
                            index_map.insert(id_name.to_string(), index_map.len());
                            index_map.len() - 2
                        } else {
                            index_map.insert(qname.to_string(), index_map.len());
                            index_map.len() - 1
                        };
                        let value = node_annos
                            .get_value_for_item(&rn, &anno_key)?
                            .ok_or(anyhow!("Annotation has no value"))?;
                        data.insert(index, value.to_string());
                        if self.id_column {
                            data.insert(index + 1, node_name.to_string());
                        }
                    }
                }
                if follow_edges {
                    let (sources, targets) = self.connected_nodes(graph, rn)?;
                    let mut prefixes = sources.iter().map(|_| "in").collect_vec();
                    prefixes.extend(targets.iter().map(|_| "out"));
                    for ((connected_node_name, component, mut edge_annotations), prefix) in
                        sources.into_iter().chain(targets.into_iter()).zip(prefixes)
                    {
                        let qualified_name = [
                            prefix,
                            component.get_type().to_string().as_str(),
                            component.layer.as_str(),
                            component.name.as_str(),
                        ]
                        .join("_");
                        edge_annotations.extend([("".to_string(), connected_node_name)]);
                        for (name, value) in edge_annotations {
                            let qname = if name.is_empty() {
                                qualified_name.to_string()
                            } else {
                                [qualified_name.as_str(), name.as_str()].join("_")
                            };
                            let index = if let Some(index) = index_map.get(&qname) {
                                *index
                            } else {
                                index_map.insert(qname, index_map.len());
                                index_map.len() - 1
                            };
                            match edge_column_data.entry(index) {
                                Entry::Vacant(e) => {
                                    let mut new_value = LinkedHashSet::default();
                                    new_value.insert(value);
                                    e.insert(new_value);
                                }
                                Entry::Occupied(mut e) => {
                                    e.get_mut().insert(value);
                                }
                            };
                        }
                    }
                }
            }
            data.extend(
                edge_column_data
                    .into_iter()
                    .map(|(ix, value_set)| (ix, value_set.iter().join(";").to_string())),
            );
            table_data.push(data);
        }
        let file_path =
            Path::new(corpus_path).join(format!("{doc_node_name}.{}", self.file_extension()));
        let mut writer_builder = csv::WriterBuilder::new();
        writer_builder.delimiter(self.delimiter as u8);
        if let Some(c) = &self.quote_char {
            writer_builder.quote(*c as u8);
            writer_builder.quote_style(csv::QuoteStyle::Always);
        }
        let mut writer = writer_builder.from_path(file_path)?;
        if !self.skip_header {
            let header = index_map
                .iter()
                .sorted_by(|(_, v), (_, v_)| v.cmp(v_))
                .map(|(k, _)| k)
                .collect_vec();
            writer.write_record(header)?;
        }
        let index_bound = index_map.len();
        for mut entry in table_data {
            let mut row = Vec::with_capacity(index_bound);
            for col_index in 0..index_bound {
                row.push(
                    entry
                        .remove(&col_index)
                        .unwrap_or(self.no_value.to_string())
                        .to_string(),
                );
            }
            if !row.iter().all(String::is_empty) {
                writer.write_record(&row)?;
            }
        }
        Ok(())
    }

    fn connected_nodes(
        &self,
        graph: &AnnotationGraph,
        node: NodeID,
    ) -> Result<(Vec<SingleEdgeData<'_>>, Vec<SingleEdgeData<'_>>), anyhow::Error> {
        let mut sources: Vec<SingleEdgeData> = Vec::new();
        let mut targets: Vec<SingleEdgeData> = Vec::new();
        for component in &self.ingoing {
            if let Some(storage) = graph.get_graphstorage(component) {
                let sources_ingoing = storage
                    .find_connected_inverse(node, 1, Bound::Excluded(2))
                    .flatten()
                    .collect_vec();
                for src in sources_ingoing {
                    if let Some(node_name) = graph
                        .get_node_annos()
                        .get_value_for_item(&src, &NODE_NAME_KEY)?
                    {
                        let edge = Edge {
                            source: src,
                            target: node,
                        };
                        let anno_storage = storage.get_anno_storage();
                        sources.push((
                            node_name.to_string(),
                            component,
                            edge_annos(anno_storage, &edge)?,
                        ));
                    }
                }
            } else {
                bail!(
                    "Component {}::{}::{} has no storage.",
                    component.get_type(),
                    component.layer,
                    component.name
                );
            }
        }
        for component in &self.outgoing {
            if let Some(storage) = graph.get_graphstorage(component) {
                let targets_outgoing = storage
                    .find_connected(node, 1, Bound::Excluded(2))
                    .flatten()
                    .collect_vec();
                for tgt in targets_outgoing {
                    if let Some(node_name) = graph
                        .get_node_annos()
                        .get_value_for_item(&tgt, &NODE_NAME_KEY)?
                    {
                        let edge = Edge {
                            source: node,
                            target: tgt,
                        };
                        let anno_storage = storage.get_anno_storage();
                        targets.push((
                            node_name.to_string(),
                            component,
                            edge_annos(anno_storage, &edge)?,
                        ));
                    }
                }
            } else {
                bail!(
                    "Component {}::{}::{} has no storage.",
                    component.get_type(),
                    component.layer,
                    component.name
                );
            }
        }
        Ok((sources, targets))
    }
}

fn edge_annos(
    anno_storage: &dyn EdgeAnnotationStorage,
    edge: &Edge,
) -> Result<Vec<(String, String)>, anyhow::Error> {
    let mut annotations = Vec::new();
    for anno_key in anno_storage.get_all_keys_for_item(edge, None, None)? {
        if anno_key.ns != ANNIS_NS {
            let qname = join_qname(&anno_key.ns, &anno_key.name);
            if let Some(value) = anno_storage.get_value_for_item(edge, &anno_key)? {
                annotations.push((qname, value.to_string()));
            }
        }
    }
    Ok(annotations)
}

#[cfg(test)]
mod tests {
    use std::path::Path;

    use graphannis::{
        AnnotationGraph,
        graph::AnnoKey,
        model::{AnnotationComponent, AnnotationComponentType},
    };
    use graphannis_core::graph::ANNIS_NS;
    use insta::assert_snapshot;

    use crate::{
        StepID,
        exporter::table::ExportTable,
        importer::{
            GenericImportConfiguration, Importer, conllu::ImportCoNLLU, exmaralda::ImportEXMARaLDA,
        },
        test_util::export_to_string,
    };

    #[test]
    fn serialize() {
        let module = ExportTable::default();
        let serialization = toml::to_string(&module);
        assert!(
            serialization.is_ok(),
            "Serialization failed: {:?}",
            serialization.err()
        );
        assert_snapshot!(serialization.unwrap());
    }

    #[test]
    fn serialize_custom() {
        let module = ExportTable {
            column_names: vec!["text".to_string(), "lemma".to_string(), "pos".to_string()],
            doc_anno: AnnoKey {
                ns: "not_annis".into(),
                name: "not_doc".into(),
            },
            delimiter: ';',
            quote_char: Some('"'),
            no_value: "NA".to_string(),
            ingoing: vec![AnnotationComponent::new(
                AnnotationComponentType::Coverage,
                ANNIS_NS.into(),
                "".into(),
            )],
            outgoing: vec![AnnotationComponent::new(
                AnnotationComponentType::Pointing,
                "".into(),
                "reference".into(),
            )],
            id_column: true,
            skip_header: false,
            skip_token: false,
        };
        let serialization = toml::to_string(&module);
        assert!(
            serialization.is_ok(),
            "Serialization failed: {:?}",
            serialization.err()
        );
        assert_snapshot!(serialization.unwrap());
    }

    #[test]
    fn core() {
        let exmaralda = ImportEXMARaLDA::default();
        let mprt = exmaralda.import_corpus(
            Path::new("tests/data/import/exmaralda/clean/import/exmaralda/"),
            StepID {
                module_name: "test_import_exb".to_string(),
                path: None,
            },
            GenericImportConfiguration::new_with_default_extensions(&exmaralda),
            None,
        );
        assert!(mprt.is_ok());
        let mut update_import = mprt.unwrap();
        let g = AnnotationGraph::with_default_graphstorages(true);
        assert!(g.is_ok());
        let mut graph = g.unwrap();
        assert!(graph.apply_update(&mut update_import, |_| {}).is_ok());
        let export = export_to_string(&graph, ExportTable::default());
        assert!(export.is_ok(), "error: {:?}", export.err());
        assert_snapshot!(export.unwrap());
    }

    #[test]
    fn quoted() {
        let exmaralda = ImportEXMARaLDA::default();
        let mprt = exmaralda.import_corpus(
            Path::new("tests/data/import/exmaralda/clean/import/exmaralda/"),
            StepID {
                module_name: "test_import_exb".to_string(),
                path: None,
            },
            GenericImportConfiguration::new_with_default_extensions(&exmaralda),
            None,
        );
        assert!(mprt.is_ok());
        let mut update_import = mprt.unwrap();
        let g = AnnotationGraph::with_default_graphstorages(true);
        assert!(g.is_ok());
        let mut graph = g.unwrap();
        assert!(graph.apply_update(&mut update_import, |_| {}).is_ok());
        let export = export_to_string(
            &graph,
            ExportTable {
                quote_char: Some('"'),
                skip_token: true,
                ..Default::default()
            },
        );
        assert!(export.is_ok(), "error: {:?}", export.err());
        assert_snapshot!(export.unwrap());
    }

    #[test]
    fn edge_features() {
        let to_conll = ImportCoNLLU::default();
        let mprt = to_conll.import_corpus(
            Path::new("tests/data/import/conll/valid/"),
            StepID {
                module_name: "test_import_conll".to_string(),
                path: None,
            },
            GenericImportConfiguration::new_with_default_extensions(&to_conll),
            None,
        );
        assert!(mprt.is_ok());
        let mut update_import = mprt.unwrap();
        let g = AnnotationGraph::with_default_graphstorages(true);
        assert!(g.is_ok());
        let mut graph = g.unwrap();
        assert!(graph.apply_update(&mut update_import, |_| {}).is_ok());
        let export = export_to_string(
            &graph,
            ExportTable {
                ingoing: vec![AnnotationComponent::new(
                    AnnotationComponentType::Pointing,
                    "".into(),
                    "dep".into(),
                )],
                ..Default::default()
            },
        );
        assert!(export.is_ok(), "error: {:?}", export.err());
        assert_snapshot!(export.unwrap());
    }

    #[test]
    fn custom() {
        let to_conll = ImportCoNLLU::default();
        let mprt = to_conll.import_corpus(
            Path::new("tests/data/import/conll/valid/"),
            StepID {
                module_name: "test_import_conll".to_string(),
                path: None,
            },
            GenericImportConfiguration::new_with_default_extensions(&to_conll),
            None,
        );
        assert!(mprt.is_ok());
        let mut update_import = mprt.unwrap();
        let g = AnnotationGraph::with_default_graphstorages(true);
        assert!(g.is_ok());
        let mut graph = g.unwrap();
        assert!(graph.apply_update(&mut update_import, |_| {}).is_ok());
        let export = export_to_string(
            &graph,
            ExportTable {
                delimiter: ';',
                no_value: "n/a".to_string(),
                quote_char: Some('\''),
                ingoing: vec![AnnotationComponent::new(
                    AnnotationComponentType::Pointing,
                    "".into(),
                    "dep".into(),
                )],
                outgoing: vec![AnnotationComponent::new(
                    AnnotationComponentType::Pointing,
                    "".into(),
                    "dep".into(),
                )],
                ..Default::default()
            },
        );
        assert!(export.is_ok(), "error: {:?}", export.err());
        assert_snapshot!(export.unwrap());
    }

    #[test]
    fn manual_column_ordering_no_id() {
        let exmaralda = ImportEXMARaLDA::default();
        let mprt = exmaralda.import_corpus(
            Path::new("tests/data/import/exmaralda/clean/import/exmaralda/"),
            StepID {
                module_name: "test_import_exb".to_string(),
                path: None,
            },
            GenericImportConfiguration::new_with_default_extensions(&exmaralda),
            None,
        );
        assert!(mprt.is_ok());
        let mut update_import = mprt.unwrap();
        let g = AnnotationGraph::with_default_graphstorages(true);
        assert!(g.is_ok());
        let mut graph = g.unwrap();
        assert!(graph.apply_update(&mut update_import, |_| {}).is_ok());
        let m = ExportTable {
            column_names: vec![
                "norm::pos".to_string(),
                "annis::tok".to_string(),
                "dipl::sentence".to_string(),
            ],
            id_column: false,
            ..Default::default()
        };
        let export = export_to_string(&graph, m);
        assert!(export.is_ok(), "error: {:?}", export.err());
        assert_snapshot!(export.unwrap());
    }

    #[test]
    fn manual_column_ordering_with_id() {
        let exmaralda = ImportEXMARaLDA::default();
        let mprt = exmaralda.import_corpus(
            Path::new("tests/data/import/exmaralda/clean/import/exmaralda/"),
            StepID {
                module_name: "test_import_exb".to_string(),
                path: None,
            },
            GenericImportConfiguration::new_with_default_extensions(&exmaralda),
            None,
        );
        assert!(mprt.is_ok());
        let mut update_import = mprt.unwrap();
        let g = AnnotationGraph::with_default_graphstorages(true);
        assert!(g.is_ok());
        let mut graph = g.unwrap();
        assert!(graph.apply_update(&mut update_import, |_| {}).is_ok());
        let m = ExportTable {
            column_names: vec![
                "norm::pos".to_string(),
                "annis::tok".to_string(),
                "dipl::sentence".to_string(),
            ],
            id_column: true,
            ..Default::default()
        };
        let export = export_to_string(&graph, m);
        assert!(export.is_ok(), "error: {:?}", export.err());
        assert_snapshot!(export.unwrap());
    }

    #[test]
    fn no_id_column() {
        let exmaralda = ImportEXMARaLDA::default();
        let mprt = exmaralda.import_corpus(
            Path::new("tests/data/import/exmaralda/clean/import/exmaralda/"),
            StepID {
                module_name: "test_import_exb".to_string(),
                path: None,
            },
            GenericImportConfiguration::new_with_default_extensions(&exmaralda),
            None,
        );
        assert!(mprt.is_ok());
        let mut update_import = mprt.unwrap();
        let g = AnnotationGraph::with_default_graphstorages(true);
        assert!(g.is_ok());
        let mut graph = g.unwrap();
        assert!(graph.apply_update(&mut update_import, |_| {}).is_ok());
        let mut exporter = ExportTable::default();
        exporter.id_column = false;
        exporter.skip_token = true;
        let export = export_to_string(&graph, exporter);
        assert!(export.is_ok(), "error: {:?}", export.err());
        assert_snapshot!(export.unwrap());
    }
}