Skip to content

Commit

Permalink
Merge pull request #86 from weso/issue83
Browse files Browse the repository at this point in the history
Solving issue #83 about oxigraph dependencies
  • Loading branch information
labra authored Aug 1, 2024
2 parents 18f0914 + 27df9bc commit f9a5d75
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ shacl_validation = { path = "./shacl_validation" }
shex_compact = { path = "./shex_compact" }
prefixmap = { path = "./prefixmap" }
shapemap = { path = "./shapemap" }
srdf = { path = "./srdf" }
srdf = { path = "./srdf", features = ["rdf-star"] }
iri_s = { path = "./iri_s" }
shacl_ast = { path = "./shacl_ast" }
shacl_ast = { path = "./shacl_ast", features = ["rdf-star"] }
dctap = { path = "./dctap" }
oxrdf = "0.2.0-alpha.2"
oxigraph = "0.3.22"
oxigraph = "0.4.0-alpha.7"
serde_json = "1.0"
regex = "1.10.4"
tracing = "0.1"
Expand Down
1 change: 1 addition & 0 deletions dctap/src/dctap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Person,PersonLabel,knows,knowsLabel
let dctap = DCTap::from_reader(data.as_bytes()).unwrap();
let mut expected_shape = TapShape::new();
expected_shape.set_shape_id(&ShapeId::new("Person"));
expected_shape.set_shape_label("PersonLabel");
let mut statement = TapStatement::new(PropertyId::new("knows"));
statement.set_property_label("knowsLabel");
expected_shape.add_statement(statement);
Expand Down
6 changes: 3 additions & 3 deletions dctap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ pub use crate::property_id::*;
pub use crate::shape_id::*;
pub use crate::tap_config::*;
pub use crate::tap_error::*;
pub(crate) use crate::tap_reader::*;
pub(crate) use crate::tap_reader_builder::*;
pub(crate) use crate::tap_reader_state::*;
pub use crate::tap_reader::*;
pub use crate::tap_reader_builder::*;
pub use crate::tap_reader_state::*;
pub use crate::tap_shape::*;
pub use crate::tap_statement::*;
pub use crate::value_constraint::*;
Expand Down
2 changes: 1 addition & 1 deletion dctap/src/tap_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use csv::StringRecord;
use tracing::debug;

#[derive(Debug, Default)]
pub(crate) struct TapHeaders {
pub struct TapHeaders {
shape_id: Option<usize>,
shape_label: Option<usize>,
property_id: Option<usize>,
Expand Down
8 changes: 6 additions & 2 deletions dctap/src/tap_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use csv::{Reader, StringRecord};
// use indexmap::IndexSet;
use std::io::{self};

pub(crate) struct TapReader<R> {
pub struct TapReader<R> {
reader: Reader<R>,
state: TapReaderState,
config: TapConfig,
Expand Down Expand Up @@ -308,7 +308,7 @@ fn get_strs(str: &str) -> impl Iterator<Item = &str> {
/// A borrowed iterator over Shapes
///
/// The lifetime parameter `'r` refers to the lifetime of the underlying `TapReader`.
pub(crate) struct ShapesIter<'r, R: 'r> {
pub struct ShapesIter<'r, R: 'r> {
reader: &'r mut TapReader<R>,
}

Expand Down Expand Up @@ -351,6 +351,7 @@ Person,PersonLabel,knows,KnowsLabel
TapReaderBuilder::from_reader(data.as_bytes(), &TapConfig::default()).unwrap();
let mut expected_shape = TapShape::new();
expected_shape.set_shape_id(&ShapeId::new("Person"));
expected_shape.set_shape_label("PersonLabel");
let mut statement = TapStatement::new(PropertyId::new("knows"));
statement.set_property_label("KnowsLabel");
expected_shape.add_statement(statement);
Expand All @@ -369,6 +370,7 @@ Person,PersonLabel,knows,KnowsLabel
TapReaderBuilder::from_reader(data.as_bytes(), &TapConfig::default()).unwrap();
let mut expected_shape = TapShape::new();
expected_shape.set_shape_id(&ShapeId::new("Person"));
expected_shape.set_shape_label("PersonLabel");
let mut statement = TapStatement::new(PropertyId::new("knows"));
statement.set_property_label("KnowsLabel");
expected_shape.add_statement(statement);
Expand All @@ -391,6 +393,7 @@ Company,CompanyLabel,founder,FounderLabel
TapReaderBuilder::from_reader(data.as_bytes(), &TapConfig::default()).unwrap();
let mut expected_shape1 = TapShape::new();
expected_shape1.set_shape_id(&ShapeId::new("Person"));
expected_shape1.set_shape_label("PersonLabel");
let mut statement = TapStatement::new(PropertyId::new("knows"));
statement.set_property_label("KnowsLabel");
expected_shape1.add_statement(statement);
Expand All @@ -402,6 +405,7 @@ Company,CompanyLabel,founder,FounderLabel

let mut expected_shape2 = TapShape::new();
expected_shape2.set_shape_id(&ShapeId::new("Company"));
expected_shape2.set_shape_label("CompanyLabel");
let mut statement = TapStatement::new(PropertyId::new("founder"));
statement.set_property_label("FounderLabel");
expected_shape2.add_statement(statement);
Expand Down
7 changes: 4 additions & 3 deletions dctap/src/tap_reader_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use std::io::{self};
use std::path::Path;

#[derive(Default)]
pub(crate) struct TapReaderBuilder {
pub struct TapReaderBuilder {
_reader_builder: ReaderBuilder,
}

impl TapReaderBuilder {
pub fn _new() -> TapReaderBuilder {
pub fn new() -> TapReaderBuilder {
TapReaderBuilder::default()
}
/*
Expand Down Expand Up @@ -47,11 +47,12 @@ impl TapReaderBuilder {
/// # Example
/// ```no_run
/// use dctap::TapReaderBuilder;
/// use dctap::TapConfig;
/// use std::error::Error;
///
/// # fn main() { example().unwrap(); }
/// fn example() -> Result<(), Box<dyn Error>> {
/// let mut tap = TapReaderBuilder::new().from_path("foo.csv")?;
/// let mut tap = TapReaderBuilder::from_path("foo.csv", &TapConfig::default())?;
/// for result in tap.shapes() {
/// let shape = result?;
/// println!("{:?}", shape);
Expand Down
8 changes: 7 additions & 1 deletion dctap/src/tap_reader_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::TapShape;
use csv::{Position, StringRecord};

#[derive(Debug)]
pub(crate) struct TapReaderState {
pub struct TapReaderState {
current_shape: TapShape,
cached_next_record: Option<StringRecord>,
headers: TapHeaders,
Expand Down Expand Up @@ -51,3 +51,9 @@ impl TapReaderState {
}
}
}

impl Default for TapReaderState {
fn default() -> Self {
Self::new()
}
}
6 changes: 3 additions & 3 deletions rdfsx_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ repository.workspace = true
[dependencies]
shex_ast = { path = "../shex_ast", version = "0.1.0" }
shex_validation = { path = "../shex_validation", version = "0.1.0" }
srdf = { path = "../srdf", version = "0.1.0" }
srdf = { path = "../srdf", version = "0.1.0", features = ["rdf-star"] }
prefixmap = { path = "../prefixmap", version = "0.1.0" }
iri_s = { path = "../iri_s", version = "0.1.5" }
shapemap = { path = "../shapemap", version = "0.1.0" }
shex_compact = { path = "../shex_compact", version = "0.1.0" }
shacl_ast = { path = "../shacl_ast", version = "0.1.0" }
shacl_ast = { path = "../shacl_ast", version = "0.1.0", features = ["rdf-star"] }
dctap = { path = "../dctap", version = "0.1.0" }
shapes_converter = { path = "../shapes_converter", version = "0.1.0" }
shacl_validation = { path = "../shacl_validation", version = "0.1.0" }
Expand All @@ -32,7 +32,7 @@ void = "1"
clap = { version = "4.2.1", features = ["derive"] }
oxrdf = "0.2.0-alpha.2"
oxiri = "0.2.3-alpha.1"
oxigraph = "0.3.22"
oxigraph = "0.4.0-alpha.7"
regex = "^1.10"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = [ "env-filter" ] }
2 changes: 1 addition & 1 deletion rdfsx_cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{Parser, Subcommand, ValueEnum};
use oxigraph::io::GraphFormat;
use oxigraph::io::RdfFormat as GraphFormat;
use srdf::RDFFormat;
use std::convert::TryFrom;
use std::fmt::Display;
Expand Down
19 changes: 11 additions & 8 deletions rdfsx_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern crate tracing_subscriber;
use anyhow::*;
use clap::Parser;
use dctap::{DCTap, TapConfig};
use oxigraph::model::GraphNameRef;
use oxigraph::io::RdfParser;
use oxigraph::store::Store;
use prefixmap::IriRef;
use shacl_ast::{Schema as ShaclSchema, ShaclParser, ShaclWriter};
Expand All @@ -39,7 +39,7 @@ use srdf::srdf_sparql::SRDFSparql;
use srdf::SRDF;
use std::convert::TryInto;
use std::fs::File;
use std::io::{self, BufReader, BufWriter, Write};
use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::result::Result::Ok;
use std::str::FromStr;
Expand Down Expand Up @@ -380,12 +380,15 @@ fn run_validate_shacl(
}?;
if let Ok(data_format) = data_format.to_owned().try_into() {
let store = Store::new()?;
store.bulk_loader().load_graph(
BufReader::new(File::open(path)?),
data_format,
GraphNameRef::DefaultGraph,
None,
)?;
let parser = RdfParser::from_format(data_format);
let fp = match File::open(path) {
Ok(fp) => fp,
Err(error) => {
eprintln!("Error while opening file {}: {}", path.display(), error);
return Ok(());
}
};
store.bulk_loader().load_from_read(parser, fp)?;
let mut writer = get_writer(output)?;
let validate = validate(&store, shacl_schema);
match validate {
Expand Down
3 changes: 3 additions & 0 deletions shacl_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[features]
rdf-star = ["oxrdf/rdf-star"]

[dependencies]
srdf = { path = "../srdf", version = "0.1.0" }
iri_s = { path = "../iri_s", version = "0.1.5" }
Expand Down
2 changes: 2 additions & 0 deletions shacl_ast/src/ast/property_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ impl PropertyShape {
}
OxTerm::BlankNode(node) => RDFNode::bnode(node.to_string()),
OxTerm::Literal(literal) => RDFNode::literal(literal.into()),
#[cfg(feature = "rdf-star")]
OxTerm::Triple(_) => unimplemented!(),
})
.collect::<HashSet<RDFNode>>()
} else {
Expand Down
2 changes: 1 addition & 1 deletion shacl_testsuite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ clap = { version = "4.2.1", features = ["derive"] }
const_format = "0.2"

oxiri = "0.2"
oxigraph = "0.3.22"
oxigraph = "0.4.0-alpha.7"
indoc = "2"
10 changes: 7 additions & 3 deletions shacl_testsuite/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::Path;
use std::str::FromStr;

use indoc::formatdoc;
use oxigraph::io::GraphFormat;
use oxigraph::io::RdfFormat;
use oxigraph::model::{GraphNameRef, NamedNode};
use oxigraph::{model::Term, store::Store};
use oxiri::Iri;
Expand Down Expand Up @@ -35,6 +35,8 @@ impl Manifest {
}
}

// TODO: Change load_graph by load_from_read
#[allow(deprecated)]
pub fn collect_tests(&self) -> Result<Vec<ShaclTest>, ManifestError> {
let mut ans = Vec::new();
for entry in &self.entries {
Expand Down Expand Up @@ -123,7 +125,7 @@ impl Manifest {
data_store = Store::new()?;
data_store.bulk_loader().load_graph(
BufReader::new(File::open(path.replace("file:/", ""))?),
GraphFormat::Turtle,
RdfFormat::Turtle,
GraphNameRef::DefaultGraph,
Some(&self.base),
)?;
Expand All @@ -141,6 +143,8 @@ impl Manifest {
Ok(ans)
}

// TODO: Change load_graph by load_from_read
#[allow(deprecated)]
pub fn load(file: &str) -> Result<Manifest, ManifestError> {
let path = Path::new(file);

Expand All @@ -153,7 +157,7 @@ impl Manifest {

store.bulk_loader().load_graph(
BufReader::new(File::open(path)?),
GraphFormat::Turtle,
RdfFormat::Turtle,
GraphNameRef::DefaultGraph,
Some(&base),
)?;
Expand Down
2 changes: 1 addition & 1 deletion shacl_validation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ thiserror = "1.0.63"
lazy_static = "1"
const_format = "0.2"

oxigraph = "0.3.22"
oxigraph = "0.4.0-alpha.7"
indoc = "2"
3 changes: 3 additions & 0 deletions srdf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[features]
rdf-star = ["oxrdf/rdf-star"]

[dependencies]
iri_s = { path = "../iri_s", version = "0.1.5" }
prefixmap = { path = "../prefixmap", version = "0.1.0" }
Expand Down
16 changes: 8 additions & 8 deletions srdf/src/srdf_graph/srdfgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ impl SRDFBasic for SRDFGraph {
match subject {
OxSubject::NamedNode(n) => OxTerm::NamedNode(n.clone()),
OxSubject::BlankNode(b) => OxTerm::BlankNode(b.clone()),
// #[cfg(feature = "rdf-star")]
// _ => unimplemented!(),
#[cfg(feature = "rdf-star")]
OxSubject::Triple(_) => unimplemented!(),
}
}

Expand Down Expand Up @@ -263,8 +263,8 @@ impl SRDFBasic for SRDFGraph {
}
}
OxTerm::NamedNode(iri) => Object::Iri(Self::iri2iri_s(iri)),
// #[cfg(feature = "rdf-star")]
// _ => unimplemented!(),
#[cfg(feature = "rdf-star")]
OxTerm::Triple(_) => unimplemented!(),
}
}

Expand All @@ -282,8 +282,8 @@ impl SRDFBasic for SRDFGraph {
match subj {
OxSubject::BlankNode(bn) => self.show_blanknode(bn),
OxSubject::NamedNode(n) => self.qualify_iri(n),
// #[cfg(feature = "rdf-star")]
// _ => unimplemented!(),
#[cfg(feature = "rdf-star")]
OxSubject::Triple(_) => unimplemented!(),
}
}

Expand All @@ -292,8 +292,8 @@ impl SRDFBasic for SRDFGraph {
OxTerm::BlankNode(bn) => self.show_blanknode(bn),
OxTerm::Literal(lit) => self.show_literal(lit),
OxTerm::NamedNode(n) => self.qualify_iri(n),
// #[cfg(feature = "rdf-star")]
// _ => unimplemented!(),
#[cfg(feature = "rdf-star")]
OxTerm::Triple(_) => unimplemented!(),
}
}

Expand Down
12 changes: 10 additions & 2 deletions srdf/src/srdf_sparql/srdfsparql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ impl SRDFBasic for SRDFSparql {
}
},
Self::Term::NamedNode(iri) => Object::Iri(Self::iri2iri_s(iri)),

#[cfg(feature = "rdf-star")]
OxTerm::Triple(_) => unimplemented!(),
}
}

Expand All @@ -220,6 +223,8 @@ impl SRDFBasic for SRDFSparql {
match subj {
OxSubject::BlankNode(bn) => self.show_blanknode(bn),
OxSubject::NamedNode(n) => self.qualify_iri(n),
#[cfg(feature = "rdf-star")]
OxSubject::Triple(_) => unimplemented!(),
}
}

Expand All @@ -228,6 +233,8 @@ impl SRDFBasic for SRDFSparql {
OxTerm::BlankNode(bn) => self.show_blanknode(bn),
OxTerm::Literal(lit) => self.show_literal(lit),
OxTerm::NamedNode(n) => self.qualify_iri(n),
#[cfg(feature = "rdf-star")]
OxTerm::Triple(_) => unimplemented!(),
}
}

Expand Down Expand Up @@ -623,8 +630,9 @@ fn subject_as_term(subject: &OxSubject) -> OxTerm {
match subject {
OxSubject::NamedNode(n) => OxTerm::NamedNode(n.clone()),
OxSubject::BlankNode(b) => OxTerm::BlankNode(b.clone()),
// #[cfg(feature = "rdf-star")]
// _ => unimplemented!(),
#[cfg(feature = "rdf-star")]
#[cfg(feature = "rdf-star")]
OxSubject::Triple(_) => unimplemented!(),
}
}

Expand Down

0 comments on commit f9a5d75

Please sign in to comment.