diff --git a/Cargo.lock b/Cargo.lock index eeaa11d7..17185a0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1165,9 +1165,9 @@ dependencies = [ [[package]] name = "mownstr" -version = "0.1.3" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76aacdf8f9850a9db34e33e35abfc17a29b9577d0eb2cbfaeb734662cacca5b3" +checksum = "8bc45ce96192b5d8b20cffb10ccd85cc431c283a7d171a0d843ac0bd7d444598" [[package]] name = "nix" @@ -1585,15 +1585,9 @@ dependencies = [ [[package]] name = "resiter" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd69ab1e90258b7769f0b5c46bfd802b8206d0707ced4ca4b9d5681b744de1be" - -[[package]] -name = "rio_api" -version = "0.6.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed96d73ad4e0de59e667b26c899930c90912cad3fec5f0291fc3171c90dacae" +checksum = "cbc95d56eb1865f69288945759cc0879d60ee68168dce676730275804ad2b276" [[package]] name = "rio_api" @@ -1601,17 +1595,6 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1924fa1f0e6d851f9b73b3c569e607c368a0d92995d99d563ad7bf1414696603" -[[package]] -name = "rio_turtle" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1945ea5cf5f489bd2cbafeb705686abdc94edfa9dd88a63a25e8c5c0d38f9cc2" -dependencies = [ - "oxilangtag", - "oxiri", - "rio_api 0.6.2", -] - [[package]] name = "rio_turtle" version = "0.8.4" @@ -1620,7 +1603,7 @@ checksum = "5cec59971eafd99b9c7e3544bfcabafea81a7072ac51c9f46985ca0bd7ba6016" dependencies = [ "oxilangtag", "oxiri", - "rio_api 0.8.4", + "rio_api", ] [[package]] @@ -1632,7 +1615,7 @@ dependencies = [ "oxilangtag", "oxiri", "quick-xml", - "rio_api 0.8.4", + "rio_api", ] [[package]] @@ -1703,8 +1686,8 @@ dependencies = [ name = "serde-rdf" version = "2.0.0" dependencies = [ - "rio_api 0.8.4", - "rio_turtle 0.8.4", + "rio_api", + "rio_turtle", "rio_xml", "serde", ] @@ -1878,15 +1861,16 @@ dependencies = [ [[package]] name = "sophia" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "044d2d79633c0413a3cdb5b3cdd6f18b2d6a7f0d76cb75d3251ff92a83c4f55d" +checksum = "0d9d3e79754eeda3fc7e3610afcc492613fa0a5581d286d7545094e3e7ce1608" dependencies = [ - "resiter", "sophia_api", - "sophia_indexed", + "sophia_c14n", "sophia_inmem", "sophia_iri", + "sophia_isomorphism", + "sophia_resource", "sophia_rio", "sophia_term", "sophia_turtle", @@ -1894,95 +1878,110 @@ dependencies = [ [[package]] name = "sophia_api" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aad03aad8253bd0f7c5423da4a1aaf4b18e5856b40e8841063ba5226cebc5efb" +checksum = "2e41b1197b9dbd2e5e2a7d8dc62fd6bab001724576463831920b13567bde2a4c" dependencies = [ "lazy_static", "mownstr", "regex", "resiter", + "serde", "sophia_iri", "thiserror", ] [[package]] -name = "sophia_indexed" -version = "0.7.2" +name = "sophia_c14n" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8385acd3ff5e36a22fe4f6d308a10a66b87bbb437bcab096c1d88d522b05ece" +checksum = "04e4ebf65104879fc9f3f1f54224b42ad1f9e40b6a5dc26c5a17bf43846d6a1d" dependencies = [ + "sha2", "sophia_api", - "sophia_term", + "sophia_iri", + "thiserror", ] [[package]] name = "sophia_inmem" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28f09086332b823c4d8fa2365987cf881f1c6a9b139991db78c09729a5a3442c" +checksum = "ba3f836b898bbd5d5a73a977995e1d5dab8e2cf96a017890954864ece18b1e8c" dependencies = [ "sophia_api", - "sophia_indexed", - "sophia_term", + "thiserror", ] [[package]] name = "sophia_iri" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecf2b1953a03e53c8cbfb029646be5b75c7e3a83cde8ef16ffe185c471093437" +checksum = "bb62d2fcd10fc3a44b646b1893ad478df0cb771f7ceb0331a5f3cee25f37ba7e" dependencies = [ "lazy_static", - "mownstr", + "oxiri", "regex", + "serde", + "thiserror", +] + +[[package]] +name = "sophia_isomorphism" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b3876c71756d3dd94590c51090a036298a983f6b1e5c316f9eca514b2f6a5e" +dependencies = [ + "sophia_api", + "sophia_iri", +] + +[[package]] +name = "sophia_resource" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "807253d3a4144e1f3eacf6976849dab04cbd493ff568414df07c33fd10886ce2" +dependencies = [ + "sophia_api", + "sophia_iri", + "sophia_turtle", "thiserror", ] [[package]] name = "sophia_rio" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcd2f32812619d11e0c531ce35f6d2704fa354dec97ca4072872744d042311" +checksum = "93e107086ca2b3e329dbe0f85f9ce504b1fbb478c85341338942b9dff613d4d8" dependencies = [ - "rio_api 0.6.2", + "rio_api", "sophia_api", + "sophia_iri", ] [[package]] name = "sophia_term" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d21426110f6c45ba6f6a0f5354b4d201cc42a00d2550f7c7ca26e6d6ba89490" +checksum = "ca3a77f8523038dc1204a59dd461f27322cbe14bea3da873d41b6cc40c3e63e9" dependencies = [ "lazy_static", - "mownstr", - "oxilangtag", - "regex", "sophia_api", - "sophia_iri", - "thiserror", - "weak-table", ] [[package]] name = "sophia_turtle" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d31f4522a1fb3a49144c20f3cce6a00e1d6c33b5552c0338311868cbb62c7f5d" +checksum = "4a7b7ce7aeb34f55867599544622420b2a6b6488b16811e06fd3755fc9cae4d0" dependencies = [ "lazy_static", "oxiri", "regex", - "rio_api 0.6.2", - "rio_turtle 0.6.2", + "rio_turtle", "sophia_api", - "sophia_indexed", - "sophia_inmem", "sophia_iri", "sophia_rio", - "sophia_term", - "thiserror", ] [[package]] @@ -2547,12 +2546,6 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" -[[package]] -name = "weak-table" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "323f4da9523e9a669e1eaf9c6e763892769b1d38c623913647bfdc1532fe4549" - [[package]] name = "winapi" version = "0.3.9" diff --git a/dsp-meta/Cargo.toml b/dsp-meta/Cargo.toml index 18f72749..8ba2e030 100644 --- a/dsp-meta/Cargo.toml +++ b/dsp-meta/Cargo.toml @@ -31,7 +31,7 @@ serde_yaml.workspace = true nonempty.workspace = true valico.workspace = true regex.workspace = true -sophia = "0.7.2" +sophia = "0.8.0" tokio.workspace = true tower.workspace = true tower-http.workspace = true diff --git a/dsp-meta/src/api/convert/rdf/error.rs b/dsp-meta/src/api/convert/rdf/error.rs index 86c12584..bd014cc4 100644 --- a/dsp-meta/src/api/convert/rdf/error.rs +++ b/dsp-meta/src/api/convert/rdf/error.rs @@ -1,13 +1,7 @@ use crate::error::DspMetaError; -impl From for DspMetaError { - fn from(error: sophia::iri::error::InvalidIri) -> Self { +impl From for DspMetaError { + fn from(error: sophia::iri::InvalidIri) -> Self { DspMetaError::SerializeToRdf(error.0) } } - -impl From for DspMetaError { - fn from(error: sophia::term::TermError) -> Self { - DspMetaError::SerializeToRdf(error.to_string()) - } -} diff --git a/dsp-meta/src/api/convert/rdf/project.rs b/dsp-meta/src/api/convert/rdf/project.rs index 7dbb382c..45481f90 100644 --- a/dsp-meta/src/api/convert/rdf/project.rs +++ b/dsp-meta/src/api/convert/rdf/project.rs @@ -1,10 +1,10 @@ // placeholder for project use dsp_domain::metadata::entity::project::Project; -use sophia::graph::inmem::LightGraph; -use sophia::graph::{Graph, MutableGraph}; -use sophia::ns::{rdf, Namespace}; -use sophia::term::SimpleIri; +use sophia::api::graph::{Graph, MutableGraph}; +use sophia::api::ns::{rdf, Namespace}; +use sophia::inmem::graph::LightGraph; +use sophia::iri::Iri; use crate::api::convert::rdf::constance::DSP_NAMESPACE_STRING; use crate::api::convert::rdf::value::shortcode::ShortcodeGraphDto; @@ -15,17 +15,21 @@ impl ProjectGraphDto { let mut graph = LightGraph::new(); // http://ns.dasch.swiss/repository#dsp-081C-project a http://ns.dasch.swiss/repository#Project - let dsp = Namespace::new_unchecked(DSP_NAMESPACE_STRING); - let project_iri_suffix = format!("dsp-{}-project", self.0.shortcode.0); - let project_iri = SimpleIri::new_unchecked(dsp.as_ref(), Some(project_iri_suffix.as_str())); - let project_class = SimpleIri::new_unchecked(dsp.as_ref(), Some("Project")); + let ns = Namespace::new_unchecked(DSP_NAMESPACE_STRING); - let shortcode_graph = ShortcodeGraphDto(&self.0.shortcode).to_graph(&project_iri); + let project_iri = ns + .get(format!("{}dsp-{}-project", ns.as_str(), self.0.shortcode.0).as_str()) + .expect("project_iri creation failed.") + .to_string(); + let project_iri = Iri::new(project_iri).expect("project_iri creation failed."); + + let project_class = ns.get("Project").expect("project_class creation failed."); graph - .insert(&project_iri, &rdf::type_, &project_class) + .insert(&project_iri, rdf::type_, project_class) .expect("insert of project triples into graph failed."); + let shortcode_graph = ShortcodeGraphDto(&self.0.shortcode).to_graph(&project_iri); graph .insert_all(shortcode_graph.triples()) .expect("insert of project triples into graph failed."); diff --git a/dsp-meta/src/api/convert/rdf/project_metadata.rs b/dsp-meta/src/api/convert/rdf/project_metadata.rs index d950080c..f5dbfe4b 100644 --- a/dsp-meta/src/api/convert/rdf/project_metadata.rs +++ b/dsp-meta/src/api/convert/rdf/project_metadata.rs @@ -1,18 +1,17 @@ use dsp_domain::metadata::entity::project_metadata::ProjectMetadata; -use sophia::graph::inmem::LightGraph; -use sophia::graph::*; -use sophia::iri::IriBox; -use sophia::ns::Namespace; -use sophia::prefix::PrefixBox; -use sophia::serializer::turtle::{TurtleConfig, TurtleSerializer}; -use sophia::serializer::*; +use sophia::api::ns::Namespace; +use sophia::api::prefix::{Prefix, PrefixMapPair}; +use sophia::api::prelude::Stringifier; +use sophia::api::serializer::TripleSerializer; +use sophia::inmem::graph::LightGraph; +use sophia::iri::Iri; +use sophia::turtle::serializer::turtle::{TurtleConfig, TurtleSerializer}; use tracing::trace; use crate::api::convert::rdf::constance::{ DSP_NAMESPACE_STRING, PROV_NAMESPACE_STRING, SCHEMA_NAMESPACE_STRING, XSD_NAMESPACE_STRING, }; use crate::api::convert::rdf::project::ProjectGraphDto; - pub struct ProjectMetadataGraph { graph: LightGraph, } @@ -79,41 +78,41 @@ impl ProjectMetadataGraph { /// sdo:url "https://admin.dasch.swiss/project/081C" ] . /// ``` pub fn to_turtle_string(&self) -> String { - let prefix_map = vec![ + let prefix_map: Vec = vec![ ( - PrefixBox::new_unchecked("dsp".into()), - IriBox::new_unchecked("http://ns.dasch.swiss/repository#".into()), + Prefix::new_unchecked("dsp".into()), + Iri::new_unchecked("http://ns.dasch.swiss/repository#".into()), ), ( - PrefixBox::new_unchecked("prov".into()), - IriBox::new_unchecked("http://www.w3.org/ns/prov#".into()), + Prefix::new_unchecked("prov".into()), + Iri::new_unchecked("http://www.w3.org/ns/prov#".into()), ), ( - PrefixBox::new_unchecked("sdo".into()), - IriBox::new_unchecked("https://schema.org/".into()), + Prefix::new_unchecked("sdo".into()), + Iri::new_unchecked("https://schema.org/".into()), ), ( - PrefixBox::new_unchecked("rdf".into()), - IriBox::new_unchecked("http://www.w3.org/1999/02/22-rdf-syntax-ns#".into()), + Prefix::new_unchecked("rdf".into()), + Iri::new_unchecked("http://www.w3.org/1999/02/22-rdf-syntax-ns#".into()), ), ( - PrefixBox::new_unchecked("rdfs".into()), - IriBox::new_unchecked("http://www.w3.org/2000/01/rdf-schema#".into()), + Prefix::new_unchecked("rdfs".into()), + Iri::new_unchecked("http://www.w3.org/2000/01/rdf-schema#".into()), ), ( - PrefixBox::new_unchecked("xsd".into()), - IriBox::new_unchecked("http://www.w3.org/2001/XMLSchema#".into()), + Prefix::new_unchecked("xsd".into()), + Iri::new_unchecked("http://www.w3.org/2001/XMLSchema#".into()), ), ]; let config = TurtleConfig::new() .with_pretty(true) .with_own_prefix_map(prefix_map); - let out = TurtleSerializer::new_stringifier_with_config(config) + let mut serializer = TurtleSerializer::new_stringifier_with_config(config); + let out = serializer .serialize_graph(&self.graph) .expect("Error serializing graph to turtle.") .to_string(); - out } } @@ -138,14 +137,7 @@ impl From for ProjectMetadataGraph { let _xsd = Namespace::new_unchecked(XSD_NAMESPACE_STRING); - let mut graph: LightGraph = LightGraph::new(); - - let project_graph = ProjectGraphDto(value.0.project).to_graph(); - - graph - .insert_all(project_graph.triples()) - .expect("insert of project triples into project metadata graph failed"); - + let graph = ProjectGraphDto(value.0.project).to_graph(); let result = ProjectMetadataGraph { graph }; trace!("The resulting graph\n{}", result.to_turtle_string()); diff --git a/dsp-meta/src/api/convert/rdf/value/shortcode.rs b/dsp-meta/src/api/convert/rdf/value/shortcode.rs index 9938fd4a..6823004c 100644 --- a/dsp-meta/src/api/convert/rdf/value/shortcode.rs +++ b/dsp-meta/src/api/convert/rdf/value/shortcode.rs @@ -1,28 +1,26 @@ use dsp_domain::metadata::value::Shortcode; -use sophia::graph::inmem::LightGraph; -use sophia::graph::MutableGraph; -use sophia::ns::Namespace; -use sophia::term::literal::Literal; -use sophia::term::SimpleIri; +use sophia::api::graph::MutableGraph; +use sophia::api::ns::Namespace; +use sophia::inmem::graph::LightGraph; +use sophia::iri::Iri; pub(crate) struct ShortcodeGraphDto<'a>(pub &'a Shortcode); impl<'a> ShortcodeGraphDto<'a> { - pub fn to_graph(&self, project_iri: &SimpleIri) -> LightGraph { - let mut graph: LightGraph = LightGraph::new(); - + pub fn to_graph(&self, project_iri: &Iri) -> LightGraph { // http://ns.dasch.swiss/repository#dsp-081C-project http://ns.dasch.swiss/repository#hasShortcode "081C"^^http://www.w3.org/2001/XMLSchema#string let dsp = Namespace::new_unchecked("http://ns.dasch.swiss/repository#"); - let has_shortcode_property = SimpleIri::new_unchecked(dsp.as_ref(), Some("hasShortcode")); - graph - .insert( - project_iri, - &has_shortcode_property, - &Literal::::new_lang_unchecked(&self.0.as_string(), "en"), - ) - .expect("insert of shortcode triples into graph failed."); + let has_shortcode = dsp + .get("hasShortcode") + .expect("has_shortcode_property creation failed."); + // mutating the graph + let mut graph: LightGraph = LightGraph::new(); + + graph + .insert(project_iri, has_shortcode, self.0.as_string().as_str()) + .expect("triple inserted"); graph } }