From 36868e3be3575b0fa977c84b384eb0688d0b22ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Haudebourg?= Date: Fri, 22 Mar 2024 15:25:24 +0100 Subject: [PATCH] Bump `rdf-types` to version 0.22.0. --- Cargo.lock | 58 +++++++++---------- Cargo.toml | 12 ++-- .../rust/treeldr-rs-macros/src/generate/de.rs | 8 +-- .../src/{generate.rs => generate/mod.rs} | 0 generators/rust/treeldr-rs/src/datatypes.rs | 9 +-- .../rust/treeldr-rs/src/{de.rs => de/mod.rs} | 0 generators/rust/treeldr-rs/src/rdf.rs | 4 +- .../treeldr-rs/src/{ser.rs => ser/mod.rs} | 0 layouts/examples/combine.rs | 4 +- layouts/src/distill/de.rs | 3 + layouts/src/distill/hy/data.rs | 42 ++++++-------- layouts/src/lib.rs | 4 +- layouts/src/value/cbor/mod.rs | 36 ++++++------ layouts/src/value/cbor/serde_cbor.rs | 4 +- layouts/tests/distill.rs | 6 +- 15 files changed, 94 insertions(+), 96 deletions(-) rename generators/rust/treeldr-rs-macros/src/{generate.rs => generate/mod.rs} (100%) rename generators/rust/treeldr-rs/src/{de.rs => de/mod.rs} (100%) rename generators/rust/treeldr-rs/src/{ser.rs => ser/mod.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 10856fa..d47f86d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -204,9 +204,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.2" +version = "4.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" +checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" dependencies = [ "clap_builder", "clap_derive", @@ -226,14 +226,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.0" +version = "4.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -316,7 +316,7 @@ dependencies = [ "enum-ordinalize 4.3.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -329,7 +329,7 @@ dependencies = [ "num-traits", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -349,7 +349,7 @@ checksum = "0d28318a75d4aead5c4db25382e8ef717932d0346600cacae6357eb5941bc5ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -392,9 +392,9 @@ checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" @@ -537,9 +537,9 @@ dependencies = [ [[package]] name = "nquads-syntax" -version = "0.18.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2194fce1f6b074aed63a56cc2cda1520037f6efa560026dee4a9576343ba54ea" +checksum = "d093a55cc878f36a9fb55d876fff1feef013c92b0d7218e6dc30aed2e6313007" dependencies = [ "decoded-char", "iref", @@ -686,9 +686,9 @@ checksum = "2bdb1922ff2a9ec6037b4c0698ba44cf423fcc3656ba9ea7f45959ebb4525bf0" [[package]] name = "rdf-types" -version = "0.19.8" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ebae16231635524baf6c872c58e7428e5bc23711127e8e35dacc53284949e3" +checksum = "80515d9a077a11efd380ae8e3840bdecd943af3023cf428d8a73e34642f2f874" dependencies = [ "educe 0.5.11", "indexmap", @@ -747,7 +747,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -783,9 +783,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "static-iref" @@ -795,7 +795,7 @@ checksum = "3cc4068497ae43896d41174586dcdc2153a1af2c82856fb308bfaaddc28e5549" dependencies = [ "iref", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -814,7 +814,7 @@ dependencies = [ "quote", "serde", "sha2", - "syn 2.0.52", + "syn 2.0.53", "thiserror", ] @@ -834,7 +834,7 @@ dependencies = [ "quote", "serde", "sha2", - "syn 2.0.52", + "syn 2.0.53", "thiserror", ] @@ -870,9 +870,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" dependencies = [ "proc-macro2", "quote", @@ -905,7 +905,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -943,7 +943,7 @@ dependencies = [ "rdf-types", "serde_json", "stderrlog", - "syn 2.0.52", + "syn 2.0.53", "thiserror", "treeldr-layouts", ] @@ -983,7 +983,7 @@ dependencies = [ "rdf-types", "serde_json", "static-iref", - "syn 2.0.52", + "syn 2.0.53", "thiserror", "treeldr-gen-rust", "treeldr-layouts", @@ -1040,7 +1040,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "wasm-bindgen-shared", ] @@ -1062,7 +1062,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1181,9 +1181,9 @@ checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "xsd-types" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba162384bfc9b961b94a854ad494edc723aee56389adff4c47b0e35c46155adb" +checksum = "694ae3389b0d6e7ab43f40d5f8f140cda0ec4018548a2ee1ef4145149df513e1" dependencies = [ "chrono", "iref", diff --git a/Cargo.toml b/Cargo.toml index 60587e4..d792b15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,10 +8,10 @@ members = [ resolver = "2" [workspace.package] -version = "0.2.0" -edition = "2021" authors = ["Spruce Systems Inc."] -rust-version = "1.74" +edition = "2021" +rust-version = "1.74.0" +version = "0.2.0" [workspace.dependencies] treeldr-layouts = { path = "layouts", version = "0.2.0" } @@ -25,8 +25,8 @@ num-bigint = "0.4" num-rational = "0.4" iref = "3.1.4" static-iref = "3.0" -rdf-types = "0.19.8" -xsd-types = "0.9.1" +rdf-types = "0.22.0" +xsd-types = "0.9.2" btree-range-map = { version = "0.7.2", features = ["serde"] } langtag = "0.4.0" thiserror = "1.0.50" @@ -34,7 +34,7 @@ serde = "1.0.192" serde_json = { version = "1.0", features = ["arbitrary_precision"] } locspan = "0.8.2" -nquads-syntax = "0.18.0" +nquads-syntax = "0.19.0" clap = "4.0" stderrlog = "0.5" diff --git a/generators/rust/treeldr-rs-macros/src/generate/de.rs b/generators/rust/treeldr-rs-macros/src/generate/de.rs index a75b62f..031b82a 100644 --- a/generators/rust/treeldr-rs-macros/src/generate/de.rs +++ b/generators/rust/treeldr-rs-macros/src/generate/de.rs @@ -719,17 +719,17 @@ fn generate_data( for l in rdf.interpretation.literals_of(&resource) { has_literal = true; let literal = rdf.vocabulary.literal(l).unwrap(); - let ty_iri = match &literal.type_ { - ::treeldr::rdf_types::LiteralType::Any(i) => { + let ty_iri = match literal.type_ { + ::treeldr::rdf_types::LiteralTypeRef::Any(i) => { rdf.vocabulary.iri(i).unwrap() }, - ::treeldr::rdf_types::LiteralType::LangString(_) => { + ::treeldr::rdf_types::LiteralTypeRef::LangString(_) => { ::treeldr::rdf_types::RDF_LANG_STRING } }; if ty_iri == expected_ty_iri { - if let Ok(value) = ::treeldr::de::FromRdfLiteral::from_rdf_literal(&literal.value) { + if let Ok(value) = ::treeldr::de::FromRdfLiteral::from_rdf_literal(literal.value) { if result.replace(value).is_some() { return Err(::treeldr::DeserializeError::AmbiguousLiteralValue) } diff --git a/generators/rust/treeldr-rs-macros/src/generate.rs b/generators/rust/treeldr-rs-macros/src/generate/mod.rs similarity index 100% rename from generators/rust/treeldr-rs-macros/src/generate.rs rename to generators/rust/treeldr-rs-macros/src/generate/mod.rs diff --git a/generators/rust/treeldr-rs/src/datatypes.rs b/generators/rust/treeldr-rs/src/datatypes.rs index 3d0667a..39e6513 100644 --- a/generators/rust/treeldr-rs/src/datatypes.rs +++ b/generators/rust/treeldr-rs/src/datatypes.rs @@ -4,7 +4,8 @@ use rdf_types::{ ReverseTermInterpretation, ReverseTermInterpretationMut, TermInterpretation, TermInterpretationMut, }, - Dataset, InterpretationMut, Literal, LiteralType, Vocabulary, VocabularyMut, XSD_STRING, + Dataset, InterpretationMut, Literal, LiteralType, LiteralTypeRef, Vocabulary, VocabularyMut, + XSD_STRING, }; use crate::{ @@ -120,10 +121,10 @@ where { for l in rdf.interpretation.literals_of(&inputs[0]) { let literal = rdf.vocabulary.literal(l).unwrap(); - if let LiteralType::Any(i) = &literal.type_ { + if let LiteralTypeRef::Any(i) = literal.type_ { let iri = rdf.vocabulary.iri(i).unwrap(); if iri == XSD_STRING { - return Ok(literal.value.clone()); + return Ok(literal.value.to_owned()); } } } @@ -178,7 +179,7 @@ macro_rules! xsd_datatypes { for l in rdf.interpretation.literals_of(&inputs[0]) { has_literal = true; let literal = rdf.vocabulary.literal(l).unwrap(); - if let LiteralType::Any(i) = &literal.type_ { + if let LiteralTypeRef::Any(i) = literal.type_ { let iri = rdf.vocabulary.iri(i).unwrap(); if iri == xsd_types::$xsd_iri { match Self::parse_xsd(&literal.value) { diff --git a/generators/rust/treeldr-rs/src/de.rs b/generators/rust/treeldr-rs/src/de/mod.rs similarity index 100% rename from generators/rust/treeldr-rs/src/de.rs rename to generators/rust/treeldr-rs/src/de/mod.rs diff --git a/generators/rust/treeldr-rs/src/rdf.rs b/generators/rust/treeldr-rs/src/rdf.rs index 4b173a5..fc7c3cf 100644 --- a/generators/rust/treeldr-rs/src/rdf.rs +++ b/generators/rust/treeldr-rs/src/rdf.rs @@ -47,7 +47,9 @@ impl<'a, V, I> RdfContext<'a, V, I> { LiteralType::LangString(tag) => LiteralType::LangString(tag), }; - let lit = self.vocabulary.get_literal(&Literal::new(value, type_))?; + let lit = self + .vocabulary + .get_literal(Literal::new(value, type_).as_ref())?; self.interpretation.literal_interpretation(&lit) } } diff --git a/generators/rust/treeldr-rs/src/ser.rs b/generators/rust/treeldr-rs/src/ser/mod.rs similarity index 100% rename from generators/rust/treeldr-rs/src/ser.rs rename to generators/rust/treeldr-rs/src/ser/mod.rs diff --git a/layouts/examples/combine.rs b/layouts/examples/combine.rs index 553a3f3..c49681f 100644 --- a/layouts/examples/combine.rs +++ b/layouts/examples/combine.rs @@ -1,4 +1,4 @@ -use rdf_types::{dataset::BTreeDataset, BlankIdBuf, Id, RdfDisplay, Term}; +use rdf_types::{dataset::IndexedBTreeDataset, BlankIdBuf, Id, RdfDisplay, Term}; use serde_json::json; use treeldr_layouts::{ abs::{syntax::Layout, Builder}, @@ -108,7 +108,7 @@ fn main() { let mut generator = rdf_types::generator::Blank::new(); - let mut dataset = BTreeDataset::default(); + let mut dataset = IndexedBTreeDataset::default(); let (nested_dataset, _) = treeldr_layouts::distill::de::dehydrate( &layouts, &nested_json.into(), diff --git a/layouts/src/distill/de.rs b/layouts/src/distill/de.rs index 3af2150..5b6055f 100644 --- a/layouts/src/distill/de.rs +++ b/layouts/src/distill/de.rs @@ -238,6 +238,9 @@ impl Options { /// treeldr_layouts::distill::de::Options::default() /// ).unwrap(); /// +/// // Index the dataset so we can run queries on it. +/// let dataset = dataset.into_indexed(); +/// /// // The number of subjects is equal to the number of layout inputs. /// assert_eq!(subjects.len(), 1); /// diff --git a/layouts/src/distill/hy/data.rs b/layouts/src/distill/hy/data.rs index e41e7c8..5fbec3d 100644 --- a/layouts/src/distill/hy/data.rs +++ b/layouts/src/distill/hy/data.rs @@ -9,7 +9,7 @@ use iref::Iri; use rdf_types::{ dataset::{PatternMatchingDataset, TraversableDataset}, interpretation::{ReverseIriInterpretation, ReverseLiteralInterpretation}, - Interpretation, LiteralType, Vocabulary, + Interpretation, LiteralTypeRef, Vocabulary, }; use xsd_types::{lexical::Lexical, ParseXsd}; @@ -68,16 +68,15 @@ where for l in interpretation.literals_of(&resource) { let literal = vocabulary.literal(l).unwrap(); - let i = match &literal.type_ { - LiteralType::Any(i) => i, - LiteralType::LangString(_) => { + let i = match literal.type_ { + LiteralTypeRef::Any(i) => i, + LiteralTypeRef::LangString(_) => { todo!() // Lang string } }; if interpretation.iris_of(&layout.datatype).any(|j| i == j) { - let v = - hydrate_boolean_value(literal.value.as_ref(), vocabulary.iri(i).unwrap())?; + let v = hydrate_boolean_value(literal.value, vocabulary.iri(i).unwrap())?; if value.replace(v).is_some() { todo!() // Ambiguity @@ -112,16 +111,15 @@ where for l in interpretation.literals_of(&resource) { let literal = vocabulary.literal(l).unwrap(); - let i = match &literal.type_ { - LiteralType::Any(i) => i, - LiteralType::LangString(_) => { + let i = match literal.type_ { + LiteralTypeRef::Any(i) => i, + LiteralTypeRef::LangString(_) => { todo!() // Lang string } }; if interpretation.iris_of(&layout.datatype).any(|j| i == j) { - let v = - hydrate_number_value(literal.value.as_ref(), vocabulary.iri(i).unwrap())?; + let v = hydrate_number_value(literal.value, vocabulary.iri(i).unwrap())?; if value.replace(v).is_some() { todo!() // Ambiguity @@ -156,18 +154,15 @@ where for l in interpretation.literals_of(&resource) { let literal = vocabulary.literal(l).unwrap(); - let i = match &literal.type_ { - LiteralType::Any(i) => i, - LiteralType::LangString(_) => { + let i = match literal.type_ { + LiteralTypeRef::Any(i) => i, + LiteralTypeRef::LangString(_) => { todo!() // Lang string } }; if interpretation.iris_of(&layout.datatype).any(|j| i == j) { - let v = hydrate_byte_string_value( - literal.value.as_ref(), - vocabulary.iri(i).unwrap(), - )?; + let v = hydrate_byte_string_value(literal.value, vocabulary.iri(i).unwrap())?; if value.replace(v).is_some() { todo!() // Ambiguity @@ -202,18 +197,15 @@ where for l in interpretation.literals_of(&resource) { let literal = vocabulary.literal(l).unwrap(); - let i = match &literal.type_ { - LiteralType::Any(i) => i, - LiteralType::LangString(_) => { + let i = match literal.type_ { + LiteralTypeRef::Any(i) => i, + LiteralTypeRef::LangString(_) => { todo!() // Lang string } }; if interpretation.iris_of(&layout.datatype).any(|j| i == j) { - let v = hydrate_text_string_value( - literal.value.as_ref(), - vocabulary.iri(i).unwrap(), - )?; + let v = hydrate_text_string_value(literal.value, vocabulary.iri(i).unwrap())?; if value.replace(v).is_some() { todo!() // Ambiguity diff --git a/layouts/src/lib.rs b/layouts/src/lib.rs index caeef0f..b56d498 100644 --- a/layouts/src/lib.rs +++ b/layouts/src/lib.rs @@ -11,7 +11,7 @@ //! //! ``` //! use static_iref::iri; -//! use rdf_types::{Quad, Term, Literal, LiteralType, dataset::BTreeDataset}; +//! use rdf_types::{Quad, Term, Literal, LiteralType, dataset::IndexedBTreeDataset}; //! use xsd_types::XSD_STRING; //! use serde_json::json; //! @@ -44,7 +44,7 @@ //! let layouts = builder.build(); //! //! // Create an RDF dataset with a single triple. -//! let dataset: BTreeDataset = [ +//! let dataset: IndexedBTreeDataset = [ //! Quad( //! Term::iri(iri!("https://example.org/#john.smith").to_owned()), //! Term::iri(iri!("https://schema.org/name").to_owned()), diff --git a/layouts/src/value/cbor/mod.rs b/layouts/src/value/cbor/mod.rs index 6450c3d..87ef200 100644 --- a/layouts/src/value/cbor/mod.rs +++ b/layouts/src/value/cbor/mod.rs @@ -43,29 +43,29 @@ where { let layout = layouts.get(layout_ref).expect("missing layout definition"); match interpretation.lexical_iri_interpretation(vocabulary, CBOR_TAG_IRI) { - Some(prop) => match layout.extra_properties().get(&prop) { - Some(value) => { - for l in interpretation.literals_of(value) { - if let Some(literal) = vocabulary.literal(l) { - if let rdf_types::LiteralType::Any(ty) = &literal.type_ { - if let Some(ty_iri) = vocabulary.iri(ty) { - return match xsd_types::UnsignedLongDatatype::from_iri(ty_iri) { - Some(_) => literal - .value - .parse() - .map(Some) - .map_err(|_| InvalidTag::Value(literal.value.clone())), - None => Err(InvalidTag::Type(ty_iri.to_owned())), - }; + Some(prop) => { + match layout.extra_properties().get(&prop) { + Some(value) => { + for l in interpretation.literals_of(value) { + if let Some(literal) = vocabulary.literal(l) { + if let rdf_types::LiteralTypeRef::Any(ty) = literal.type_ { + if let Some(ty_iri) = vocabulary.iri(ty) { + return match xsd_types::UnsignedLongDatatype::from_iri(ty_iri) { + Some(_) => literal.value.parse().map(Some).map_err(|_| { + InvalidTag::Value(literal.value.to_owned()) + }), + None => Err(InvalidTag::Type(ty_iri.to_owned())), + }; + } } } } - } - Err(InvalidTag::NonLiteral) + Err(InvalidTag::NonLiteral) + } + None => Ok(None), } - None => Ok(None), - }, + } None => Ok(None), } } diff --git a/layouts/src/value/cbor/serde_cbor.rs b/layouts/src/value/cbor/serde_cbor.rs index 56e0107..d093f6e 100644 --- a/layouts/src/value/cbor/serde_cbor.rs +++ b/layouts/src/value/cbor/serde_cbor.rs @@ -163,7 +163,7 @@ mod tests { abs::{self, syntax}, hydrate, }; - use rdf_types::{dataset::BTreeDataset, BlankIdBuf, Literal, LiteralType, Quad, Term}; + use rdf_types::{dataset::IndexedBTreeDataset, BlankIdBuf, Literal, LiteralType, Quad, Term}; use serde_json::json; use static_iref::iri; use xsd_types::XSD_STRING; @@ -195,7 +195,7 @@ mod tests { let layout_ref = layout.build(&mut builder).unwrap(); let layouts = builder.build(); - let mut dataset = BTreeDataset::new(); + let mut dataset = IndexedBTreeDataset::new(); let subject = Term::blank(BlankIdBuf::from_suffix("subject").unwrap()); dataset.insert(Quad( subject.clone(), diff --git a/layouts/tests/distill.rs b/layouts/tests/distill.rs index 1e3d75e..61cd176 100644 --- a/layouts/tests/distill.rs +++ b/layouts/tests/distill.rs @@ -1,6 +1,6 @@ use nquads_syntax::Parse; use paste::paste; -use rdf_types::dataset::BTreeDataset; +use rdf_types::dataset::IndexedBTreeDataset; use rdf_types::{BlankIdBuf, Term}; use static_iref::iri; use std::fs; @@ -18,7 +18,7 @@ fn hydrate(id: &str, inputs: [Term; N]) { let output_path = file_path(id, "-out.json"); // Parse the input dataset from N-Quads. - let dataset: BTreeDataset = + let dataset: IndexedBTreeDataset = nquads_syntax::Document::parse_str(&std::fs::read_to_string(input_path).unwrap()) .unwrap() .into_value() @@ -65,7 +65,7 @@ fn dehydrate(id: &str, expected_values: [Term; N]) { let input: treeldr_layouts::Value = input_json.into(); // Parse the expected output dataset from N-Quads. - let expected_dataset: BTreeDataset = + let expected_dataset: IndexedBTreeDataset = nquads_syntax::Document::parse_str(&std::fs::read_to_string(output_path).unwrap()) .unwrap() .into_value()