oxirs-wasm 0.2.3

WebAssembly bindings for OxiRS - Run RDF/SPARQL in the browser
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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
//! High-level public API for WASM consumers
//!
//! This module provides clean, ergonomic Rust types that can be bound to
//! JavaScript with `wasm_bindgen`, or used directly from Rust tests.
//!
//! Design principles:
//! - All public methods use plain Rust types (no `JsValue`) so they can be
//!   unit-tested natively without a WASM runtime
//! - Error results are `Result<_, String>` for easy JS conversion
//! - Streaming loading is supported via `feed_chunk` / `finish_loading`

use crate::parser::{RdfFormat, StreamingParser};
use crate::store::{CompactTripleStore, RdfTerm};

// -----------------------------------------------------------------------
// Conversion helpers
// -----------------------------------------------------------------------

/// Convert a serialized N-Triples-style string into an [`RdfTerm`].
///
/// Accepts:
/// - `<iri>` -> `RdfTerm::Iri`
/// - `_:id` -> `RdfTerm::BlankNode`
/// - `"value"@lang` -> `RdfTerm::LangLiteral`
/// - `"value"^^<dt>` -> `RdfTerm::TypedLiteral`
/// - `"value"` → `RdfTerm::PlainLiteral`
/// - anything else → `RdfTerm::Iri` (treated as bare IRI)
fn str_to_rdf_term(s: &str) -> RdfTerm {
    let s = s.trim();
    if s.starts_with('<') && s.ends_with('>') {
        RdfTerm::iri(&s[1..s.len() - 1])
    } else if let Some(id) = s.strip_prefix("_:") {
        RdfTerm::blank(id)
    } else if s.starts_with('"') {
        // Find closing quote (accounting for escapes)
        let chars: Vec<char> = s.chars().collect();
        let mut pos = 1usize;
        let mut escaped = false;
        while pos < chars.len() {
            if escaped {
                escaped = false;
                pos += 1;
                continue;
            }
            if chars[pos] == '\\' {
                escaped = true;
                pos += 1;
                continue;
            }
            if chars[pos] == '"' {
                break;
            }
            pos += 1;
        }
        // Value is chars[1..pos]
        let value: String = chars[1..pos].iter().collect();
        let rest: String = if pos + 1 < chars.len() {
            chars[pos + 1..].iter().collect()
        } else {
            String::new()
        };

        if let Some(lang) = rest.strip_prefix('@') {
            RdfTerm::lang_literal(value, lang)
        } else if let Some(dt_raw) = rest.strip_prefix("^^") {
            let datatype = if dt_raw.starts_with('<') && dt_raw.ends_with('>') {
                dt_raw[1..dt_raw.len() - 1].to_string()
            } else {
                dt_raw.to_string()
            };
            RdfTerm::typed_literal(value, datatype)
        } else {
            RdfTerm::literal(value)
        }
    } else {
        // Bare string – treat as IRI
        RdfTerm::iri(s)
    }
}

/// Convert an [`RdfTerm`] to its N-Triples string representation
fn rdf_term_to_str(term: &RdfTerm) -> String {
    term.to_string()
}

// -----------------------------------------------------------------------
// WasmSparqlStore
// -----------------------------------------------------------------------

/// A SPARQL-capable RDF store suitable for WASM binding.
///
/// Combines a [`CompactTripleStore`] (memory-efficient storage) with a
/// [`StreamingParser`] (incremental RDF parsing) into a single convenient API.
///
/// # Usage (Rust)
/// ```no_run
/// # use oxirs_wasm::api::wasm_api::WasmSparqlStore;
/// let mut store = WasmSparqlStore::new();
/// let count = store.load_ntriples("<http://s> <http://p> <http://o> .\n").expect("should succeed");
/// assert_eq!(count, 1);
///
/// let results = store.query_pattern(Some("<http://s>"), None, None);
/// assert_eq!(results.len(), 1);
/// ```
pub struct WasmSparqlStore {
    /// Compact triple store (dictionary + sorted indexes)
    store: CompactTripleStore,
    /// Streaming parser state (for incremental chunk loading)
    streaming_parser: Option<StreamingParser>,
    /// Format for the active streaming session
    streaming_format: RdfFormat,
    /// Total triples loaded via streaming in the current session
    streaming_count: usize,
}

impl WasmSparqlStore {
    /// Create a new empty store
    pub fn new() -> Self {
        Self {
            store: CompactTripleStore::new(),
            streaming_parser: None,
            streaming_format: RdfFormat::NTriples,
            streaming_count: 0,
        }
    }

    // -----------------------------------------------------------------------
    // Bulk loading
    // -----------------------------------------------------------------------

    /// Load a complete Turtle document.
    ///
    /// Returns the number of triples inserted.
    pub fn load_turtle(&mut self, data: &str) -> Result<usize, String> {
        self.load_format(data, RdfFormat::Turtle)
    }

    /// Load a complete N-Triples document.
    ///
    /// Returns the number of triples inserted.
    pub fn load_ntriples(&mut self, data: &str) -> Result<usize, String> {
        self.load_format(data, RdfFormat::NTriples)
    }

    /// Load a complete N-Quads document (graph names are ignored for storage).
    ///
    /// Returns the number of triples inserted.
    pub fn load_nquads(&mut self, data: &str) -> Result<usize, String> {
        self.load_format(data, RdfFormat::NQuads)
    }

    fn load_format(&mut self, data: &str, format: RdfFormat) -> Result<usize, String> {
        let mut parser = StreamingParser::new(format);
        let mut stmts = parser
            .feed(data)
            .map_err(|e| format!("Parse error: {}", e))?;
        let mut tail = parser
            .finish()
            .map_err(|e| format!("Parse error during finalization: {}", e))?;
        stmts.append(&mut tail);

        let before = self.store.triple_count();
        self.store.bulk_insert(stmts.iter().map(|s| {
            let subj = s.subject().to_ntriples_string();
            let pred = s.predicate().to_ntriples_string();
            let obj = s.object().to_ntriples_string();
            (
                str_to_rdf_term(&subj),
                str_to_rdf_term(&pred),
                str_to_rdf_term(&obj),
            )
        }));
        let inserted = self.store.triple_count() - before;
        Ok(inserted)
    }

    // -----------------------------------------------------------------------
    // Streaming loading (chunk-by-chunk)
    // -----------------------------------------------------------------------

    /// Begin a streaming load session in the given format.
    ///
    /// Must be called before [`feed_chunk`](Self::feed_chunk). Any previously
    /// active streaming session is discarded.
    pub fn begin_streaming(&mut self, format: RdfFormat) {
        self.streaming_parser = Some(StreamingParser::new(format));
        self.streaming_format = format;
        self.streaming_count = 0;
    }

    /// Feed a chunk of RDF data in the current streaming session.
    ///
    /// Returns the number of triples parsed from complete statements in this
    /// chunk. Incomplete statements are buffered for subsequent chunks.
    ///
    /// # Errors
    /// Returns an error string if the chunk contains a syntax error.
    pub fn feed_chunk(&mut self, chunk: &str) -> Result<usize, String> {
        let parser = self.streaming_parser.as_mut().ok_or_else(|| {
            "No active streaming session. Call begin_streaming() first.".to_string()
        })?;

        let stmts = parser
            .feed(chunk)
            .map_err(|e| format!("Parse error in chunk: {}", e))?;

        let count = stmts.len();
        self.streaming_count += count;
        self.store.bulk_insert(stmts.iter().map(|s| {
            let subj = s.subject().to_ntriples_string();
            let pred = s.predicate().to_ntriples_string();
            let obj = s.object().to_ntriples_string();
            (
                str_to_rdf_term(&subj),
                str_to_rdf_term(&pred),
                str_to_rdf_term(&obj),
            )
        }));

        Ok(count)
    }

    /// Finish the current streaming session, flushing any remaining buffered data.
    ///
    /// Returns the total number of triples inserted during this session.
    pub fn finish_loading(&mut self) -> Result<usize, String> {
        let parser = self.streaming_parser.as_mut().ok_or_else(|| {
            "No active streaming session. Call begin_streaming() first.".to_string()
        })?;

        let stmts = parser
            .finish()
            .map_err(|e| format!("Parse error in final flush: {}", e))?;

        let count = stmts.len();
        self.streaming_count += count;
        self.store.bulk_insert(stmts.iter().map(|s| {
            let subj = s.subject().to_ntriples_string();
            let pred = s.predicate().to_ntriples_string();
            let obj = s.object().to_ntriples_string();
            (
                str_to_rdf_term(&subj),
                str_to_rdf_term(&pred),
                str_to_rdf_term(&obj),
            )
        }));

        let total = self.streaming_count;
        self.streaming_parser = None;
        self.streaming_count = 0;

        Ok(total)
    }

    // -----------------------------------------------------------------------
    // Triple management
    // -----------------------------------------------------------------------

    /// Insert a single triple.
    ///
    /// Terms should be in N-Triples serialization format:
    /// - IRIs: `<http://example.org/>`
    /// - Blank nodes: `_:b0`
    /// - Literals: `"hello"`, `"hello"@en`, `"42"^^<xsd:integer>`
    pub fn insert_triple(&mut self, subject: &str, predicate: &str, object: &str) {
        self.store.insert(
            &str_to_rdf_term(subject),
            &str_to_rdf_term(predicate),
            &str_to_rdf_term(object),
        );
    }

    /// Delete a triple.
    ///
    /// Returns `true` if the triple existed and was deleted.
    pub fn delete_triple(&mut self, subject: &str, predicate: &str, object: &str) -> bool {
        self.store.delete(
            &str_to_rdf_term(subject),
            &str_to_rdf_term(predicate),
            &str_to_rdf_term(object),
        )
    }

    /// Check whether a triple exists
    pub fn triple_exists(&self, subject: &str, predicate: &str, object: &str) -> bool {
        self.store.contains(
            &str_to_rdf_term(subject),
            &str_to_rdf_term(predicate),
            &str_to_rdf_term(object),
        )
    }

    // -----------------------------------------------------------------------
    // Querying
    // -----------------------------------------------------------------------

    /// Execute a triple pattern query.
    ///
    /// Each optional argument is an N-Triples-serialized term acting as a filter.
    /// `None` means "match anything" (wildcard).
    ///
    /// Returns a list of matching triples, each as `[subject, predicate, object]`
    /// in N-Triples serialization format.
    ///
    /// # Example
    /// ```no_run
    /// # use oxirs_wasm::api::wasm_api::WasmSparqlStore;
    /// let mut store = WasmSparqlStore::new();
    /// store.load_ntriples("<http://s> <http://p> <http://o> .\n").expect("should succeed");
    ///
    /// // Find all triples with subject <http://s>
    /// let results = store.query_pattern(Some("<http://s>"), None, None);
    /// assert_eq!(results.len(), 1);
    ///
    /// // Find all triples
    /// let all = store.query_pattern(None, None, None);
    /// assert_eq!(all.len(), 1);
    /// ```
    pub fn query_pattern(
        &mut self,
        subject: Option<&str>,
        predicate: Option<&str>,
        object: Option<&str>,
    ) -> Vec<Vec<String>> {
        match (subject, predicate, object) {
            // Subject bound, predicate and object unbound → use SPO index
            (Some(s), None, None) => {
                let s_term = str_to_rdf_term(s);
                self.store
                    .find_by_subject(&s_term)
                    .into_iter()
                    .map(|(s, p, o)| vec![s.to_string(), p.to_string(), o.to_string()])
                    .collect()
            }
            // Predicate bound, subject and object unbound → use PSO index
            (None, Some(p), None) => {
                let p_term = str_to_rdf_term(p);
                self.store
                    .find_by_predicate(&p_term)
                    .into_iter()
                    .map(|(s, p, o)| vec![s.to_string(), p.to_string(), o.to_string()])
                    .collect()
            }
            // Predicate and object bound → specialized index lookup
            (None, Some(p), Some(o)) => {
                let p_term = str_to_rdf_term(p);
                let o_term = str_to_rdf_term(o);
                self.store
                    .find_by_predicate_object(&p_term, &o_term)
                    .into_iter()
                    .map(|s| {
                        vec![
                            s.to_string(),
                            rdf_term_to_str(&str_to_rdf_term(p)),
                            rdf_term_to_str(&str_to_rdf_term(o)),
                        ]
                    })
                    .collect()
            }
            // Full wildcard or other combinations → linear scan with filters
            _ => {
                let s_filter = subject.map(str_to_rdf_term);
                let p_filter = predicate.map(str_to_rdf_term);
                let o_filter = object.map(str_to_rdf_term);

                self.store
                    .iter_all()
                    .filter(|(s, p, o)| {
                        s_filter.as_ref().map_or(true, |f| f == s)
                            && p_filter.as_ref().map_or(true, |f| f == p)
                            && o_filter.as_ref().map_or(true, |f| f == o)
                    })
                    .map(|(s, p, o)| vec![s.to_string(), p.to_string(), o.to_string()])
                    .collect()
            }
        }
    }

    /// Find all triples with the given subject
    pub fn find_by_subject(&mut self, subject: &str) -> Vec<Vec<String>> {
        self.query_pattern(Some(subject), None, None)
    }

    /// Find all triples with the given predicate
    pub fn find_by_predicate(&mut self, predicate: &str) -> Vec<Vec<String>> {
        self.query_pattern(None, Some(predicate), None)
    }

    /// Find all subjects that have a specific predicate-object pair
    pub fn find_subjects_by_predicate_object(
        &mut self,
        predicate: &str,
        object: &str,
    ) -> Vec<String> {
        let p_term = str_to_rdf_term(predicate);
        let o_term = str_to_rdf_term(object);
        self.store
            .find_by_predicate_object(&p_term, &o_term)
            .into_iter()
            .map(|s| s.to_string())
            .collect()
    }

    // -----------------------------------------------------------------------
    // Serialization
    // -----------------------------------------------------------------------

    /// Export all triples as N-Triples text
    pub fn to_ntriples(&mut self) -> String {
        self.store
            .iter_all()
            .map(|(s, p, o)| format!("{} {} {} .\n", s, p, o))
            .collect()
    }

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

    /// Return the number of triples currently stored
    pub fn triple_count(&self) -> usize {
        self.store.triple_count()
    }

    /// Return the number of unique RDF terms in the dictionary
    pub fn term_count(&self) -> usize {
        self.store.term_count()
    }

    /// Estimate memory usage in bytes (triples + dictionary)
    pub fn memory_bytes(&self) -> usize {
        self.store.memory_estimate_bytes()
    }
}

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

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

#[cfg(test)]
mod tests {
    use super::*;

    fn make_store_with_data() -> WasmSparqlStore {
        let mut store = WasmSparqlStore::new();
        store
            .load_ntriples(
                "<http://example.org/alice> <http://example.org/knows> <http://example.org/bob> .\n\
                 <http://example.org/alice> <http://example.org/name> \"Alice\" .\n\
                 <http://example.org/bob> <http://example.org/name> \"Bob\" .\n",
            )
            .expect("load_ntriples");
        store
    }

    #[test]
    fn test_load_ntriples() {
        let mut store = WasmSparqlStore::new();
        let count = store
            .load_ntriples("<http://s> <http://p> <http://o> .\n")
            .expect("load");
        assert_eq!(count, 1);
        assert_eq!(store.triple_count(), 1);
    }

    #[test]
    fn test_load_turtle() {
        let mut store = WasmSparqlStore::new();
        let ttl = "@prefix ex: <http://example.org/> .\nex:s ex:p ex:o .\n";
        let count = store.load_turtle(ttl).expect("load turtle");
        assert_eq!(count, 1);
    }

    #[test]
    fn test_streaming_ntriples() {
        let mut store = WasmSparqlStore::new();
        store.begin_streaming(RdfFormat::NTriples);

        // Feed in three chunks (split mid-line)
        let c1 = store.feed_chunk("<http://s> ").expect("chunk 1");
        assert_eq!(c1, 0); // No complete statement yet

        let c2 = store
            .feed_chunk("<http://p> <http://o> .\n")
            .expect("chunk 2");
        assert_eq!(c2, 1);

        let total = store.finish_loading().expect("finish");
        assert_eq!(total, 1);
        assert_eq!(store.triple_count(), 1);
    }

    #[test]
    fn test_streaming_without_begin_fails() {
        let mut store = WasmSparqlStore::new();
        let result = store.feed_chunk("data");
        assert!(result.is_err());
    }

    #[test]
    fn test_streaming_multiple_chunks() {
        let mut store = WasmSparqlStore::new();
        store.begin_streaming(RdfFormat::NTriples);

        // Feed 10 triples one at a time
        for i in 0..10 {
            let line = format!("<http://s{}> <http://p> <http://o{}> .\n", i, i);
            let c = store.feed_chunk(&line).expect("chunk");
            assert_eq!(c, 1);
        }

        let total = store.finish_loading().expect("finish");
        assert_eq!(total, 10);
        assert_eq!(store.triple_count(), 10);
    }

    #[test]
    fn test_insert_and_delete() {
        let mut store = WasmSparqlStore::new();
        store.insert_triple("<http://s>", "<http://p>", "<http://o>");
        assert!(store.triple_exists("<http://s>", "<http://p>", "<http://o>"));

        let deleted = store.delete_triple("<http://s>", "<http://p>", "<http://o>");
        assert!(deleted);
        assert!(!store.triple_exists("<http://s>", "<http://p>", "<http://o>"));
    }

    #[test]
    fn test_query_pattern_all_wildcards() {
        let mut store = make_store_with_data();
        let all = store.query_pattern(None, None, None);
        assert_eq!(all.len(), 3);
    }

    #[test]
    fn test_query_pattern_subject_bound() {
        let mut store = make_store_with_data();
        let results = store.query_pattern(Some("<http://example.org/alice>"), None, None);
        assert_eq!(results.len(), 2); // knows + name
    }

    #[test]
    fn test_query_pattern_predicate_bound() {
        let mut store = make_store_with_data();
        let results = store.query_pattern(None, Some("<http://example.org/name>"), None);
        assert_eq!(results.len(), 2); // Alice + Bob
    }

    #[test]
    fn test_query_pattern_predicate_object_bound() {
        let mut store = make_store_with_data();
        let results = store.query_pattern(
            None,
            Some("<http://example.org/knows>"),
            Some("<http://example.org/bob>"),
        );
        assert_eq!(results.len(), 1);
        assert!(results[0][0].contains("alice"));
    }

    #[test]
    fn test_query_pattern_no_match() {
        let mut store = make_store_with_data();
        let results = store.query_pattern(Some("<http://example.org/nobody>"), None, None);
        assert_eq!(results.len(), 0);
    }

    #[test]
    fn test_find_by_subject() {
        let mut store = make_store_with_data();
        let results = store.find_by_subject("<http://example.org/bob>");
        assert_eq!(results.len(), 1); // name only
    }

    #[test]
    fn test_find_by_predicate() {
        let mut store = make_store_with_data();
        let results = store.find_by_predicate("<http://example.org/name>");
        assert_eq!(results.len(), 2);
    }

    #[test]
    fn test_find_subjects_by_predicate_object() {
        let mut store = make_store_with_data();
        let subjects = store.find_subjects_by_predicate_object(
            "<http://example.org/knows>",
            "<http://example.org/bob>",
        );
        assert_eq!(subjects.len(), 1);
        assert!(subjects[0].contains("alice"));
    }

    #[test]
    fn test_to_ntriples() {
        let mut store = make_store_with_data();
        let nt = store.to_ntriples();
        assert!(nt.contains("<http://example.org/alice>"));
        assert!(nt.contains("<http://example.org/bob>"));
    }

    #[test]
    fn test_triple_count_and_term_count() {
        let store = make_store_with_data();
        assert_eq!(store.triple_count(), 3);
        // At least 5 unique terms (alice, knows, bob, name, "Alice", "Bob")
        assert!(store.term_count() >= 5);
    }

    #[test]
    fn test_memory_bytes() {
        let store = make_store_with_data();
        assert!(store.memory_bytes() > 0);
    }

    #[test]
    fn test_str_to_rdf_term_iri() {
        let term = str_to_rdf_term("<http://example.org/>");
        assert!(matches!(term, RdfTerm::Iri(_)));
        assert_eq!(term.value(), "http://example.org/");
    }

    #[test]
    fn test_str_to_rdf_term_blank() {
        let term = str_to_rdf_term("_:b0");
        assert!(matches!(term, RdfTerm::BlankNode(_)));
        assert_eq!(term.value(), "b0");
    }

    #[test]
    fn test_str_to_rdf_term_literal() {
        let term = str_to_rdf_term("\"hello\"");
        assert!(matches!(term, RdfTerm::PlainLiteral(_)));
        assert_eq!(term.value(), "hello");
    }

    #[test]
    fn test_str_to_rdf_term_lang_literal() {
        let term = str_to_rdf_term("\"hello\"@en");
        assert!(matches!(term, RdfTerm::LangLiteral { .. }));
        assert_eq!(term.value(), "hello");
        assert_eq!(term.lang(), Some("en"));
    }

    #[test]
    fn test_str_to_rdf_term_typed_literal() {
        let term = str_to_rdf_term("\"42\"^^<http://www.w3.org/2001/XMLSchema#integer>");
        assert!(matches!(term, RdfTerm::TypedLiteral { .. }));
        assert_eq!(term.value(), "42");
        assert_eq!(
            term.datatype(),
            Some("http://www.w3.org/2001/XMLSchema#integer")
        );
    }

    #[test]
    fn test_load_turtle_with_semicolon() {
        let mut store = WasmSparqlStore::new();
        let ttl = "@prefix ex: <http://example.org/> .\n\
                   ex:alice ex:knows ex:bob ; ex:name \"Alice\" .\n";
        let count = store.load_turtle(ttl).expect("load turtle");
        assert_eq!(count, 2);
        assert_eq!(store.triple_count(), 2);
    }
}