annatto 0.50.1

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
//! Created edges between nodes based on their annotation value.
use super::Manipulator;
use crate::{
    StepID, error::AnnattoError, progress::ProgressReporter, util::update_graph_silent,
    workflow::StatusSender,
};
use anyhow::anyhow;
use facet::Facet;
use graphannis::{
    AnnotationGraph, aql,
    graph::NodeID,
    model::AnnotationComponent,
    update::{GraphUpdate, UpdateEvent},
};
use graphannis_core::{graph::NODE_NAME_KEY, types::AnnoKey};
use itertools::Itertools;
use serde::Serialize;
use serde_derive::Deserialize;
use std::{collections::BTreeMap, ops::Deref};

/// Link nodes within a graph. Source and target of a link are determined via
/// queries; type, layer, and name of the link component can be configured.
///
/// This manipulator collects a source node set and a target node set given
/// the respective queries. In each node set, the nodes are mapped to a value.
/// Between each node in the source node set and the target node set, that are
/// assigned the same value, an edge is created (from source to target node).
/// The edges will be part of the defined component. Additionally, annotations
/// can be moved from the source or target node onto the edge.
///
/// The values assigned to each node in the source or target node set can be
/// created in several ways:
/// - a value from a single node in the query
/// - a concatenated value from multiple nodes in the query
/// - a concatenated value using a delimiter (`value_sep`) from multiple nodes in the query
///
/// The value formation is the crucial part of building correct edges.
///
/// Example:
/// ```toml
/// [[graph_op]]
/// action = "link"
///
/// [graph_op.config]
/// source_query = "tok _=_ id @* doc"
/// source_node = 1
/// source_value = [3, 2]
/// target_query = "func _=_ norm _=_ norm_id @* doc"
/// target_node = 2
/// target_value = [4, 3]
/// target_to_edge = [1]
/// component = { ctype = "Pointing", layer = "", name = "align" }
/// value_sep = "-"
/// ```
///
/// The example builds the source node set by trying to find all tok-nodes that have an id
/// and are linked to a node with a `doc` annotation (the document name) via a PartOf edge.
/// As source node, that goes into the said, the first (`1`) node from each result is
/// chosen, i. e. the token. The value, that is used to find a mapping partner from the
/// target node set, is build with the third (`3`) and second (`2`) node, concatenated
/// by a dash (s. `value_sep`). So a token with id "7", which is part of "document1",
/// will be assigned the value "document1-7".
///
/// The target configuration of query, node, and value maps nodes with a norm (`2`)
/// annotation to values, that concatenate the document name and the `norm_id`
/// annotation via a dash. So a norm token with id "7" in document "document1" will
/// also be assigned the value "document1-7".
///
/// This leads to edges from tokens with the same value to norm nodes with the same
/// value within the graphANNIS component `Pointing//align`.
///
/// Additionally, all edges are assigned a func annotation retrieved in the target query,
/// as `target_to_edge` is configured to copy annotation "1", which is `func` in the
/// example query, to the edge.
///
#[derive(Facet, Deserialize, Serialize, Clone, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct LinkNodes {
    /// The AQL query to find all source node annotations. Source and target nodes are then paired by equal value for their query match.
    source_query: String,
    /// The 1-based index selecting the value providing node in the AQL source query.
    source_node: usize,
    /// Contains one or multiple 1-based indexes, from which (in order of mentioning) the value for mapping source and target will be concatenated.
    source_value: Vec<usize>,
    /// This 1-based index list can be used to copy the given annotations from the source query to the edge that is to be created.
    #[serde(default)]
    source_to_edge: Vec<usize>,
    /// The AQL query to find all target node annotations.
    target_query: String,
    /// The 1-based index selecting the value providing node in the AQL target query.
    target_node: usize,
    /// Contains one or multiple 1-based indexes, from which (in order of mentioning) the value for mapping source and target will be concatenated.
    target_value: Vec<usize>,
    /// This 1-based index list can be used to copy the given annotations from the target query to the edge that is to be created.
    #[serde(default)]
    target_to_edge: Vec<usize>,
    /// The edge component to be built.
    #[serde(with = "crate::estarde::annotation_component")]
    component: AnnotationComponent,
    /// In case of multiple `source_values` or `target_values` this delimiter (default empty string) will be used for value concatenation.
    #[serde(default)]
    value_sep: String,
}

impl Manipulator for LinkNodes {
    fn manipulate_corpus(
        &self,
        graph: &mut graphannis::AnnotationGraph,
        _workflow_directory: &std::path::Path,
        step_id: StepID,
        tx: Option<crate::workflow::StatusSender>,
    ) -> Result<(), Box<dyn std::error::Error>> {
        let link_sources = gather_link_data(
            graph,
            self.source_query.to_string(),
            self.source_node,
            &self.source_value,
            &self.source_to_edge,
            &self.value_sep,
            &step_id,
        )?;
        let link_targets = gather_link_data(
            graph,
            self.target_query.to_string(),
            self.target_node,
            &self.target_value,
            &self.target_to_edge,
            &self.value_sep,
            &step_id,
        )?;
        let mut update = self.link_nodes(link_sources, link_targets, tx, step_id)?;
        update_graph_silent(graph, &mut update)?;
        Ok(())
    }

    fn requires_statistics(&self) -> bool {
        true
    }
}

type NodeBundle = Vec<(AnnoKey, NodeID)>;

/// This function executes a single query and returns bundled results or an error.
/// A bundled result is the annotation key the node has a match for and the matching node itself.
fn retrieve_nodes_with_values(
    graph: &AnnotationGraph,
    query: String,
) -> Result<Vec<NodeBundle>, Box<dyn std::error::Error>> {
    let mut node_bundles = Vec::new();
    let disj = aql::parse(&query, false)?;

    for m in aql::execute_query_on_graph(graph, &disj, true, None)?.flatten() {
        node_bundles.push(
            m.into_iter()
                .map(|match_member| (match_member.anno_key.deref().clone(), match_member.node))
                .collect_vec(),
        );
    }
    Ok(node_bundles)
}

type NodeNameWithEdgeData = (String, Vec<(AnnoKey, String)>);

/// This function queries the corpus graph and returns the relevant match data.
/// The returned data maps an annotation value or a joint value (value) to the nodes holding said value.
fn gather_link_data(
    graph: &AnnotationGraph,
    query: String,
    node_index: usize,
    value_indices: &[usize],
    edge_indices: &[usize],
    sep: &str,
    step_id: &StepID,
) -> Result<BTreeMap<String, Vec<NodeNameWithEdgeData>>, Box<dyn std::error::Error>> {
    let mut data: BTreeMap<String, Vec<NodeNameWithEdgeData>> = BTreeMap::new();
    let node_annos = graph.get_node_annos();
    for group_of_bundles in retrieve_nodes_with_values(graph, query.to_string())? {
        if let Some((_, link_node_id)) = group_of_bundles.get(node_index - 1) {
            let mut target_data = Vec::new();
            let mut value_segments = Vec::new();
            let mut edge_data = Vec::new();
            for edge_index in edge_indices {
                if let Some((k, n)) = group_of_bundles.get(edge_index - 1)
                    && let Some(v) = graph.get_node_annos().get_value_for_item(n, k)?
                {
                    edge_data.push(((*k).clone(), v.to_string()));
                }
            }
            for value_index in value_indices {
                if let Some((anno_key, value_node_id)) = group_of_bundles.get(*value_index - 1) {
                    if let Some(anno_value) =
                        node_annos.get_value_for_item(value_node_id, anno_key)?
                    {
                        value_segments.push(anno_value.trim().to_lowercase()); // simply concatenate values
                    }
                } else {
                    return Err(AnnattoError::Manipulator {
                        reason: format!(
                            "Could not extract node with value index {value_index} from query `{}`",
                            &query
                        ),
                        manipulator: step_id.module_name.to_string(),
                    }
                    .into());
                }
                let link_node_name = graph
                    .get_node_annos()
                    .get_value_for_item(link_node_id, &NODE_NAME_KEY)?
                    .ok_or(anyhow!("Could not determine node name."))?
                    .to_string();
                target_data.push((link_node_name, edge_data.clone())); // memory-inefficient for large queries, but that should usually not happen
            }
            let joint_value = value_segments.join(sep);
            if let Some(nodes_with_value) = data.get_mut(&joint_value) {
                nodes_with_value.extend(target_data);
            } else {
                data.insert(joint_value, target_data);
            }
        } else {
            return Err(AnnattoError::Manipulator {
                reason: format!(
                    "Could not extract node with node index {node_index} from query `{}`",
                    &query
                ),
                manipulator: step_id.module_name.to_string(),
            }
            .into());
        }
    }
    Ok(data)
}

impl LinkNodes {
    fn link_nodes(
        &self,
        sources: BTreeMap<String, Vec<NodeNameWithEdgeData>>,
        targets: BTreeMap<String, Vec<NodeNameWithEdgeData>>,
        tx: Option<StatusSender>,
        step_id: StepID,
    ) -> Result<GraphUpdate, Box<dyn std::error::Error>> {
        let mut update = GraphUpdate::default();
        let progress = ProgressReporter::new(tx, step_id, sources.len())?;
        for (anno_value, node_list) in sources {
            if let Some(target_node_list) = targets.get(&anno_value) {
                for ((source, src_edge_data), (target, tgt_edge_data)) in
                    node_list.iter().cartesian_product(target_node_list)
                {
                    update.add_event(UpdateEvent::AddEdge {
                        source_node: source.to_string(),
                        target_node: target.to_string(),
                        layer: self.component.layer.to_string(),
                        component_type: self.component.get_type().to_string(),
                        component_name: self.component.name.to_string(),
                    })?;
                    for data in [src_edge_data, tgt_edge_data] {
                        for (k, v) in data {
                            update.add_event(UpdateEvent::AddEdgeLabel {
                                source_node: source.to_string(),
                                target_node: target.to_string(),
                                layer: self.component.layer.to_string(),
                                component_type: self.component.get_type().to_string(),
                                component_name: self.component.name.to_string(),
                                anno_ns: k.ns.to_string(),
                                anno_name: k.name.to_string(),
                                anno_value: v.to_string(),
                            })?;
                        }
                    }
                }
            }
            progress.worked(1)?;
        }
        Ok(update)
    }
}

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

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

    use crate::{
        StepID,
        exporter::graphml::GraphMLExporter,
        manipulator::{Manipulator, link::LinkNodes},
        test_util::export_to_string,
        util::example_generator,
        util::update_graph_silent,
    };

    #[test]
    fn serialize_custom() {
        let module = LinkNodes {
            source_query: "node @* doc=/1/".to_string(),
            source_node: 1,
            source_value: vec![1],
            source_to_edge: vec![],
            target_query: "node @* doc=/2/".to_string(),
            target_node: 1,
            target_value: vec![1],
            target_to_edge: vec![],
            component: AnnotationComponent::new(
                AnnotationComponentType::Pointing,
                "".into(),
                "link".into(),
            ),
            value_sep: "#".to_string(),
        };
        let serialization = toml::to_string(&module);
        assert!(
            serialization.is_ok(),
            "Serialization failed: {:?}",
            serialization.err()
        );
        assert_snapshot!(serialization.unwrap());
    }

    #[test]
    fn graph_statistics() {
        let g = AnnotationGraph::with_default_graphstorages(false);
        assert!(g.is_ok());
        let mut graph = g.unwrap();
        let mut u = GraphUpdate::default();
        example_generator::create_corpus_structure_simple(&mut u);
        assert!(update_graph_silent(&mut graph, &mut u).is_ok());
        let module = LinkNodes {
            source_query: "node".to_string(),
            source_node: 1,
            source_value: vec![],
            source_to_edge: vec![],
            target_query: "node".to_string(),
            target_node: 1,
            target_value: vec![],
            target_to_edge: vec![],
            component: AnnotationComponent::new(
                AnnotationComponentType::Pointing,
                "".into(),
                "link".into(),
            ),
            value_sep: "".to_string(),
        };
        assert!(
            module
                .validate_graph(
                    &mut graph,
                    StepID {
                        module_name: "test".to_string(),
                        path: None
                    },
                    None
                )
                .is_ok()
        );
        assert!(graph.global_statistics.is_some());
    }

    #[test]
    fn link() -> Result<(), Box<dyn std::error::Error>> {
        let mut graph = source_graph()?;
        let linker = LinkNodes {
            source_query: "norm _=_ lemma".to_string(),
            source_node: 1,
            source_value: vec![2],
            target_query: "morph & node? !> #1".to_string(),
            target_node: 1,
            target_value: vec![1],
            component: AnnotationComponent::new(
                AnnotationComponentType::Pointing,
                "".into(),
                "morphology".into(),
            ),
            value_sep: "".to_string(),
            source_to_edge: vec![2],
            target_to_edge: vec![1],
        };
        linker.manipulate_corpus(
            &mut graph,
            Path::new("./"),
            StepID {
                module_name: "test_linker".into(),
                path: None,
            },
            None,
        )?;
        let actual = export_to_string(&graph, GraphMLExporter::default())?;
        assert_snapshot!(actual);
        Ok(())
    }

    fn source_graph() -> Result<AnnotationGraph, Box<dyn std::error::Error>> {
        // copied this from exmaralda test
        let mut graph = AnnotationGraph::with_default_graphstorages(true)?;
        let mut u = GraphUpdate::default();
        u.add_event(UpdateEvent::AddNode {
            node_name: "import".to_string(),
            node_type: "corpus".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/exmaralda".to_string(),
            node_type: "corpus".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/exmaralda".to_string(),
            target_node: "import".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::PartOf.to_string(),
            component_name: "".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/exmaralda/test_doc".to_string(),
            node_type: "corpus".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/exmaralda/test_doc".to_string(),
            target_node: "import/exmaralda".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::PartOf.to_string(),
            component_name: "".to_string(),
        })?;
        let tlis = ["T286", "T0", "T1", "T2", "T3", "T4"];
        let times = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0];
        for tli in tlis {
            let node_name = format!("import/exmaralda/test_doc#{}", tli);
            u.add_event(UpdateEvent::AddNode {
                node_name: node_name.to_string(),
                node_type: "node".to_string(),
            })?;
            u.add_event(UpdateEvent::AddNodeLabel {
                node_name: node_name.to_string(),
                anno_ns: ANNIS_NS.to_string(),
                anno_name: "tok".to_string(),
                anno_value: " ".to_string(),
            })?;
            u.add_event(UpdateEvent::AddNodeLabel {
                node_name: node_name.to_string(),
                anno_ns: ANNIS_NS.to_string(),
                anno_name: "layer".to_string(),
                anno_value: "default_layer".to_string(),
            })?;
        }
        for window in tlis.windows(2) {
            let tli0 = window[0];
            let tli1 = window[1];
            let source = format!("import/exmaralda/test_doc#{}", tli0);
            let target = format!("import/exmaralda/test_doc#{}", tli1);
            u.add_event(UpdateEvent::AddEdge {
                source_node: source,
                target_node: target,
                layer: ANNIS_NS.to_string(),
                component_type: AnnotationComponentType::Ordering.to_string(),
                component_name: "".to_string(),
            })?;
        }
        let mut prev: Option<String> = None;
        for (tpe, spk, name, value, start, end, reset_after) in [
            ("t", "dipl", "dipl", "I'm", 0, 2, false),
            ("t", "dipl", "dipl", "in", 2, 3, false),
            ("t", "dipl", "dipl", "New", 3, 4, false),
            ("t", "dipl", "dipl", "York", 4, 5, true),
            ("a", "dipl", "sentence", "1", 0, 5, true),
            ("t", "norm", "norm", "I", 0, 1, false),
            ("t", "norm", "norm", "am", 1, 2, false),
            ("t", "norm", "norm", "in", 2, 3, false),
            ("t", "norm", "norm", "New York", 3, 5, true),
            ("a", "norm", "lemma", "I", 0, 1, true),
            ("a", "norm", "lemma", "be", 1, 2, true),
            ("a", "norm", "lemma", "in", 2, 3, true),
            ("a", "norm", "lemma", "New York", 3, 5, true),
            ("a", "norm", "pos", "PRON", 0, 1, true),
            ("a", "norm", "pos", "VERB", 1, 2, true),
            ("a", "norm", "pos", "ADP", 2, 3, true),
            ("a", "norm", "pos", "PROPN", 3, 5, true),
        ] {
            let node_name = format!(
                "{}#{}_{}_{}-{}",
                "import/exmaralda/test_doc", tpe, spk, tlis[start], tlis[end]
            );
            let start_time = times[start];
            let end_time = times[end];
            u.add_event(UpdateEvent::AddNode {
                node_name: node_name.to_string(),
                node_type: "node".to_string(),
            })?;
            u.add_event(UpdateEvent::AddNodeLabel {
                node_name: node_name.to_string(),
                anno_ns: ANNIS_NS.to_string(),
                anno_name: "time".to_string(),
                anno_value: format!("{}-{}", start_time, end_time),
            })?;
            u.add_event(UpdateEvent::AddNodeLabel {
                node_name: node_name.to_string(),
                anno_ns: ANNIS_NS.to_string(),
                anno_name: "layer".to_string(),
                anno_value: spk.to_string(),
            })?;
            if tpe == "t" {
                u.add_event(UpdateEvent::AddNodeLabel {
                    node_name: node_name.to_string(),
                    anno_ns: ANNIS_NS.to_string(),
                    anno_name: "tok".to_string(),
                    anno_value: value.to_string(),
                })?;
                u.add_event(UpdateEvent::AddEdge {
                    source_node: node_name.to_string(),
                    target_node: "import/exmaralda/test_doc".to_string(),
                    layer: ANNIS_NS.to_string(),
                    component_type: AnnotationComponentType::PartOf.to_string(),
                    component_name: "".to_string(),
                })?;
                if let Some(other_name) = prev {
                    u.add_event(UpdateEvent::AddEdge {
                        source_node: other_name,
                        target_node: node_name.to_string(),
                        layer: ANNIS_NS.to_string(),
                        component_type: AnnotationComponentType::Ordering.to_string(),
                        component_name: spk.to_string(),
                    })?;
                }
                prev = if reset_after {
                    None
                } else {
                    Some(node_name.to_string())
                }
            }
            u.add_event(UpdateEvent::AddNodeLabel {
                node_name: node_name.to_string(),
                anno_ns: spk.to_string(),
                anno_name: name.to_string(),
                anno_value: value.to_string(),
            })?;
            for i in start..end {
                u.add_event(UpdateEvent::AddEdge {
                    source_node: node_name.to_string(),
                    target_node: format!("import/exmaralda/test_doc#{}", tlis[i]),
                    layer: ANNIS_NS.to_string(),
                    component_type: AnnotationComponentType::Coverage.to_string(),
                    component_name: "".to_string(),
                })?;
            }
        }
        // add unlinked corpus nodes
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/lex".to_string(),
            node_type: "corpus".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/lex/new_york".to_string(),
            node_type: "corpus".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/lex/i".to_string(),
            node_type: "corpus".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/lex".to_string(),
            target_node: "import".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::PartOf.to_string(),
            component_name: "".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/lex/new_york".to_string(),
            target_node: "import/lex".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::PartOf.to_string(),
            component_name: "".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/lex/i".to_string(),
            target_node: "import/lex".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::PartOf.to_string(),
            component_name: "".to_string(),
        })?;
        // add unlinked data nodes
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/lex/new_york#root".to_string(),
            node_type: "node".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNodeLabel {
            node_name: "import/lex/new_york#root".to_string(),
            anno_ns: "".to_string(),
            anno_name: "morph".to_string(),
            anno_value: "New York".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/lex/new_york#root".to_string(),
            target_node: "import/lex/new_york".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::PartOf.to_string(),
            component_name: "".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/lex/new_york#m1".to_string(),
            node_type: "node".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNodeLabel {
            node_name: "import/lex/new_york#m1".to_string(),
            anno_ns: "".to_string(),
            anno_name: "morph".to_string(),
            anno_value: "New".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/lex/new_york#m2".to_string(),
            node_type: "node".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNodeLabel {
            node_name: "import/lex/new_york#m2".to_string(),
            anno_ns: "".to_string(),
            anno_name: "morph".to_string(),
            anno_value: "York".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/lex/new_york#root".to_string(),
            target_node: "import/lex/new_york#m1".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::Dominance.to_string(),
            component_name: "".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/lex/new_york#root".to_string(),
            target_node: "import/lex/new_york#m2".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::Dominance.to_string(),
            component_name: "".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNode {
            node_name: "import/lex/i#root".to_string(),
            node_type: "node".to_string(),
        })?;
        u.add_event(UpdateEvent::AddNodeLabel {
            node_name: "import/lex/i#root".to_string(),
            anno_ns: "".to_string(),
            anno_name: "morph".to_string(),
            anno_value: "I".to_string(),
        })?;
        u.add_event(UpdateEvent::AddEdge {
            source_node: "import/lex/i#root".to_string(),
            target_node: "import/lex/i".to_string(),
            layer: ANNIS_NS.to_string(),
            component_type: AnnotationComponentType::PartOf.to_string(),
            component_name: "".to_string(),
        })?;
        graph.apply_update(&mut u, |_| {})?;
        Ok(graph)
    }
}