Skip to content

Commit

Permalink
Release 0.1.55
Browse files Browse the repository at this point in the history
  • Loading branch information
labra committed Nov 13, 2024
1 parent e9e0be4 commit b20c27d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Current changes without release yet

## [v0.1.55] - 2024-11-14

- Added methods to show query solutions in rudof and pyrudof

## [v0.1.54] - 2024-11-13

- Added query to rudof and pyrudof
Expand Down
2 changes: 1 addition & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyrudof"
version = "0.1.54"
version = "0.1.55"
documentation = "https://rudof-project.github.io/rudof/"
readme = "README.md"
license.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion rudof_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rudof_lib"
version = "0.1.54"
version = "0.1.55"
authors.workspace = true
description.workspace = true
documentation = "https://docs.rs/rudof_lib"
Expand Down
22 changes: 13 additions & 9 deletions rudof_lib/src/rudof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use shapemap::{QueryShapeMap, ResultShapeMap, ShapeMapFormat, ValidationStat
pub use shex_compact::{ShExFormatter, ShapeMapParser, ShapemapFormatter as ShapeMapFormatter};
pub use shex_validation::Validator as ShExValidator;
pub use shex_validation::{ShExFormat, ValidatorConfig};
pub use srdf::{QuerySolutions, RDFFormat, ReaderMode, SRDFSparql};
pub use srdf::{QuerySolution, QuerySolutions, RDFFormat, ReaderMode, SRDFSparql};
pub type Result<T> = result::Result<T, RudofError>;
pub use shacl_ast::ast::Schema as ShaclSchema;
pub use shapes_converter::UmlGenerationMode;
Expand Down Expand Up @@ -243,28 +243,32 @@ impl Rudof {
}
}

pub fn run_query<R: io::Read>(&mut self, reader: &mut R) -> Result<QuerySolutions<RdfData>> {
let mut str = String::new();
reader
.read_to_string(&mut str)
.map_err(|e| RudofError::ReadError {
error: format!("{e}"),
})?;
pub fn run_query_str(&mut self, str: &str) -> Result<QuerySolutions<RdfData>> {
self.rdf_data
.check_store()
.map_err(|e| RudofError::StorageError {
error: format!("{e}"),
})?;
let results = self
.rdf_data
.query_select(&str)
.query_select(str)
.map_err(|e| RudofError::QueryError {
str: str.to_string(),
error: format!("{e}"),
})?;
Ok(results)
}

pub fn run_query<R: io::Read>(&mut self, reader: &mut R) -> Result<QuerySolutions<RdfData>> {
let mut str = String::new();
reader
.read_to_string(&mut str)
.map_err(|e| RudofError::ReadError {
error: format!("{e}"),
})?;
self.run_query_str(str.as_str())
}

pub fn serialize_shacl<W: io::Write>(
&self,
format: &ShaclFormat,
Expand Down
2 changes: 1 addition & 1 deletion sparql_service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sparql_service"
version = "0.1.54"
version = "0.1.55"
authors.workspace = true
description.workspace = true
edition.workspace = true
Expand Down
1 change: 0 additions & 1 deletion sparql_service/src/srdf_data/rdf_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ impl QuerySRDF for RdfData {
let sol = cnv_query_results(new_sol)?;
sols.extend(sol)
}
println!("Results...before endpoint: {}", sols.count());
for endpoint in &self.endpoints {
let new_sols = endpoint.query_select(query_str)?;
let new_sols_converted: Vec<QuerySolution<RdfData>> =
Expand Down
2 changes: 1 addition & 1 deletion srdf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "srdf"
version = "0.1.54"
version = "0.1.55"
authors.workspace = true
description.workspace = true
documentation = "https://docs.rs/srdf"
Expand Down
26 changes: 24 additions & 2 deletions srdf/src/query_srdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<S: SRDFBasic> VariableSolutionIndex<S> for &VarName {
}

/// Represents one query solution
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct QuerySolution<S: SRDFBasic> {
variables: Vec<VarName>,
values: Vec<Option<S::Term>>,
Expand All @@ -71,6 +71,7 @@ impl<S: SRDFBasic> QuerySolution<S> {
pub fn new(variables: Vec<VarName>, values: Vec<Option<S::Term>>) -> QuerySolution<S> {
QuerySolution { variables, values }
}

pub fn find_solution(&self, index: impl VariableSolutionIndex<S>) -> Option<&S::Term> {
match self.values.get(index.index(self)?) {
Some(value) => value.as_ref(),
Expand All @@ -96,6 +97,18 @@ impl<S: SRDFBasic> QuerySolution<S> {
values: cnv_values,
}
}

pub fn show(&self) -> String {
let mut result = String::new();
for var in self.variables.iter() {
let value = match self.find_solution(var) {
None => "()".to_string(),
Some(v) => format!("{v}"),
};
result.push_str(format!("{} -> {}\n", var, value).as_str())
}
result
}
}

impl<S: SRDFBasic, V: Into<Vec<VarName>>, T: Into<Vec<Option<S::Term>>>> From<(V, T)>
Expand All @@ -111,7 +124,7 @@ impl<S: SRDFBasic, V: Into<Vec<VarName>>, T: Into<Vec<Option<S::Term>>>> From<(V
}

/// Represent a list of query solutions
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct QuerySolutions<S: SRDFBasic> {
solutions: Vec<QuerySolution<S>>,
}
Expand Down Expand Up @@ -139,3 +152,12 @@ impl<S: SRDFBasic> QuerySolutions<S> {
self.solutions.len()
}
}

impl<S: SRDFBasic> IntoIterator for QuerySolutions<S> {
type Item = QuerySolution<S>;
type IntoIter = std::vec::IntoIter<QuerySolution<S>>;

fn into_iter(self) -> Self::IntoIter {
self.solutions.into_iter()
}
}

0 comments on commit b20c27d

Please sign in to comment.