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
#[cfg(test)]
mod tests {
use terraphim_middleware::thesaurus::{Logseq, ThesaurusBuilder};
use terraphim_middleware::Result;
use terraphim_types::NormalizedTermValue;
#[tokio::test]
/// Test creating a thesaurus from a Logseq haystack (Markdown files)
/// Uses `fixtures/logseq` as the haystack
async fn test_logseq_thesaurus() -> Result<()> {
let logseq = Logseq::default();
let thesaurus = logseq
.build("some_role".to_string(), "fixtures/logseq")
.await?;
let json = serde_json::to_string_pretty(&thesaurus)?;
println!("{}", json);
println!(
"Value {:?}",
thesaurus
.get(&NormalizedTermValue::new("example bar".to_string()))
.unwrap()
.value
);
println!(
"Key {:?}",
thesaurus
.get(&NormalizedTermValue::new("example bar".to_string()))
.unwrap()
.id
);
// Make sure `json` has the following structure:
// {
// "example": {
// "id": "...",
// "nterm": "example bar"
// },
// "ai": {
// "id": "...",
// "nterm": "artificial intelligence"
// }
// }
println!("{:#?}", thesaurus);
assert_eq!(thesaurus.len(), 7);
// Verify "example bar" maps to "example" concept (id may vary based on processing order)
let example_bar_term = thesaurus
.get(&NormalizedTermValue::new("example bar".to_string()))
.unwrap();
assert_eq!(
example_bar_term.value,
NormalizedTermValue::new("example".to_string())
);
assert_eq!(
thesaurus
.get(&NormalizedTermValue::new("example bar".to_string()))
.unwrap()
.value,
NormalizedTermValue::new("example".to_string())
);
assert_eq!(
thesaurus
.get(&NormalizedTermValue::new("example".to_string()))
.unwrap()
.value,
NormalizedTermValue::new("example".to_string())
);
assert_eq!(
thesaurus
.get(&NormalizedTermValue::new("ai".to_string()))
.unwrap()
.value,
NormalizedTermValue::new("ai".to_string())
);
Ok(())
}
}