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
use crate::NTriplesParser;
impl_triple_source!(NTriplesParser);
#[cfg(test)]
mod test {
use super::*;
use rio_api::model::{Literal, NamedNode};
use sophia_api::graph::Graph;
use sophia_api::ns::rdf;
use sophia_api::term::matcher::ANY;
use sophia_api::term::test::TestTerm;
use sophia_api::triple::stream::TripleSource;
#[test]
fn test_simple_nt_string() -> Result<(), Box<dyn std::error::Error>> {
let ntriples = r#"
<http://localhost/ex#me> <http://example.org/ns/knows> _:b1.
_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns/Person>.
_:b1 <http://example.org/ns/name> "Alice".
"#;
let p = NTriplesParser::new(ntriples.as_ref());
let g: Vec<[TestTerm<String>; 3]> = p.collect_triples()?;
assert_eq!(g.len(), 3);
assert!(g
.triples_matching(
&NamedNode {
iri: "http://localhost/ex#me"
},
&NamedNode {
iri: "http://example.org/ns/knows"
},
&ANY,
)
.next()
.is_some());
assert!(g
.triples_matching(
&ANY,
&rdf::type_,
&NamedNode {
iri: "http://example.org/ns/Person"
},
)
.next()
.is_some());
assert!(g
.triples_matching(
&ANY,
&NamedNode {
iri: "http://example.org/ns/name"
},
&Literal::Simple { value: "Alice" },
)
.next()
.is_some());
Ok(())
}
}