ebi 0.3.14

A stochastic process mining utility and library
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
use ebi_objects::anyhow::{Ok, Result};
use clap::Command;
use ebi_objects::EbiObjectType;
use inflector::Inflector;
use layout::{
    core::{base::Orientation, color::Color, geometry::Point, style::StyleAttr},
    std_shapes::{
        render::get_shape_size,
        shapes::{Arrow, Element, ShapeKind},
    },
    topo::layout::VisualGraph,
};
use std::{
    collections::{BTreeSet, HashMap},
    io::Write,
};
use strum::IntoEnumIterator;
use crate::{ebi_commands::ebi_command_itself::EBI_ITSELF, ebi_framework::{ebi_command::{EBI_COMMANDS, EbiCommand, get_applicable_commands}, ebi_file_handler::{EBI_FILE_HANDLERS, get_file_handlers}, ebi_importer_parameters, ebi_input::{self, EbiInputType}, ebi_output::{EbiExporter, EbiOutput, EbiOutputType}, ebi_trait::EbiTrait}, prom::java_object_handler::{JavaObjectHandlerQueryExport, JavaObjectHandlerQueryImport}, python::python::{PYTHON_PACKAGE, pm4py_function_name}, text::{Joiner, LatexEscaper, Rank}};

pub fn manual() -> Result<EbiOutput> {
    let mut f = vec![];

    //version
    writeln!(f, "\\def\\version{{{}}}", env!("CARGO_PKG_VERSION"))?;

    //statistics
    writeln!(f, "\\def\\numberofcommands{{{}}}", EBI_COMMANDS.get_command_paths().len())?;
    writeln!(f, "\\def\\numberoftraits{{{}}}", EbiTrait::iter().len())?;
    writeln!(f, "\\def\\numberoffilehandlers{{{}}}", EBI_FILE_HANDLERS.len())?;

    // //command list
    // writeln!(f, "\\def\\ebicommandlist{{\\begin{{itemize}}")?;
    // for path in EBI_COMMANDS.get_command_paths() {
    //     writeln!(f, "\\item\\texttt{{{}}} or \\texttt{{{}}} (\\cref{{command:{}}})", EbiCommand::path_to_string(&path), EbiCommand::path_to_short_string(&path), EbiCommand::path_to_string(&path))?;
    // }
    // writeln!(f, "\\end{{itemize}}}}")?;

    write_commands(&mut f)?;

    //file handlers
    writeln!(f, "\\long\\def\\ebifilehandlers{{")?;
    let file_handlers: BTreeSet::<_> = EBI_FILE_HANDLERS.iter().collect();
    for file_handler in file_handlers.iter() {
        writeln!(f, "\\clearpage")?;
        writeln!(f, "\\section{{{} (.{})}}", file_handler.name.to_sentence_case(), file_handler.file_extension)?;
        writeln!(f, "\\label{{filehandler:{}}}", file_handler.name)?;
        writeln!(f, "Import as objects: {}.", or_none(&file_handler.object_importers.iter().map(|importer| importer.to_string()).collect::<Vec<_>>().join(", ")))?;
        writeln!(f, "\\\\Fallible import as objects: {}.", or_none(&file_handler.object_importers_fallible.iter().map(|importer| importer.to_string()).collect::<Vec<_>>().join(", ")))?;
        writeln!(f, "\\\\Import as traits: {}.", or_none(&file_handler.trait_importers.iter().map(|importer| importer.to_string()).collect::<Vec<_>>().join(", ")))?;
        writeln!(f, "\\subsection*{{Input to commands}} {}", or_none(&file_handler.get_applicable_commands().iter().map(
            |path| format!("\\null\\qquad\\hyperref[command:{}]{{\\texttt{{{}}}}} (\\cref{{command:{}}})", EbiCommand::path_to_string(path), EbiCommand::path_to_string(path), EbiCommand::path_to_string(path)))
            .collect::<Vec<_>>().join("\\\\")))?;
        
        writeln!(f, "\\subsection*{{Output of commands}} {}", or_none(&file_handler.get_producing_commands().iter().map(
            |path| format!("\\null\\qquad\\hyperref[command:{}]{{\\texttt{{{}}}}} (\\cref{{command:{}}})", EbiCommand::path_to_string(path), EbiCommand::path_to_string(path), EbiCommand::path_to_string(path)))
            .collect::<Vec<_>>().join("\\\\")))?;

        writeln!(f, "\\subsection*{{Java \\& Python}}")?;
        {
            let mut to_java = false;
            let mut from_java = false;
            for java in file_handler.java_object_handlers {
                if java.translator_ebi_to_java.is_some() {
                    to_java = true;
                }
                if java.translator_java_to_ebi.is_some() {
                    from_java = true;
                }
            }
            if to_java && from_java {
                writeln!(f, "{} {} can be imported and exported between Ebi, and ProM and Java.", file_handler.article.to_string().to_sentence_case(), file_handler)?;
            } else if to_java {
                writeln!(f, "{} {} can be exported from Ebi to ProM and Java.", file_handler.article.to_string().to_sentence_case(), file_handler)?;
            } else if from_java {
                writeln!(f, "{} {} can be imported from ProM and Java to Ebi.", file_handler.article.to_string().to_sentence_case(), file_handler)?;
            } else {
                writeln!(f, "{} {} can be neither imported nor exported between Ebi, and ProM and Java.", file_handler.article.to_string().to_sentence_case(), file_handler)?;
            }
        }

        writeln!(f, "\\subsection*{{File format specification}}{}", file_handler.format_specification)?;
    }
    writeln!(f, "}}")?;

    //file handlers list
    let file_handlers: BTreeSet::<_> = EBI_FILE_HANDLERS.iter().collect();
    writeln!(f, "\\def\\ebifilehandlerlist{{\\begin{{itemize}}")?;
    for file_handler in file_handlers {
        writeln!(f, "\\item {} (.{}) (\\cref{{filehandler:{}}})", file_handler.name, file_handler.file_extension, file_handler.name)?;
    }
    writeln!(f, "\\end{{itemize}}}}")?;

    //trait list
    writeln!(f, "\\long\\def\\ebitraitlist{{")?;
    for etrait in EbiTrait::iter() {
        writeln!(f, "\\subsection{{{}}}", etrait.to_string().to_sentence_case())?;
        writeln!(f, "\\label{{trait:{}}}", etrait.to_string())?;
        writeln!(f, "{}", etrait.get_explanation())?;

        writeln!(f, "\\\\File types that can be imported as {} {}: {}.", 
            etrait.get_article(), 
            etrait, 
            or_none(
                    &etrait.get_file_handlers().iter().map(|file_handler| 
                        format!("\\\\\\null\\qquad\\hyperref[filehandler:{}]{{{}}} (.{} -- \\cref{{filehandler:{}}})", file_handler.name, file_handler.name, file_handler.file_extension, file_handler.name)
                    ).collect::<Vec<_>>().join(", "))
            )?;

        writeln!(f, "\\\\Commands that accept {} {} as input: {}", etrait.get_article(), etrait, or_none(&etrait.get_applicable_commands().iter().map(
            |path| format!("\\\\\\null\\qquad\\hyperref[command:{}]{{\\texttt{{{}}}}} (\\cref{{command:{}}})", EbiCommand::path_to_string(path), EbiCommand::path_to_string(path), EbiCommand::path_to_string(path)))
            .collect::<Vec<_>>().join("")))?;
    }
    writeln!(f, "}}")?;

    //object type list
    writeln!(f, "\\def\\ebiobjecttypelist{{\\begin{{itemize}}")?;
    for object_type in EbiObjectType::iter() {
        writeln!(f, "\\item {}", object_type)?;
    }
    writeln!(f, "\\end{{itemize}}}}")?;

    //prom commands
    writeln!(f, "\\def\\promcommands{{{}}}", 
        EBI_COMMANDS.get_command_paths().iter().filter_map(
            |path| 
            {
                if path.last().unwrap().is_in_java() {
                    Some(format!("\\\\\\null\\qquad\\hyperref[command:{}]{{\\texttt{{{}}}}} (\\cref{{command:{}}})", EbiCommand::path_to_string(path), EbiCommand::path_to_string(path), EbiCommand::path_to_string(path)))
                } else {
                    None
                }
            }).collect::<Vec<_>>().join("")
        )?;

    //prom input list
    writeln!(f, "\\def\\ebiprominput{{\\begin{{itemize}}")?;
    for r#trait in EbiTrait::iter() {
        let java_object_handlers = r#trait.get_java_object_handlers_that_can_import();
        if !java_object_handlers.is_empty() {
            writeln!(f, "\\item {} (trait).\\\\Java class: {}.", 
                r#trait.to_string().to_sentence_case(), 
                java_object_handlers.into_iter().map(|java_object_handler| java_object_handler.java_class).collect::<Vec<_>>().join(", ")
            )?;
        }
    }
    for object_type in EbiObjectType::iter() {
        let java_object_handlers = object_type.get_java_object_handlers_that_can_import();
        if !java_object_handlers.is_empty() {
            writeln!(f, "\\item {}.\\\\Java class: {}.", 
                object_type.to_string().to_sentence_case(), 
                java_object_handlers.into_iter().map(|java_object_handler| java_object_handler.java_class).collect::<Vec<_>>().join(", ")
            )?;
        }
    }
    for output_type in EbiInputType::iter() {
        let java_object_handlers = output_type.get_java_object_handlers_that_can_import();
        if !java_object_handlers.is_empty() {
            writeln!(f, "\\item {}.\\\\Java class: {}.", 
                output_type.to_string().to_sentence_case(), 
                java_object_handlers.into_iter().map(|java_object_handler| java_object_handler.java_class).collect::<Vec<_>>().join(", ")
            )?;
        }
    }
    writeln!(f, "\\end{{itemize}}}}")?;

    //prom output list
    writeln!(f, "\\def\\ebipromoutput{{\\begin{{itemize}}")?;
    for object_type in EbiObjectType::iter() {
        let java_object_handlers = object_type.get_java_object_handlers_that_can_export();
        if !java_object_handlers.is_empty() {
            writeln!(f, "\\item {}.\\\\Java class: {}.", 
                object_type.to_string().to_sentence_case(), 
                java_object_handlers.into_iter().map(|java_object_handler| java_object_handler.java_class).collect::<Vec<_>>().join(", ")
            )?;
        }
    }
    for output_type in EbiOutputType::iter() {
        let java_object_handlers = output_type.get_java_object_handlers_that_can_export();
        if !java_object_handlers.is_empty() {
            writeln!(f, "\\item {}.\\\\Java class: {}.", 
                output_type.to_string().to_sentence_case(), 
                java_object_handlers.into_iter().map(|java_object_handler| java_object_handler.java_class).collect::<Vec<_>>().join(", ")
            )?;
        }
    }
    writeln!(f, "\\end{{itemize}}}}")?;

    //table file handlers -> object types
    writeln!(f, "\\def\\filehandlersobjecttypes{{{}}}", object_importers_table()?)?;

    //table file handlers -> traits
    writeln!(f, "\\def\\filehandlerstraits{{{}}}", trait_importers_table()?)?;

    //table object types -> file handlers
    writeln!(f, "\\def\\objecttypesfilehandlers{{{}}}", object_exporters_table()?)?;
    

    Ok(EbiOutput::String(String::from_utf8(f).unwrap()))
}

fn write_commands(f: &mut Vec<u8>) -> Result<()> {
    writeln!(f, "\\def\\ebicommands{{")?;
    for path in EBI_COMMANDS.get_command_paths() {
        write_command(f, path)?;
    }
    writeln!(f, "}}")?;
    Ok(())
}

fn write_command(f: &mut Vec<u8>, path: Vec<&EbiCommand>) -> Result<()> {
    writeln!(f, "\\clearpage\\section{{\\texttt{{{}}}}}", EbiCommand::path_to_string(&path))?;
    writeln!(f, "\\label{{command:{}}}", EbiCommand::path_to_string(&path))?;

    if let EbiCommand::Command { name_long, explanation_short, explanation_long, latex_link, cli_command, exact_arithmetic, input_types: input_typess, input_names, input_helps, output_type, .. } = path[path.len()-1] {

        //alias
        if let Some(_) = name_long {
            writeln!(f, "Alias: \\texttt{{{}}}.\\\\", EbiCommand::path_to_short_string(&path))?;
        }

        //explanation
        if let Some(l) = explanation_long {
            writeln!(f, "{}\\\\", l)?;
        } else {
            writeln!(f, "{}\\\\", explanation_short)?;
        }

        //latex link
        if let Some(link) = latex_link {
            writeln!(f, "More information: {}~\\\\", link)?;
        }
        
        //output
        writeln!(f, "\\noindent Output: {}, which can be written as {}.\\\\", output_type, output_types(output_type))?;

        //ProM
        if path.last().unwrap().is_in_java() {
            writeln!(f, "\\\\This command is available in Java and ProM.")?;
        } else {
            writeln!(f, "\\\\This command is not available in Java and ProM.")?;
        }

        //pm4py
        if path.last().unwrap().is_in_python() {
            writeln!(f, "\\\\This command is available in the {} Python package using the function {}.", PYTHON_PACKAGE, pm4py_function_name(&path).escape_latex())?;
        } else {
            writeln!(f, "\\\\This command is not available in the {} Python package.", PYTHON_PACKAGE)?;
        }

        //parameters table
        writeln!(f, "\\begin{{tabularx}}{{\\linewidth}}{{lX}}")?;
        writeln!(f, "\\toprule")?;
        writeln!(f, "Parameter \\\\\\midrule")?;

        //standard parameters
        for (input_name, (input_types, input_help)) in input_names.iter().zip(input_typess.iter().zip(input_helps.iter())) {
            write!(f, "<\\texttt{{{}}}>", input_name.escape_latex())?;    
            writeln!(f, "&{}\\\\", input_help)?;

            //mandatoryness
            if let Some(default) = ebi_input::default(input_types) {
                writeln!(f, "&\\textit{{Mandatory:}} \\quad no: if no value is provided, a default of {} will be used. It can also be provided on STDIN by giving a `-' on the command line.\\\\", default)?;
            } else {
                writeln!(f, "&\\textit{{Mandatory:}} \\quad yes, though it can be given on STDIN by giving a `-' on the command line.\\\\")?;
            }

            //accepted values
            writeln!(f, "&\\textit{{Accepted values:}}\\quad {}.\\\\", EbiInputType::get_possible_inputs_with_latex(input_types).join_with(", ", " and "))?;
        }

        //custom parameters
        if let Some(fu) = cli_command {
            for arg in (fu)(Command::new("")).get_arguments() {
                if let Some(short) = arg.get_short() {
                    if let Some(long) = arg.get_long() {
                        writeln!(f, "-\\texttt{{{}}} or --\\texttt{{{}}}", short, long)?;
                    } else {
                        writeln!(f, "-\\texttt{{{}}}", short)?;
                    }
                } else {
                    if let Some(long) = arg.get_long() {
                        writeln!(f, "--\\texttt{{{}}}", long)?;
                    } else {
                        writeln!(f, "<\\texttt{{{}}}>", arg.get_value_names().unwrap()[0])?;
                    }
                }
                writeln!(f, "&{}\\\\", if let Some(h) = arg.get_long_help() {h.to_string()} else {arg.get_help().unwrap().to_string()})?;

                if arg.get_short().is_none() && arg.get_long().is_none() {
                    //custom argument
                    if let Some(default) = arg.get_default_values().iter().next() {
                        writeln!(f, "&\\textit{{Mandatory:}}\\quad {}\\\\", if arg.is_required_set() {"yes".to_owned()} else {format!("no; if not provided, a default value of {} will be used", default.to_string_lossy())} )?;
                    } else {
                        writeln!(f, "&\\textit{{Mandatory:}}\\quad {}\\\\", if arg.is_required_set() {"yes"} else {"no"} )?;
                    }
                } else {
                    writeln!(f, "&\\textit{{Mandatory:}}\\quad no\\\\")?;
                }
            }
        }

        //output-type
        if output_type.get_exporters().len() > 1 {
            let output_extensions = output_type
                    .get_exporters()
                    .iter()
                    .map(|exporter| exporter.get_extension())
                    .collect::<Vec<_>>()
                    .join_with(", ", " and ");
            writeln!(f, "\\texttt{{-t}} or \\texttt{{--output\\_type}} <\\texttt{{OUTPUT\\_TYPE}}> &")?;
            writeln!(f, "The output file extension (without period). The default is {}. Possible values are {}.\\\\", output_type.get_default_exporter().get_extension(), output_extensions)?;
            writeln!(f, "&\\textit{{Mandatory:}} \\quad no\\\\")?;
        }

        //output
        writeln!(f, "\\texttt{{-o}} or \\texttt{{--output}} <\\texttt{{FILE}}> &")?;
        if output_type.get_exporters().len() == 1 {
            let exporter = output_type.get_exporters().remove(0);
            writeln!(f, "The {} file to which the result must be written. If the parameter is not given, the results will be written to STDOUT.\\\\", exporter)?;
        } else {
            writeln!(f, "The file to which the results must be written. Based on the file extension, Ebi will output either {}.", output_types(output_type))?;
            writeln!(f, "If the parameter is not given, the results will be written to STDOUT as {} {}.\\\\", output_type.get_default_exporter().get_article(), output_type.get_default_exporter())?;
        }
        writeln!(f, "&\\textit{{Mandatory:}} \\quad no\\\\")?;
        
        //exact arithmetic flag
        if *exact_arithmetic {
            writeln!(f, "\\texttt{{-a}} or \\texttt{{--approximate}} & Use approximate arithmetic instead of exact arithmetic.\\\\")?;
            writeln!(f, "&\\textit{{Mandatory:}}\\quad no\\\\")?;
        }

        //importer parameters
        for (input_index, (input_types, input_name)) in input_typess.iter().zip(input_names.iter()).enumerate() {
            for parameter in ebi_importer_parameters::merge_importer_parameters(input_types) { 
                writeln!(f, "\\texttt{{--{}}} & {}. This parameter applies to some of the importers of the {} input {}. {}\\\\", ebi_importer_parameters::name_to_id(parameter.name(), input_index).escape_latex(), parameter.explanation().escape_latex(), input_index.rank(), input_name.escape_latex(), ebi_importer_parameters::explanation_with_values(parameter).escape_latex())?;
                writeln!(f, "&\\textit{{Mandatory:}}\\quad no\\\\")?;
                if ebi_importer_parameters::has_accepted_values(parameter) {
                    writeln!(f, "&\\textit{{Accepted values:}}\\quad {}.\\\\", ebi_importer_parameters::explanation_with_values(parameter).escape_latex())?;
                }
            }
        }

        writeln!(f, "\\bottomrule")?;
        writeln!(f, "\\end{{tabularx}}")?;
        writeln!(f, "A \\textdagger{{}} indicates that the file type is converted on import, but that this conversion may fail.")?;
    }
    Ok(())
}

pub fn or_none(string: &str) -> &str {
    if string.is_empty() {
        return "none";
    }
    string
}

pub fn output_types(output_type: &EbiOutputType) -> String {
    let mut list = output_type.get_exporters().into_iter().map(
        |exp| exp.get_article().to_string() 
        + " " 
        + match exp {
            EbiExporter::Object(_, file_handler) => format!("{} (.{} -- \\cref{{filehandler:{}}})", file_handler.name, file_handler.file_extension, file_handler.name),
            _ => exp.to_string()
        }.as_str()
    ).collect::<Vec<_>>();
    if list.len() == 1 {
        return list.remove(0)
    }
    let (last, list) = list.split_last().unwrap();
    format!("{} {} {}", list.join(", "), "or", last)
}

pub fn graph() -> Result<VisualGraph> {
    let mut graph = VisualGraph::new(Orientation::LeftToRight);

    //traits
    let mut traits = HashMap::new();
    for etrait in EbiTrait::iter() {
        let shape = ShapeKind::new_box(&("trait ".to_owned() + etrait.to_string().as_str()));
        let look = StyleAttr::simple();
        let orientation = Orientation::LeftToRight;
        let mut size = get_shape_size(orientation, &shape, look.font_size, false);
        scale(&mut size);
        let node = Element::create(shape, look, orientation, size);
        let nodeh = graph.add_node(node);

        traits.insert(etrait, nodeh);
    }

    //object types
    let mut object_types = HashMap::new();
    for object_type in EbiObjectType::iter() {
        let shape = ShapeKind::new_box(&("type ".to_owned() + object_type.to_string().as_str()));
        let mut look = StyleAttr::simple();
        look.fill_color = Color::from_name("lightgray");
        let orientation = Orientation::LeftToRight;
        let mut size = get_shape_size(orientation, &shape, look.font_size, false);
        scale(&mut size);
        let node = Element::create(shape, look, orientation, size);
        let nodeh = graph.add_node(node);

        object_types.insert(object_type, nodeh);
    }

    //file handlers
    let mut file_handlers = HashMap::new();
    for file_handler in EBI_FILE_HANDLERS {
        let shape = ShapeKind::new_circle(&(".".to_owned() + file_handler.file_extension.to_string().as_str()));
        let look = StyleAttr::simple();
        let orientation = Orientation::LeftToRight;
        let mut size = get_shape_size(orientation, &shape, look.font_size-5, false);
        scale(&mut size);
        let node = Element::create(shape, look, orientation, size);
        let nodeh = graph.add_node(node);

        file_handlers.insert(file_handler, nodeh);
    }

    //files to traits
    for etrait in EbiTrait::iter() {
        let to = traits.get(&etrait).unwrap();
        for file_handler in etrait.get_file_handlers() {
            let from = file_handlers.get(&file_handler).unwrap();
            let arrow = Arrow::simple("");
            graph.add_edge(arrow, *from, *to);
        }
    }

    //commands
    let mut commands = HashMap::new();
    for command in EBI_COMMANDS.get_command_paths() {
        let shape = ShapeKind::new_double_circle(&EbiCommand::path_to_short_string(&command));
        let look = StyleAttr::simple();
        let orientation = Orientation::LeftToRight;
        let size = get_shape_size(orientation, &shape, look.font_size, false);
        let node = Element::create(shape, look, orientation, size);
        let nodeh = graph.add_node(node);

        commands.insert(command, nodeh);
    }

    //command trait inputs
    for etrait in EbiTrait::iter() {
        let source = traits.get(&etrait).unwrap();
        for command in etrait.get_applicable_commands() {
            let target = commands.get(&command).unwrap();
            let arrow = Arrow::simple("");
            graph.add_edge(arrow, *source, *target);
        }
    }

    //object types to commands
    for object_type in EbiObjectType::iter() {
        let source = object_types.get(&object_type).unwrap();
        for command in get_applicable_commands(&object_type) {
            let target = commands.get(&command).unwrap();
            let arrow = Arrow::simple("");
            graph.add_edge(arrow, *source, *target);
        }
    }

    //files to object types
    for object_type in EbiObjectType::iter() {
        let to = object_types.get(&object_type).unwrap();
        for file_handler in get_file_handlers(&object_type) {
            let from = file_handlers.get(&file_handler).unwrap();
            let arrow = Arrow::simple("");
            graph.add_edge(arrow, *from, *to);
        }
    }

    return Ok(graph)
}

pub fn scale(point: &mut Point) {
    point.x *= 0.5;
}

pub fn html() -> String {
    let commands_html = EBI_COMMANDS
        .get_command_paths()
        .iter()
        .filter_map(|path| {
            if path[1].long_name() != EBI_ITSELF.long_name() {
                Some(format!(
                    "<i>{}</i>. {}",
                    EbiCommand::path_to_string(&path[1..]).to_sentence_case(),
                    path.last().unwrap().explanation_short()
                ))
            } else {
                None
            }
        })
        .collect::<Vec<_>>()
        .join("</li><li>");

    let file_formats_html = EBI_FILE_HANDLERS
        .iter()
        .map(|file_handler| {
            format!(
                "{} (.{})",
                file_handler.name.to_sentence_case(),
                file_handler.file_extension
            )
        })
        .collect::<Vec<_>>()
        .join("</li><li>");

    format!(
        "<h2>Commands</h2>\
        Ebi offers the following comands and techniques. \
        Please refer to the <a href=\"https://git.rwth-aachen.de/rwth-bpm/rustlibrary/-/raw/main/build/nightly/manual.pdf?ref_type=heads&inline=true\">manual</a> for more information. \
        <ul><li>{}</li></ul>\
        <h2>Supported file formats</h2>\
        <ul><li>{}</li></ul>",
        commands_html, file_formats_html
    )
}

pub fn object_importers_table() -> Result<String> {
    let mut f = vec![];

    let types = EbiObjectType::iter().collect::<BTreeSet<_>>();
    let handlers = EBI_FILE_HANDLERS.iter().collect::<BTreeSet<_>>();

    //header
    writeln!(f, "\\begin{{tabular}}{{l")?;
    for _ in EbiObjectType::iter() {
        writeln!(f, "@{{~}}c")?;
    }
    writeln!(f, "}}")?;
    writeln!(f, "\\toprule")?;
    writeln!(f, "File handler")?;
    for object_type in &types {
        writeln!(f, "&\\rotatebox{{90}}{{{}}}", object_type)?;
    }
    writeln!(f, "\\\\\\midrule")?;

    //body
    for file_handler in handlers {
        writeln!(f, "{}\\hfill .{}", file_handler.name, file_handler.file_extension)?;
        for object_type in &types {
            write!(f, "&{}", file_handler.can_import_as_object(&object_type).to_latex_circle())?;
        }
        writeln!(f, "\\\\")?;
    }

    //footer
    writeln!(f, "\\bottomrule")?;
    writeln!(f, "\\end{{tabular}}")?;
    

    Ok(String::from_utf8(f)?)
}

pub fn trait_importers_table() -> Result<String> {
    let mut f = vec![];

    let types = EbiTrait::iter().collect::<BTreeSet<_>>();
    let handlers = EBI_FILE_HANDLERS.iter().collect::<BTreeSet<_>>();

    //header
    writeln!(f, "\\begin{{tabular}}{{l")?;
    for _ in EbiObjectType::iter() {
        writeln!(f, "@{{~}}c")?;
    }
    writeln!(f, "}}")?;
    writeln!(f, "\\toprule")?;
    writeln!(f, "File handler")?;
    for object_type in &types {
        writeln!(f, "&\\rotatebox{{90}}{{{}}}", object_type)?;
    }
    writeln!(f, "\\\\\\midrule")?;

    //body
    for file_handler in handlers {
        writeln!(f, "{}\\hfill .{}", file_handler.name, file_handler.file_extension)?;

        for object_type in &types {
            if file_handler.can_import_as_trait(&object_type) {
                write!(f, "&\\CIRCLE")?;
            } else {
                write!(f, "&\\Circle")?;
            }
        }
        writeln!(f, "\\\\")?;
    }

    //footer
    writeln!(f, "\\bottomrule")?;
    writeln!(f, "\\end{{tabular}}")?;

    Ok(String::from_utf8(f)?)
}

pub fn object_exporters_table() -> Result<String> {
    let mut f = vec![];

    let types = EbiObjectType::iter().collect::<BTreeSet<_>>();
    let handlers = EBI_FILE_HANDLERS.iter().collect::<BTreeSet<_>>();

    //header
    writeln!(f, "\\begin{{tabular}}{{l")?;
    for _ in &handlers {
        writeln!(f, "@{{~}}c")?;
    }
    writeln!(f, "}}")?;
    writeln!(f, "\\toprule")?;
    writeln!(f, "Object")?;
    for file_handler in &handlers {
        writeln!(f, "&\\rotatebox{{90}}{{{} (.{})}}", file_handler.name, file_handler.file_extension)?;
    }
    writeln!(f, "\\\\\\midrule")?;

    //body
    for object_type in types {
        writeln!(f, "{}", object_type)?;

        for file_handler in &handlers {
            write!(f, "&{}", file_handler.can_export_as_object(&object_type).to_latex_circle())?;
        }
        writeln!(f, "\\\\")?;
    }

    //footer
    writeln!(f, "\\bottomrule")?;
    writeln!(f, "\\end{{tabular}}")?;

    Ok(String::from_utf8(f)?)
}