Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
angelip2303 committed Jan 21, 2025
1 parent 33fe842 commit 1c1ab52
Show file tree
Hide file tree
Showing 22 changed files with 370 additions and 340 deletions.
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,19 @@ shacl_validation = { version = "*", path = "./shacl_validation" }
# shex_validation = { version = "0.1.0", path = "./shex_validation" }
# shex_compact = { version = "0.1.0", path = "./shex_compact" }
srdf = { version = "*", path = "./srdf" }
sparql_service = { version = "0.1.37", path = "./sparql_service" }
sparql_service = { version = "*", path = "./sparql_service" }

# External dependencies
anyhow = "1.0"
clap = { version = "4.5.21", features = ["derive"] }
colored = "2"
clap = { version = "4.5.23", features = ["derive"] }
colored = "2.2.0"
indexmap = { version = "2", features = ["serde"] }
regex = "1.10.4"
supports-color = "3.0.0"
serde = "1.0.215"
serde = "1.0.216"
serde_json = "1.0"
serde_derive = "1.0.215"
serde_derive = "1.0.216"
serde_yml = "0.0.12"
thiserror = "2.0.3"
thiserror = "2.0.8"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
lazy_static = "1"
Expand Down
4 changes: 2 additions & 2 deletions shacl_validation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shacl_validation"
version = "0.1.52"
version = "0.1.58"
readme = "README.md"
license.workspace = true
authors.workspace = true
Expand Down Expand Up @@ -30,5 +30,5 @@ const_format = "0.2" # needed for the definition of the vocab
indoc = "2" # needed for the definition of SPARQL queries

[dev-dependencies] # necessary for the tests
# sparql_service = { workspace = true }
sparql_service = { workspace = true }
oxrdf = { workspace = true }
6 changes: 3 additions & 3 deletions shacl_validation/src/engine/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<R: Rdf + Clone + 'static> Engine<R> for NativeEngine {
.inner_store()
.triples_matching(None, Some(&rdf_type), Some(class))
{
Ok(subjects) => subjects.map(Triple::subj).map(Clone::clone).map(Into::into),
Ok(subjects) => subjects.map(Triple::into_subject).map(Into::into),
Err(_) => return Err(ValidateError::SRDF),
};

Expand All @@ -78,7 +78,7 @@ impl<R: Rdf + Clone + 'static> Engine<R> for NativeEngine {
predicate: &Predicate<R>,
) -> Result<FocusNodes<R>, ValidateError> {
let triples = match store.inner_store().triples_with_predicate(predicate) {
Ok(triples) => triples.map(Triple::subj).map(Clone::clone).map(Into::into),
Ok(triples) => triples.map(Triple::into_subject).map(Into::into),
Err(_) => return Err(ValidateError::SRDF),
};

Expand All @@ -91,7 +91,7 @@ impl<R: Rdf + Clone + 'static> Engine<R> for NativeEngine {
predicate: &Predicate<R>,
) -> Result<FocusNodes<R>, ValidateError> {
let triples = match store.inner_store().triples_with_predicate(predicate) {
Ok(triples) => triples.map(Triple::obj).map(Clone::clone).map(Into::into),
Ok(triples) => triples.map(Triple::into_object).map(Into::into),
Err(_) => return Err(ValidateError::SRDF),
};

Expand Down
2 changes: 1 addition & 1 deletion shacl_validation/src/helpers/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn validate_sparql_ask<R: Rdf + Sparql + Clone>(
shape,
value_nodes,
ValueNodeIteration,
|value_node| match store.inner_store().ask(&query(value_node)) {
|value_node| match store.inner_store().ask(query(value_node)) {
Ok(ask) => Ok(!ask),
Err(err) => Err(ConstraintError::Query(format!("ASK query failed: {}", err))),
},
Expand Down
4 changes: 2 additions & 2 deletions shacl_validation/src/helpers/sparql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ pub fn select<S: Rdf + Sparql>(
index: &str,
) -> Result<HashSet<Object<S>>, SPARQLError> {
let mut ans = HashSet::new();
let query = match store.select(&query_str) {
let query = match store.select(query_str.clone()) {
Ok(ans) => ans,
Err(e) => {
return Err(SPARQLError::Query {
query: query_str.to_string(),
query: query_str,
error: format!("{e}"),
})
}
Expand Down
8 changes: 2 additions & 6 deletions shacl_validation/src/helpers/srdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) fn get_objects_for<R: Rdf>(
};

let ans = match store.triples_matching(Some(&subject), Some(predicate), None) {
Ok(triples) => Ok(triples.map(Triple::obj).map(Clone::clone).collect()),
Ok(triples) => Ok(triples.map(Triple::into_object).collect()),
Err(e) => Err(SRDFError::ObjectsWithSubjectPredicate {
predicate: format!("{predicate}"),
subject: format!("{subject}"),
Expand All @@ -53,11 +53,7 @@ pub(crate) fn get_subjects_for<R: Rdf>(
object: &Object<R>,
) -> Result<HashSet<Object<R>>, SRDFError> {
let ans = match store.triples_matching(None, Some(predicate), Some(object)) {
Ok(triples) => Ok(triples
.map(Triple::subj)
.map(Clone::clone)
.map(Into::into)
.collect()),
Ok(triples) => Ok(triples.map(Triple::into_subject).map(Into::into).collect()),
Err(e) => Err(SRDFError::SubjectsWithPredicateObject {
predicate: format!("{predicate}"),
object: format!("{object}"),
Expand Down
7 changes: 4 additions & 3 deletions shacl_validation/src/validation_report/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use shacl_ast::vocab::SH_RESULT;
use srdf::model::rdf::Object;
use srdf::model::rdf::Predicate;
use srdf::model::rdf::Rdf;
use srdf::model::BlankNode;
use srdf::model::Iri;
use srdf::model::Term;

Expand Down Expand Up @@ -164,7 +165,7 @@ impl<R: Rdf> Display for ValidationReport<R> {
fn show_node<R: Rdf>(node: &Object<R>, prefixmap: &PrefixMap) -> String {
match (node.is_iri(), node.is_blank_node(), node.is_literal()) {
(true, false, false) => prefixmap.qualify(&node.iri().unwrap().into_iri_s()),
(false, true, false) => format!("_:{}", node.blank_node().unwrap().to_string()),
(false, true, false) => format!("_:{}", node.blank_node().unwrap().label()),
(false, false, true) => format!("{}", node.literal().unwrap()),
_ => unreachable!(),
}
Expand All @@ -177,7 +178,7 @@ fn show_component<R: Rdf>(component: &Object<R>, shacl_prefixmap: &PrefixMap) ->
component.is_literal(),
) {
(true, false, false) => shacl_prefixmap.qualify(&component.iri().unwrap().into_iri_s()),
(false, true, false) => format!("_:{}", component.blank_node().unwrap().to_string()),
(false, true, false) => format!("_:{}", component.blank_node().unwrap().label()),
(false, false, true) => format!("{}", component.literal().unwrap()),
_ => unreachable!(),
}
Expand All @@ -190,7 +191,7 @@ fn show_severity<R: Rdf>(severity: &Object<R>, shacl_prefixmap: &PrefixMap) -> S
severity.is_literal(),
) {
(true, false, false) => shacl_prefixmap.qualify(&severity.iri().unwrap().into_iri_s()),
(false, true, false) => format!("_:{}", severity.blank_node().unwrap().to_string()),
(false, true, false) => format!("_:{}", severity.blank_node().unwrap().label()),
(false, false, true) => format!("{}", severity.literal().unwrap()),
_ => unreachable!(),
}
Expand Down
9 changes: 5 additions & 4 deletions sparql_service/src/query_config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{io, path::Path};
use std::io;
use std::path::Path;

use serde_derive::Deserialize;
use serde_derive::Serialize;
use thiserror::Error;

use serde_derive::{Deserialize, Serialize};

use srdf::RdfDataConfig;
use crate::data_config::RdfDataConfig;

/// This struct can be used to define configuration of RDF data readers
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
Expand Down
6 changes: 1 addition & 5 deletions sparql_service/src/query_processor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use prefixmap::PrefixMap;
use srdf::{QuerySolutions, Rdf};
use srdf::model::rdf::Rdf;

Check warning on line 2 in sparql_service/src/query_processor.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `srdf::model::rdf::Rdf`

Check warning on line 2 in sparql_service/src/query_processor.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `srdf::model::rdf::Rdf`

use crate::RdfData;

Expand All @@ -18,8 +18,4 @@ impl QueryProcessor {
pub fn prefix_map(&self) -> Option<PrefixMap> {
Some(self.rdf_data.prefixmap_in_memory())
}

pub fn query_select<S: Rdf>(_str: &str) -> QuerySolutions<S> {
todo!()
}
}
9 changes: 6 additions & 3 deletions sparql_service/src/service_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use std::{fmt::Display, io::BufRead, path::Path};

use iri_s::IriS;
use itertools::Itertools;
use srdf::{GenericGraph, RDFFormat, ReaderMode};
use srdf::{
model::{reader::ReaderMode, RdfFormat},
oxgraph::GenericGraph,
};

use crate::{ServiceDescriptionError, ServiceDescriptionParser};

Expand Down Expand Up @@ -154,7 +157,7 @@ impl ServiceDescription {

pub fn from_path<P: AsRef<Path>>(
path: P,
format: &RDFFormat,
format: &RdfFormat,
base: Option<&str>,
reader_mode: &ReaderMode,
) -> Result<ServiceDescription, ServiceDescriptionError> {
Expand All @@ -166,7 +169,7 @@ impl ServiceDescription {

pub fn from_reader<R: BufRead>(
read: R,
format: &RDFFormat,
format: &RdfFormat,
base: Option<&str>,
reader_mode: &ReaderMode,
) -> Result<ServiceDescription, ServiceDescriptionError> {
Expand Down
5 changes: 3 additions & 2 deletions sparql_service/src/service_description_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use srdf::{RdfParseError, SRDFGraphError};
use srdf::oxgraph_error::GraphError;
use srdf::RdfParseError;
use thiserror::Error;

#[derive(Error, Debug)]
Expand All @@ -15,6 +16,6 @@ pub enum ServiceDescriptionError {
#[error(transparent)]
SRDFGraphError {
#[from]
error: SRDFGraphError,
error: GraphError,
},
}
22 changes: 12 additions & 10 deletions sparql_service/src/service_description_parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use iri_s::IriS;
use srdf::{ok, property_iri, property_values_iri, FocusRDF, PResult, RDFNodeParse, RDFParser};
use srdf::{
model::rdf::FocusRdf, ok, property_iri, property_values_iri, RDFNodeParse, RDFParser, Term,
};
use std::fmt::Debug;

use crate::{
Expand All @@ -14,14 +16,14 @@ type Result<A> = std::result::Result<A, ServiceDescriptionError>;

pub struct ServiceDescriptionParser<RDF>
where
RDF: FocusRDF + Debug,
RDF: FocusRdf + Debug,
{
rdf_parser: RDFParser<RDF>,
}

impl<RDF> ServiceDescriptionParser<RDF>
where
RDF: FocusRDF + Debug + 'static,
RDF: FocusRdf + Debug + 'static,
{
pub fn new(rdf: RDF) -> ServiceDescriptionParser<RDF> {
ServiceDescriptionParser {
Expand All @@ -39,7 +41,7 @@ where

pub fn service_description() -> impl RDFNodeParse<RDF, Output = ServiceDescription>
where
RDF: FocusRDF + 'static,
RDF: FocusRdf + 'static,
{
Self::endpoint().then(|iri| {
Self::supported_language().then(move |supported_language| {
Expand Down Expand Up @@ -74,21 +76,21 @@ where

pub fn default_dataset() -> impl RDFNodeParse<RDF, Output = Dataset>
where
RDF: FocusRDF + 'static,
RDF: FocusRdf + 'static,
{
property_iri(&SD_DEFAULT_DATASET).then(move |iri| ok(&Dataset::new(&iri)))
}

pub fn endpoint() -> impl RDFNodeParse<RDF, Output = IriS>
where
RDF: FocusRDF + 'static,
RDF: FocusRdf + 'static,
{
property_iri(&SD_ENDPOINT)
}

pub fn feature() -> impl RDFNodeParse<RDF, Output = Vec<Feature>>
where
RDF: FocusRDF,
RDF: FocusRdf,
{
property_values_iri(&SD_FEATURE).flat_map(|ref iris| {
let features = get_features(iris)?;
Expand All @@ -98,7 +100,7 @@ where

pub fn result_format() -> impl RDFNodeParse<RDF, Output = Vec<ResultFormat>>
where
RDF: FocusRDF,
RDF: FocusRdf,
{
property_values_iri(&SD_RESULT_FORMAT).flat_map(|ref iris| {
let result_format = get_result_formats(iris)?;
Expand All @@ -108,15 +110,15 @@ where

pub fn supported_language() -> impl RDFNodeParse<RDF, Output = Vec<SupportedLanguage>>
where
RDF: FocusRDF,
RDF: FocusRdf,
{
property_values_iri(&SD_SUPPORTED_LANGUAGE).flat_map(|ref iris| {
let langs = get_supported_languages(iris)?;
Ok(langs)
})
}

fn sd_service() -> RDF::Term {
fn sd_service() -> Term<RDF> {
RDF::iri_s2term(&SD_SERVICE)
}
}
Expand Down
Loading

0 comments on commit 1c1ab52

Please sign in to comment.