Skip to content

Commit

Permalink
Started work on adding query option
Browse files Browse the repository at this point in the history
  • Loading branch information
labra committed Sep 18, 2024
1 parent bf6af68 commit 2ea4723
Show file tree
Hide file tree
Showing 15 changed files with 427 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The binary is available at: [https://github.com/rudof-project/rudof/releases] so

The usual way to run/install a binary in Mac is to download it in a folder, add that folder to your PATH and activating the binary using:

```
```sh
chmod +x <binary_file>
```

Expand Down
18 changes: 0 additions & 18 deletions rudof_cli/src/data.rs

This file was deleted.

22 changes: 10 additions & 12 deletions rudof_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use shex_compact::{ShExFormatter, ShExParser, ShapeMapParser, ShapemapFormatter}
use shex_validation::{Validator, ValidatorConfig};
use sparql_service::{QueryConfig, ServiceConfig, ServiceDescription};
use srdf::srdf_graph::SRDFGraph;
use srdf::{RDFFormat, RdfDataConfig, SRDFBuilder, SRDFSparql, SRDF};
use srdf::{RDFFormat, RdfData, RdfDataConfig, SRDFBuilder, SRDFSparql, SRDF};

Check warning on line 42 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `SRDFBuilder`

Check warning on line 42 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `SRDFBuilder`
use std::fs::{File, OpenOptions};
use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};
Expand All @@ -50,13 +50,11 @@ use supports_color::Stream;
use tracing::debug;

pub mod cli;
pub mod data;
pub mod input_convert_format;
pub mod input_spec;
pub mod output_convert_format;

pub use cli::*;
pub use data::*;
pub use input_convert_format::InputConvertFormat;
pub use input_spec::*;
pub use output_convert_format::OutputConvertFormat;
Expand Down Expand Up @@ -570,8 +568,8 @@ fn run_validate_shex(
};
let mut validator = Validator::new(schema, config);
let result = match &data {
Data::Endpoint(endpoint) => validator.validate_shapemap(&shapemap, endpoint),
Data::RDFData(data) => validator.validate_shapemap(&shapemap, data),
RdfData::Endpoint(endpoint) => validator.validate_shapemap(&shapemap, endpoint),

Check failure on line 571 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

no associated item named `Endpoint` found for struct `RdfData` in the current scope

Check failure on line 571 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no associated item named `Endpoint` found for struct `RdfData` in the current scope
RdfData::RDFData(data) => validator.validate_shapemap(&shapemap, data),

Check failure on line 572 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

no associated item named `RDFData` found for struct `RdfData` in the current scope

Check failure on line 572 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no associated item named `RDFData` found for struct `RdfData` in the current scope
};
match result {
Result::Ok(_t) => match validator.result_map(data.prefixmap()) {

Check failure on line 575 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

mismatched types

Check failure on line 575 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

mismatched types
Expand Down Expand Up @@ -1074,19 +1072,19 @@ fn get_data(
reader_mode: &RDFReaderMode,
_debug: u8,
config: &RdfDataConfig,
) -> Result<Data> {
) -> Result<RdfData> {
match (data.is_empty(), endpoint) {
(true, None) => {
bail!("None of `data` or `endpoint` parameters have been specified for validation")
}
(false, None) => {
// let data_path = cast_to_data_path(data)?;
let data = parse_data(data, data_format, reader_mode, config)?;
Ok(Data::RDFData(data))
Ok(RdfData::RDFData(data))

Check failure on line 1083 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

no associated item named `RDFData` found for struct `RdfData` in the current scope

Check failure on line 1083 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no associated item named `RDFData` found for struct `RdfData` in the current scope
}
(true, Some(endpoint)) => {
let endpoint = SRDFSparql::from_str(endpoint)?;
Ok(Data::Endpoint(endpoint))
Ok(RdfData::Endpoint(endpoint))

Check failure on line 1087 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

no associated item named `Endpoint` found for struct `RdfData` in the current scope

Check failure on line 1087 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no associated item named `Endpoint` found for struct `RdfData` in the current scope
}
(false, Some(_)) => {
bail!("Only one of 'data' or 'endpoint' supported at the same time at this moment")
Expand Down Expand Up @@ -1131,15 +1129,15 @@ fn run_node(
let data = get_data(data, data_format, endpoint, reader_mode, debug, config)?;
let node_selector = parse_node_selector(node_str)?;
match data {
Data::Endpoint(endpoint) => show_node_info(
RdfData::Endpoint(endpoint) => show_node_info(

Check failure on line 1132 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

no associated item named `Endpoint` found for struct `RdfData` in the current scope

Check failure on line 1132 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no associated item named `Endpoint` found for struct `RdfData` in the current scope
node_selector,
predicates,
&endpoint,
show_node_mode,
show_hyperlinks,
&mut writer,
),
Data::RDFData(data) => show_node_info(
RdfData::RDFData(data) => show_node_info(

Check failure on line 1140 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

no associated item named `RDFData` found for struct `RdfData` in the current scope

Check failure on line 1140 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no associated item named `RDFData` found for struct `RdfData` in the current scope
node_selector,
predicates,
&data,
Expand Down Expand Up @@ -1306,8 +1304,8 @@ fn run_data(
let (mut writer, _color) = get_writer(output, force_overwrite)?;
let data = get_data(data, data_format, &None, reader_mode, debug, config)?;
match data {
Data::Endpoint(e) => writeln!(writer, "Endpoint {e:?}")?,
Data::RDFData(graph) => graph.serialize(RDFFormat::from(*result_format), writer)?,
RdfData::Endpoint(e) => writeln!(writer, "Endpoint {e:?}")?,

Check failure on line 1307 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

no associated item named `Endpoint` found for struct `RdfData` in the current scope

Check failure on line 1307 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no associated item named `Endpoint` found for struct `RdfData` in the current scope
RdfData::RDFData(graph) => graph.serialize(RDFFormat::from(*result_format), writer)?,

Check failure on line 1308 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Check

no associated item named `RDFData` found for struct `RdfData` in the current scope

Check failure on line 1308 in rudof_cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite

no associated item named `RDFData` found for struct `RdfData` in the current scope
}
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions sparql_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde_yml = "0.0.11"
itertools = "0.13"
indexmap = { version = "2"}
iri_s = { workspace = true }
prefixmap = { workspace = true }
srdf = { workspace = true }
tracing = { workspace = true }
oxiri = "0.2.3-alpha.1"
Expand Down
2 changes: 2 additions & 0 deletions sparql_service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! SPARQL Service
//!
pub mod query_config;
pub mod query_processor;
pub mod service_config;
pub mod service_description;
pub mod service_description_error;
pub mod service_description_parser;
pub mod service_description_vocab;

pub use crate::query_config::*;
pub use crate::query_processor::*;
pub use crate::service_config::*;
pub use crate::service_description::*;
pub use crate::service_description_error::*;
Expand Down
23 changes: 23 additions & 0 deletions sparql_service/src/query_processor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use prefixmap::PrefixMap;
use srdf::{QuerySolutionIter, RdfData, SRDF};

#[derive(Debug, Clone)]
pub struct QueryProcessor {
rdf_data: RdfData,
}

impl QueryProcessor {
pub fn new(rdf_data: RdfData) -> QueryProcessor {
QueryProcessor {
rdf_data: rdf_data.clone(),
}
}

pub fn prefix_map(&self) -> Option<PrefixMap> {
Some(self.rdf_data.prefixmap())
}

pub fn query_select<S: SRDF>(_str: &str) -> QuerySolutionIter<S> {
todo!()
}
}
4 changes: 2 additions & 2 deletions srdf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ pub mod numeric_literal;
pub mod object;
pub mod query_srdf;
pub mod rdf;
pub mod rdf_data_config;
pub mod rdf_format;
pub mod shacl_path;
pub mod srdf;
pub mod srdf_basic;
pub mod srdf_builder;
pub mod srdf_data;
pub mod srdf_graph;
pub mod srdf_parser;
pub mod srdf_sparql;
Expand All @@ -32,10 +32,10 @@ pub use crate::neighs::*;
pub use crate::query_srdf::*;
pub use crate::srdf::*;
pub use crate::srdf_basic::*;
pub use crate::srdf_data::*;
pub use bnode::*;
pub use object::*;
pub use rdf::*;
pub use rdf_data_config::*;
pub use rdf_format::*;
pub use shacl_path::*;
pub use srdf_builder::*;
Expand Down
32 changes: 30 additions & 2 deletions srdf/src/query_srdf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::rc::Rc;
use std::{marker::PhantomData, rc::Rc};

use crate::SRDFBasic;

Expand Down Expand Up @@ -76,7 +76,13 @@ pub struct QuerySolutionIter<S: SRDFBasic> {
iter: Box<dyn Iterator<Item = Result<QuerySolution<S>, S::Err>>>,
}

impl<S: SRDFBasic> QuerySolutionIter<S> {
impl<S: SRDFBasic + 'static> QuerySolutionIter<S> {
pub(crate) fn empty() -> Self {

Check warning on line 80 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Check

associated function `empty` is never used

Check warning on line 80 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Test Suite

associated function `empty` is never used

Check failure on line 80 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Clippy

associated function `empty` is never used
Self {
iter: Box::new(EmptyQuerySolutionIter::<S>::new()),
}
}

pub(crate) fn new(
variables: Rc<Vec<VarName>>,
iter: impl Iterator<Item = Result<Vec<Option<S::Term>>, S::Err>> + 'static,
Expand All @@ -89,6 +95,28 @@ impl<S: SRDFBasic> QuerySolutionIter<S> {
}
}

struct EmptyQuerySolutionIter<S: SRDFBasic> {

Check warning on line 98 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Check

struct `EmptyQuerySolutionIter` is never constructed

Check warning on line 98 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Test Suite

struct `EmptyQuerySolutionIter` is never constructed

Check failure on line 98 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Clippy

struct `EmptyQuerySolutionIter` is never constructed
marker: PhantomData<S>,
}

impl<S> EmptyQuerySolutionIter<S>
where
S: SRDFBasic,
{
pub fn new() -> EmptyQuerySolutionIter<S> {

Check warning on line 106 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Check

associated function `new` is never used

Check warning on line 106 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Test Suite

associated function `new` is never used

Check failure on line 106 in srdf/src/query_srdf.rs

View workflow job for this annotation

GitHub Actions / Clippy

associated function `new` is never used
EmptyQuerySolutionIter {
marker: PhantomData,
}
}
}

impl<S: SRDFBasic> Iterator for EmptyQuerySolutionIter<S> {
type Item = Result<QuerySolution<S>, S::Err>;
fn next(&mut self) -> Option<Self::Item> {
None
}
}

impl<S: SRDFBasic> Iterator for QuerySolutionIter<S> {
type Item = Result<QuerySolution<S>, S::Err>;
fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion srdf/src/srdf_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub trait SRDFBasic {

fn qualify_iri(&self, iri: &Self::IRI) -> String;
fn qualify_subject(&self, subj: &Self::Subject) -> String;
fn qualify_term(&self, subj: &Self::Term) -> String;
fn qualify_term(&self, term: &Self::Term) -> String;

fn prefixmap(&self) -> Option<PrefixMap>;
fn resolve_prefix_local(&self, prefix: &str, local: &str) -> Result<IriS, PrefixMapError>;
Expand Down
7 changes: 7 additions & 0 deletions srdf/src/srdf_data/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod rdf_data;
mod rdf_data_config;
mod rdf_data_error;

pub use rdf_data::*;
pub use rdf_data_config::*;
pub use rdf_data_error::*;
Loading

0 comments on commit 2ea4723

Please sign in to comment.