Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/blank nodes #1

Merged
merged 9 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Python tests

on:
push:
branches: [ main ]
branches: [ main, "feature/*" ]
pull_request:
branches: [ main ]

Expand Down
2 changes: 1 addition & 1 deletion arrow_python_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pyo3 = {version = "0.19.2", features = ["extension-module"]}
polars-core = {version="0.32.1", features=["dtype-array", "dtype-categorical", "dtype-date", "dtype-datetime",
"dtype-decimal", "dtype-duration", "dtype-i8", "dtype-i16", "dtype-struct", "dtype-time", "dtype-u8", "dtype-u16"]}
thiserror="1.0.31"
simple-error = "0.2.3"
simple-error = "0.3.0"
2 changes: 1 addition & 1 deletion arrow_python_utils/src/to_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn to_py_df(
pyarrow: &PyModule,
polars: &PyModule,
) -> PyResult<PyObject> {
let py_rb = to_py_rb(rb, names, py.clone(), pyarrow)?;
let py_rb = to_py_rb(rb, names, py, pyarrow)?;
let py_rb_list = PyList::empty(py);
py_rb_list.append(py_rb)?;
let py_table = pyarrow
Expand Down
2 changes: 1 addition & 1 deletion arrow_python_utils/src/to_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn array_to_rust(obj: &PyAny) -> PyResult<ArrayRef> {
unsafe {
let field = ffi::import_field_from_c(schema.as_ref()).map_err(ToRustError::from)?;
let array = ffi::import_array_from_c(*array, field.data_type).map_err(ToRustError::from)?;
Ok(array.into())
Ok(array)
}
}

Expand Down
12 changes: 6 additions & 6 deletions maplib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ nom={version="7.1.1", features=["alloc"]}
sprs = {version="0.11.0", features=["rayon"]}
spargebra = "0.2.2"
oxrdf = "0.1.0"
polars = {version="0.32.1", features=["semi_anti_join","abs", "round_series", "lazy", "concat_str", "is_in", "dtype-full", "strings", "horizontal_concat", "rows", "timezones", "polars-time", "temporal", "list_eval", "partition_by", "parquet", "cse", "nightly", "performant"] }
polars = {version="0.32.1", features=["semi_anti_join", "abs", "round_series", "lazy", "concat_str", "is_in", "dtype-full", "strings", "horizontal_concat", "rows", "timezones", "polars-time", "temporal", "list_eval", "partition_by", "parquet", "cse", "nightly", "performant"] }
unic-char-range = "0.9.0"
log="0.4.19"
rio_turtle = "0.7.1"
rio_api = "0.7.1"
rio_turtle = "0.8.4"
rio_api = "0.8.4"
polars-utils = "0.32.1"
polars-core = "0.32.1"
chrono = "0.4"
chrono-tz = "0.6"
chrono-tz = "0.8"
uuid = {version = "1.1.2", features = [
"v4", # Lets you generate random UUIDs
"fast-rng", # Use a faster (but still sufficiently random) RNG
Expand All @@ -30,5 +30,5 @@ thiserror="1.0.31"
env_logger = "0.10.0"

[dev-dependencies]
rstest = "0.14.0"
serial_test = "0.8.0"
rstest = "0.18.2"
serial_test = "2.0.0"
67 changes: 55 additions & 12 deletions maplib/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::constants::BLANK_NODE_IRI;
#[cfg(test)]
use crate::constants::OTTR_TRIPLE;
use oxrdf::vocab::xsd;
Expand Down Expand Up @@ -62,7 +63,7 @@ impl Display for Signature {
write!(f, ", ")?;
}
}
if let Some(_) = self.annotation_list {
if self.annotation_list.is_some() {
todo!();
}
write!(f, " ]")
Expand Down Expand Up @@ -105,27 +106,47 @@ impl Display for Parameter {

#[derive(PartialEq, Debug, Clone)]
pub enum PType {
BasicType(NamedNode, String),
LUBType(Box<PType>),
ListType(Box<PType>),
NEListType(Box<PType>),
Basic(NamedNode, String),
Lub(Box<PType>),
List(Box<PType>),
NEList(Box<PType>),
}

impl PType {
pub fn is_blank_node(&self) -> bool {
if let PType::Basic(nn, _) = &self {
if nn.as_str() == BLANK_NODE_IRI {
return true;
}
}
false
}

pub fn is_iri(&self) -> bool {
if let PType::Basic(nn, _) = self {
if nn.as_ref() == xsd::ANY_URI {
return true;
}
}
true
}
}

impl Display for PType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
PType::BasicType(_nn, s) => {
PType::Basic(_nn, s) => {
write!(f, "{}", s)
}
PType::LUBType(lt) => {
PType::Lub(lt) => {
let s = lt.to_string();
write!(f, "LUBType({})", s)
}
PType::ListType(lt) => {
PType::List(lt) => {
let s = lt.to_string();
write!(f, "ListType({})", s)
}
PType::NEListType(lt) => {
PType::NEList(lt) => {
let s = lt.to_string();
write!(f, "NEListType({})", s)
}
Expand Down Expand Up @@ -161,6 +182,22 @@ pub enum ConstantTerm {
ConstantList(Vec<ConstantTerm>),
}

impl ConstantTerm {
pub fn has_blank_node(&self) -> bool {
match self {
ConstantTerm::Constant(c) => c.is_blank_node(),
ConstantTerm::ConstantList(l) => {
for c in l {
if c.has_blank_node() {
return true;
}
}
false
}
}
}
}

impl Display for ConstantTerm {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Expand All @@ -181,16 +218,22 @@ impl Display for ConstantTerm {

#[derive(PartialEq, Debug, Clone)]
pub enum ConstantLiteral {
IRI(NamedNode),
Iri(NamedNode),
BlankNode(BlankNode),
Literal(StottrLiteral),
None,
}

impl ConstantLiteral {
pub fn is_blank_node(&self) -> bool {
matches!(self, ConstantLiteral::BlankNode(_))
}
}

impl Display for ConstantLiteral {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ConstantLiteral::IRI(i) => std::fmt::Display::fmt(i, f),
ConstantLiteral::Iri(i) => std::fmt::Display::fmt(i, f),
ConstantLiteral::BlankNode(bn) => std::fmt::Display::fmt(bn, f),
ConstantLiteral::Literal(lit) => std::fmt::Display::fmt(lit, f),
ConstantLiteral::None => {
Expand Down Expand Up @@ -346,7 +389,7 @@ fn test_display_easy_template() {
parameter_list: vec![Parameter {
optional: true,
non_blank: true,
ptype: Some(PType::BasicType(
ptype: Some(PType::Basic(
xsd::DOUBLE.into_owned(),
"xsd:double".to_string(),
)),
Expand Down
6 changes: 3 additions & 3 deletions maplib/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::fs::read_to_string;
use std::path::Path;

pub fn document_from_str(s: &str) -> Result<StottrDocument, TemplateError> {
let unresolved = whole_stottr_doc(s).map_err(|x| TemplateError::ParsingError(x))?;
resolve_document(unresolved).map_err(|x| TemplateError::ResolutionError(x))
let unresolved = whole_stottr_doc(s).map_err(TemplateError::ParsingError)?;
resolve_document(unresolved).map_err(TemplateError::ResolutionError)
}

pub fn document_from_file<P: AsRef<Path>>(p: P) -> Result<StottrDocument, TemplateError> {
let s = read_to_string(p).map_err(|x| TemplateError::ReadTemplateFileError(x))?;
let s = read_to_string(p).map_err(TemplateError::ReadTemplateFileError)?;
document_from_str(&s)
}
Loading