oxirs-star 0.2.4

RDF-star and SPARQL-star grammar support for quoted triples
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
//! Compressed dictionary for RDF-star terms, including quoted triples.
//!
//! The `StarDictionary` compresses the string space of RDF-star data by
//! assigning monotonically increasing integer IDs to each distinct term string.
//! Quoted triples receive their own ID namespace and are stored by their
//! component IDs, avoiding redundant string storage.
//!
//! # Memory layout
//!
//! | Component | Storage |
//! |-----------|---------|
//! | Simple terms (IRI, literal, blank node) | `str_to_id` + `id_to_str` |
//! | Quoted triples | `quoted_to_id` + `id_to_quoted` |
//!
//! The `EncodedTerm` enum tags each ID with its kind so that decoding is
//! unambiguous.
//!
//! # Example
//!
//! ```rust,ignore
//! use oxirs_star::storage::star_dict::{StarDictionary, EncodedTerm};
//! use oxirs_star::{StarTerm, StarTriple};
//!
//! let mut dict = StarDictionary::new();
//!
//! let alice = StarTerm::iri("http://ex.org/alice").unwrap();
//! let encoded = dict.encode_term(&alice).unwrap();
//!
//! if let EncodedTerm::Iri(id) = encoded {
//!     println!("Alice IRI has ID: {}", id);
//! }
//!
//! let decoded = dict.decode_term(&encoded).unwrap();
//! assert_eq!(decoded, alice);
//! ```

use std::collections::HashMap;

use crate::{StarError, StarResult, StarTerm, StarTriple};

// ---- Type aliases ----------------------------------------------------------

/// Opaque identifier for a simple term (IRI, blank node, or literal).
pub type TermId = u64;

/// Opaque identifier for a quoted triple.
pub type QuotedId = u64;

// ---- EncodedTerm -----------------------------------------------------------

/// A compressed representation of an RDF-star term.
///
/// Each variant carries the appropriate numeric ID rather than the raw string,
/// reducing memory usage for datasets with repeated terms.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EncodedTerm {
    /// Compressed IRI: the ID maps to the IRI string in the dictionary.
    Iri(TermId),
    /// Compressed blank node: the ID maps to the blank-node label.
    BlankNode(TermId),
    /// Compressed literal: the ID maps to the full literal representation.
    Literal(TermId),
    /// Compressed quoted triple: the ID maps to a `(s, p, o)` triple of
    /// `EncodedTerm`s in the quoted-triple table.
    QuotedTriple(QuotedId),
}

impl EncodedTerm {
    /// Return `true` if this is a quoted triple.
    pub fn is_quoted(&self) -> bool {
        matches!(self, Self::QuotedTriple(_))
    }

    /// Return the numeric ID regardless of kind.
    pub fn raw_id(&self) -> u64 {
        match self {
            Self::Iri(id) | Self::BlankNode(id) | Self::Literal(id) => *id,
            Self::QuotedTriple(id) => *id,
        }
    }
}

// ---- TermKey ----------------------------------------------------------------

/// Internal string key used for term deduplication.
///
/// Includes a kind discriminant so that an IRI `"foo"` and a literal `"foo"`
/// receive different IDs.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum TermKey {
    Iri(String),
    BlankNode(String),
    /// Stores the canonical form: `"lexical"^^<datatype>@lang`.
    Literal(String),
}

impl TermKey {
    fn from_term(term: &StarTerm) -> Option<Self> {
        match term {
            StarTerm::NamedNode(n) => Some(Self::Iri(n.iri.clone())),
            StarTerm::BlankNode(b) => Some(Self::BlankNode(b.id.clone())),
            StarTerm::Literal(l) => {
                // Canonical form includes datatype and language tag.
                let mut repr = l.value.clone();
                if let Some(ref dt) = l.datatype {
                    repr.push_str("^^");
                    repr.push_str(&dt.iri);
                }
                if let Some(ref lang) = l.language {
                    repr.push('@');
                    repr.push_str(lang);
                }
                Some(Self::Literal(repr))
            }
            StarTerm::Variable(_) | StarTerm::QuotedTriple(_) => None,
        }
    }
}

// ---- StarDictionary --------------------------------------------------------

/// Bidirectional dictionary for RDF-star terms.
///
/// Provides O(1) amortised encoding and O(1) decoding.  The dictionary grows
/// monotonically; there is no removal operation, matching typical triple-store
/// bulk-load usage patterns.
pub struct StarDictionary {
    /// String-key → ID for simple terms.
    str_to_id: HashMap<TermKey, TermId>,
    /// ID → canonical string for simple terms.  Index 0 is unused (IDs start
    /// at 1) so that 0 can act as a sentinel.
    id_to_str: Vec<(TermKey, String)>,
    next_term_id: TermId,

    /// (s_encoded, p_encoded, o_encoded) → quoted ID.
    quoted_to_id: HashMap<(EncodedTerm, EncodedTerm, EncodedTerm), QuotedId>,
    /// ID → component triple of `EncodedTerm`s.  Index 0 is unused.
    id_to_quoted: Vec<(EncodedTerm, EncodedTerm, EncodedTerm)>,
    next_quoted_id: QuotedId,
}

impl StarDictionary {
    /// Create an empty dictionary.  IDs for both namespaces start at 1.
    pub fn new() -> Self {
        // Pre-allocate slot 0 as a dummy so IDs start at 1.
        Self {
            str_to_id: HashMap::new(),
            id_to_str: vec![(TermKey::Iri(String::new()), String::new())],
            next_term_id: 1,

            quoted_to_id: HashMap::new(),
            id_to_quoted: vec![(
                EncodedTerm::Iri(0),
                EncodedTerm::Iri(0),
                EncodedTerm::Iri(0),
            )],
            next_quoted_id: 1,
        }
    }

    // ---- Encoding -----------------------------------------------------------

    /// Encode an RDF-star term, assigning a new ID if this term has not been
    /// seen before.
    ///
    /// Variables are not encodable and return an error.
    pub fn encode_term(&mut self, term: &StarTerm) -> StarResult<EncodedTerm> {
        match term {
            StarTerm::Variable(v) => Err(StarError::invalid_term_type(format!(
                "Variables cannot be encoded in the dictionary: ?{}",
                v.name
            ))),

            StarTerm::QuotedTriple(inner) => {
                // Recursively encode components, then intern the triple.
                let s = self.encode_term(&inner.subject)?;
                let p = self.encode_term(&inner.predicate)?;
                let o = self.encode_term(&inner.object)?;
                Ok(self.intern_quoted(s, p, o))
            }

            StarTerm::NamedNode(n) => {
                let key = TermKey::Iri(n.iri.clone());
                Ok(EncodedTerm::Iri(self.intern_str(key, &n.iri)))
            }
            StarTerm::BlankNode(b) => {
                let key = TermKey::BlankNode(b.id.clone());
                Ok(EncodedTerm::BlankNode(self.intern_str(key, &b.id)))
            }
            StarTerm::Literal(_l) => {
                let tk = TermKey::from_term(term).expect("literal always has a term key");
                let repr = match tk.clone() {
                    TermKey::Literal(s) => s,
                    _ => unreachable!(),
                };
                Ok(EncodedTerm::Literal(self.intern_str(tk, &repr)))
            }
        }
    }

    /// Encode all three terms of a triple.
    pub fn encode_triple(
        &mut self,
        triple: &StarTriple,
    ) -> StarResult<(EncodedTerm, EncodedTerm, EncodedTerm)> {
        let s = self.encode_term(&triple.subject)?;
        let p = self.encode_term(&triple.predicate)?;
        let o = self.encode_term(&triple.object)?;
        Ok((s, p, o))
    }

    // ---- Decoding -----------------------------------------------------------

    /// Decode an `EncodedTerm` back to a `StarTerm`.
    ///
    /// Returns `None` if the ID does not exist in the dictionary.
    pub fn decode_term(&self, encoded: &EncodedTerm) -> Option<StarTerm> {
        match encoded {
            EncodedTerm::Iri(id) => {
                let (key, _) = self.id_to_str.get(*id as usize)?;
                if let TermKey::Iri(iri) = key {
                    StarTerm::iri(iri).ok()
                } else {
                    None
                }
            }
            EncodedTerm::BlankNode(id) => {
                let (key, _) = self.id_to_str.get(*id as usize)?;
                if let TermKey::BlankNode(bn) = key {
                    StarTerm::blank_node(bn).ok()
                } else {
                    None
                }
            }
            EncodedTerm::Literal(id) => {
                let (key, repr) = self.id_to_str.get(*id as usize)?;
                if let TermKey::Literal(_) = key {
                    // Parse the canonical form back to a Literal.
                    Self::decode_literal_repr(repr)
                } else {
                    None
                }
            }
            EncodedTerm::QuotedTriple(id) => {
                let (s_enc, p_enc, o_enc) = self.id_to_quoted.get(*id as usize)?;
                let s = self.decode_term(s_enc)?;
                let p = self.decode_term(p_enc)?;
                let o = self.decode_term(o_enc)?;
                Some(StarTerm::quoted_triple(StarTriple::new(s, p, o)))
            }
        }
    }

    // ---- Statistics ---------------------------------------------------------

    /// Number of simple terms (IRIs + blank nodes + literals) in the
    /// dictionary.
    pub fn term_count(&self) -> usize {
        // Subtract 1 for the dummy slot 0.
        self.id_to_str.len().saturating_sub(1)
    }

    /// Number of quoted triples in the dictionary.
    pub fn quoted_count(&self) -> usize {
        self.id_to_quoted.len().saturating_sub(1)
    }

    /// Approximate heap memory usage in bytes.
    ///
    /// This is an estimate based on the sizes of the stored strings and
    /// hash-map overhead.
    pub fn memory_bytes(&self) -> usize {
        // String storage: sum of all stored string bytes.
        let str_bytes: usize = self
            .id_to_str
            .iter()
            .map(|(_, s)| s.len() + std::mem::size_of::<String>())
            .sum();

        // HashMap overhead: ~64 bytes per entry (key + value + metadata).
        let str_map_bytes = self.str_to_id.len() * 64;

        // Quoted triple storage: fixed-size tuples.
        let quoted_bytes = self.id_to_quoted.len() * 3 * std::mem::size_of::<EncodedTerm>();
        let quoted_map_bytes = self.quoted_to_id.len() * 64;

        str_bytes + str_map_bytes + quoted_bytes + quoted_map_bytes
    }

    /// Return the next term ID that would be assigned (useful for testing).
    pub fn next_term_id(&self) -> TermId {
        self.next_term_id
    }

    /// Return the next quoted ID that would be assigned.
    pub fn next_quoted_id(&self) -> QuotedId {
        self.next_quoted_id
    }

    // ---- Private helpers ----------------------------------------------------

    /// Intern a simple-term string and return its ID.  If the key already
    /// exists the existing ID is returned without inserting a duplicate.
    fn intern_str(&mut self, key: TermKey, repr: &str) -> TermId {
        if let Some(&existing) = self.str_to_id.get(&key) {
            return existing;
        }
        let id = self.next_term_id;
        self.str_to_id.insert(key.clone(), id);
        self.id_to_str.push((key, repr.to_owned()));
        self.next_term_id += 1;
        id
    }

    /// Intern a quoted triple (s, p, o) encoded tuple and return its ID.
    fn intern_quoted(&mut self, s: EncodedTerm, p: EncodedTerm, o: EncodedTerm) -> EncodedTerm {
        let key = (s.clone(), p.clone(), o.clone());
        if let Some(&existing) = self.quoted_to_id.get(&key) {
            return EncodedTerm::QuotedTriple(existing);
        }
        let id = self.next_quoted_id;
        self.quoted_to_id.insert(key, id);
        self.id_to_quoted.push((s, p, o));
        self.next_quoted_id += 1;
        EncodedTerm::QuotedTriple(id)
    }

    /// Parse a literal canonical representation of the form
    /// `lexical^^<datatype>@lang` back to a `StarTerm`.
    fn decode_literal_repr(repr: &str) -> Option<StarTerm> {
        // Split on `^^` first (datatype), then `@` (language tag).
        if let Some(dt_pos) = repr.find("^^") {
            let value = &repr[..dt_pos];
            let datatype = &repr[dt_pos + 2..];
            StarTerm::literal_with_datatype(value, datatype).ok()
        } else if let Some(lang_pos) = repr.rfind('@') {
            let value = &repr[..lang_pos];
            let lang = &repr[lang_pos + 1..];
            StarTerm::literal_with_language(value, lang).ok()
        } else {
            StarTerm::literal(repr).ok()
        }
    }
}

impl Default for StarDictionary {
    fn default() -> Self {
        Self::new()
    }
}

// ---- CompressedTripleSet ---------------------------------------------------

/// A compact storage structure for encoded triples.
///
/// Triples are stored as `(EncodedTerm, EncodedTerm, EncodedTerm)` tuples,
/// dramatically reducing memory compared to storing full string terms.
pub struct CompressedTripleSet {
    dict: StarDictionary,
    triples: Vec<(EncodedTerm, EncodedTerm, EncodedTerm)>,
}

impl CompressedTripleSet {
    /// Create an empty compressed triple set.
    pub fn new() -> Self {
        Self {
            dict: StarDictionary::new(),
            triples: Vec::new(),
        }
    }

    /// Insert a triple, encoding it via the dictionary.
    pub fn insert(&mut self, triple: &StarTriple) -> StarResult<()> {
        let encoded = self.dict.encode_triple(triple)?;
        self.triples.push(encoded);
        Ok(())
    }

    /// Decode and return all triples.
    pub fn iter_triples(&self) -> impl Iterator<Item = Option<StarTriple>> + '_ {
        self.triples.iter().map(move |(s, p, o)| {
            let s_term = self.dict.decode_term(s)?;
            let p_term = self.dict.decode_term(p)?;
            let o_term = self.dict.decode_term(o)?;
            Some(StarTriple::new(s_term, p_term, o_term))
        })
    }

    /// Number of triples stored.
    pub fn len(&self) -> usize {
        self.triples.len()
    }

    /// Return `true` if no triples have been inserted.
    pub fn is_empty(&self) -> bool {
        self.triples.is_empty()
    }

    /// Access the underlying dictionary (for statistics / inspection).
    pub fn dictionary(&self) -> &StarDictionary {
        &self.dict
    }

    /// Approximate heap memory usage in bytes.
    pub fn memory_bytes(&self) -> usize {
        self.dict.memory_bytes() + self.triples.len() * 3 * std::mem::size_of::<EncodedTerm>()
    }
}

impl Default for CompressedTripleSet {
    fn default() -> Self {
        Self::new()
    }
}

// ---- Tests -----------------------------------------------------------------

#[cfg(test)]
mod tests {
    use super::*;
    use crate::model::{BlankNode, Literal, NamedNode};

    fn iri(s: &str) -> StarTerm {
        StarTerm::NamedNode(NamedNode { iri: s.to_owned() })
    }

    fn blank(id: &str) -> StarTerm {
        StarTerm::BlankNode(BlankNode { id: id.to_owned() })
    }

    fn lit(v: &str) -> StarTerm {
        StarTerm::Literal(Literal {
            value: v.to_owned(),
            language: None,
            datatype: None,
        })
    }

    fn lit_lang(v: &str, lang: &str) -> StarTerm {
        StarTerm::Literal(Literal {
            value: v.to_owned(),
            language: Some(lang.to_owned()),
            datatype: None,
        })
    }

    fn lit_dt(v: &str, dt: &str) -> StarTerm {
        StarTerm::Literal(Literal {
            value: v.to_owned(),
            language: None,
            datatype: Some(NamedNode { iri: dt.to_owned() }),
        })
    }

    #[test]
    fn test_iri_round_trip() {
        let mut dict = StarDictionary::new();
        let term = iri("http://example.org/subject");
        let encoded = dict.encode_term(&term).expect("encode ok");
        assert!(matches!(encoded, EncodedTerm::Iri(_)));
        let decoded = dict.decode_term(&encoded).expect("decode ok");
        assert_eq!(decoded, term);
    }

    #[test]
    fn test_blank_node_round_trip() {
        let mut dict = StarDictionary::new();
        let term = blank("b1");
        let encoded = dict.encode_term(&term).expect("encode ok");
        assert!(matches!(encoded, EncodedTerm::BlankNode(_)));
        let decoded = dict.decode_term(&encoded).expect("decode ok");
        assert_eq!(decoded, term);
    }

    #[test]
    fn test_literal_round_trip() {
        let mut dict = StarDictionary::new();
        let term = lit("hello world");
        let encoded = dict.encode_term(&term).expect("encode ok");
        assert!(matches!(encoded, EncodedTerm::Literal(_)));
        let decoded = dict.decode_term(&encoded).expect("decode ok");
        assert_eq!(decoded, term);
    }

    #[test]
    fn test_literal_with_language_round_trip() {
        let mut dict = StarDictionary::new();
        let term = lit_lang("Bonjour", "fr");
        let encoded = dict.encode_term(&term).expect("encode ok");
        let decoded = dict.decode_term(&encoded).expect("decode ok");
        assert_eq!(decoded, term);
    }

    #[test]
    fn test_literal_with_datatype_round_trip() {
        let mut dict = StarDictionary::new();
        let term = lit_dt("42", "http://www.w3.org/2001/XMLSchema#integer");
        let encoded = dict.encode_term(&term).expect("encode ok");
        let decoded = dict.decode_term(&encoded).expect("decode ok");
        assert_eq!(decoded, term);
    }

    #[test]
    fn test_deduplication() {
        let mut dict = StarDictionary::new();
        let alice = iri("http://example.org/alice");
        let id1 = dict.encode_term(&alice).expect("encode ok");
        let id2 = dict.encode_term(&alice).expect("encode ok");
        assert_eq!(id1, id2);
        assert_eq!(dict.term_count(), 1);
    }

    #[test]
    fn test_quoted_triple_round_trip() {
        let mut dict = StarDictionary::new();

        let inner = StarTriple::new(
            iri("http://example.org/alice"),
            iri("http://example.org/age"),
            lit("30"),
        );
        let quoted = StarTerm::quoted_triple(inner.clone());

        let encoded = dict.encode_term(&quoted).expect("encode ok");
        assert!(encoded.is_quoted());

        let decoded = dict.decode_term(&encoded).expect("decode ok");
        assert_eq!(decoded, quoted);
    }

    #[test]
    fn test_nested_quoted_triple_round_trip() {
        let mut dict = StarDictionary::new();

        let inner = StarTriple::new(
            iri("http://ex.org/s"),
            iri("http://ex.org/p"),
            iri("http://ex.org/o"),
        );
        let outer = StarTriple::new(
            StarTerm::quoted_triple(inner),
            iri("http://ex.org/meta"),
            lit("evidence"),
        );
        let doubly_quoted = StarTerm::quoted_triple(outer);

        let encoded = dict.encode_term(&doubly_quoted).expect("encode ok");
        let decoded = dict.decode_term(&encoded).expect("decode ok");
        assert_eq!(decoded, doubly_quoted);
    }

    #[test]
    fn test_quoted_deduplication() {
        let mut dict = StarDictionary::new();

        let triple = StarTriple::new(
            iri("http://ex.org/s"),
            iri("http://ex.org/p"),
            iri("http://ex.org/o"),
        );
        let qt = StarTerm::quoted_triple(triple);

        let id1 = dict.encode_term(&qt).expect("encode ok");
        let id2 = dict.encode_term(&qt).expect("encode ok");
        assert_eq!(id1, id2);
        assert_eq!(dict.quoted_count(), 1);
    }

    #[test]
    fn test_variable_encoding_fails() {
        let mut dict = StarDictionary::new();
        let var = StarTerm::variable("x").expect("valid variable");
        assert!(dict.encode_term(&var).is_err());
    }

    #[test]
    fn test_term_count_is_accurate() {
        let mut dict = StarDictionary::new();
        dict.encode_term(&iri("http://ex.org/a")).expect("ok");
        dict.encode_term(&iri("http://ex.org/b")).expect("ok");
        dict.encode_term(&blank("b1")).expect("ok");
        dict.encode_term(&lit("hello")).expect("ok");
        // Re-encode existing – should not increase count.
        dict.encode_term(&iri("http://ex.org/a")).expect("ok");
        assert_eq!(dict.term_count(), 4);
    }

    #[test]
    fn test_compressed_triple_set() {
        let mut set = CompressedTripleSet::new();

        for i in 0..100_usize {
            let triple = StarTriple::new(
                iri(&format!("http://ex.org/s{i}")),
                iri("http://ex.org/p"),
                lit(&format!("{i}")),
            );
            set.insert(&triple).expect("insert ok");
        }

        assert_eq!(set.len(), 100);
        // The predicate "http://ex.org/p" should be deduplicated to 1 entry.
        // Subjects + literals + predicate = 100 + 100 + 1 = 201
        assert_eq!(set.dictionary().term_count(), 201);

        // Verify round-trip for all stored triples.
        let decoded: Vec<StarTriple> = set
            .iter_triples()
            .collect::<Vec<_>>()
            .into_iter()
            .flatten()
            .collect();
        assert_eq!(decoded.len(), 100);
    }

    #[test]
    fn test_memory_bytes_grows_with_insertions() {
        let mut dict = StarDictionary::new();
        let before = dict.memory_bytes();
        for i in 0..50_usize {
            dict.encode_term(&iri(&format!("http://ex.org/r{i}")))
                .expect("ok");
        }
        let after = dict.memory_bytes();
        assert!(after > before, "memory should grow after insertions");
    }

    #[test]
    fn test_encode_triple() {
        let mut dict = StarDictionary::new();
        let triple = StarTriple::new(
            iri("http://ex.org/s"),
            iri("http://ex.org/p"),
            iri("http://ex.org/o"),
        );
        let (s, p, o) = dict.encode_triple(&triple).expect("encode ok");
        assert!(matches!(s, EncodedTerm::Iri(_)));
        assert!(matches!(p, EncodedTerm::Iri(_)));
        assert!(matches!(o, EncodedTerm::Iri(_)));
    }
}