Skip to content
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 .cargo/audit.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[advisories]
ignore = ["RUSTSEC-2024-0436", "RUSTSEC-2025-0075"] # Unmaintained package "paste" used by Polars
ignore = ["RUSTSEC-2024-0436"] # Unmaintained package "paste" used by Polars
28 changes: 4 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ uuid = { version = "1.16.0", features = [
"fast-rng", # Use a faster (but still sufficiently random) RNG
] }
thiserror = "2.0.12"
nom = { version = "7.1.3" }
peg = "0.8"
rand = "0.9.1"
oxilangtag = "0.1.5"
Expand Down
10 changes: 1 addition & 9 deletions lib/maplib/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,7 @@ impl Model {
let mut dataset =
TemplateDataset::from_documents(vec![doc]).map_err(MaplibError::TemplateError)?;
let return_template_iri = if !dataset.templates.is_empty() {
Some(
dataset
.templates
.first()
.unwrap()
.signature
.template_name
.clone(),
)
Some(dataset.templates.first().unwrap().signature.iri.clone())
} else {
None
};
Expand Down
6 changes: 2 additions & 4 deletions lib/maplib/src/mapping/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ impl Model {

patterns.push(Instance {
list_expander: list_expander.clone(),
template_name: NamedNode::new_unchecked(OTTR_TRIPLE),
prefixed_template_name: Some("ottr:Triple".to_string()),
template_iri: NamedNode::new_unchecked(OTTR_TRIPLE),
argument_list: vec![
Argument {
list_expand: false,
Expand Down Expand Up @@ -143,8 +142,7 @@ impl Model {
self.default_template_counter += 1;
let template = Template {
signature: Signature {
template_name: NamedNode::new(template_name.clone()).unwrap(),
template_prefixed_name: None,
iri: NamedNode::new(template_name.clone()).unwrap(),
parameter_list: params,
annotation_list: None,
},
Expand Down
25 changes: 12 additions & 13 deletions lib/maplib/src/mapping/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use std::collections::{HashMap, HashSet};
use std::ops::Sub;
use std::time::Instant;
use templates::ast::{
ConstantTerm, ConstantTermOrList, DefaultValue, Instance, ListExpanderType, PType, Signature,
StottrTerm,
ConstantTerm, ConstantTermOrList, Instance, ListExpanderType, PType, Signature, StottrTerm,
};
use templates::constants::OTTR_TRIPLE;
use templates::MappingColumnType;
Expand Down Expand Up @@ -69,7 +68,7 @@ impl Model {
let now = Instant::now();

let target_template = self.resolve_template(template)?.clone();
let target_template_name = target_template.signature.template_name.as_str().to_string();
let target_template_name = target_template.signature.iri.as_str().to_string();
let MapOptions {
graph,
validate_iris,
Expand Down Expand Up @@ -130,7 +129,7 @@ impl Model {
));
}
if let Some(template) = self.template_dataset.get(name) {
if template.signature.template_name.as_str() == OTTR_TRIPLE {
if template.signature.iri.as_str() == OTTR_TRIPLE {
if let Some(df) = df {
Ok((
vec![OTTRTripleInstance {
Expand Down Expand Up @@ -173,12 +172,12 @@ impl Model {
.enumerate()
.map(|(i, (instance, series_vec))| {
let target_template = if let Some(target_template) =
self.template_dataset.get(instance.template_name.as_str())
self.template_dataset.get(instance.template_iri.as_str())
{
target_template
} else {
return Err(MappingError::TemplateNotFound(
instance.template_name.to_string(),
instance.template_iri.to_string(),
));
};
if let Some(RemapResult {
Expand All @@ -202,7 +201,7 @@ impl Model {
layer + 1,
i,
blank_node_counter,
instance.template_name.as_str(),
instance.template_iri.as_str(),
Some(instance_df),
&target_template.signature,
instance_dynamic_columns,
Expand Down Expand Up @@ -327,17 +326,17 @@ fn fill_nulls_with_defaults(
mut lf: LazyFrame,
current_types: &mut HashMap<String, MappingColumnType>,
c: &str,
default: &DefaultValue,
default: &ConstantTermOrList,
) -> Result<LazyFrame, MappingError> {
if default.constant_term.has_blank_node() {
if default.has_blank_node() {
let df = lf.collect().unwrap();
if df.column(c).unwrap().is_null().any() {
todo!();
} else {
return Ok(df.lazy());
}
}
let (expr, _, mct) = constant_to_expr(&default.constant_term, &None)?;
let (expr, _, mct) = constant_to_expr(&default, &None)?;
let is_none = if let MappingColumnType::Flat(inner) = current_types.get(c).unwrap() {
inner.is_none()
} else {
Expand Down Expand Up @@ -835,13 +834,13 @@ fn create_remapped(
fn add_default_value(
static_columns: &mut HashMap<String, StaticColumn>,
name: &str,
default: &DefaultValue,
default: &ConstantTermOrList,
) {
static_columns.insert(
name.to_string(),
StaticColumn {
constant_term: default.constant_term.clone(),
ptype: Some(default.constant_term.ptype()),
constant_term: default.clone(),
ptype: Some(default.ptype()),
},
);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ rust-version.workspace = true

[dependencies]
representation = { path = "../representation" }
spargebra = {path = "../spargebra"}

oxrdf = { workspace = true }
unic-char-range = "0.9.0"
tracing = { workspace = true }
thiserror = { workspace = true }
nom = { workspace = true, features = ["alloc"] }
pyo3.workspace = true
walkdir.workspace = true
oxiri.workspace = true
oxilangtag.workspace = true
peg = {workspace = true, features = ["trace"] }
31 changes: 5 additions & 26 deletions lib/templates/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,14 @@ impl Display for Template {

#[derive(PartialEq, Debug, Clone)]
pub struct Signature {
pub template_name: NamedNode,
pub template_prefixed_name: Option<String>,
pub iri: NamedNode,
pub parameter_list: Vec<Parameter>,
pub annotation_list: Option<Vec<Annotation>>,
}

impl Display for Signature {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if let Some(template_prefixed_name) = &self.template_prefixed_name {
write!(f, "{template_prefixed_name}")?;
} else {
write!(f, "{}", &self.template_name)?;
}
write!(f, "{}", &self.iri)?;
write!(f, " [")?;
for (idx, p) in self.parameter_list.iter().enumerate() {
write!(f, "\n ")?;
Expand All @@ -86,7 +81,7 @@ pub struct Parameter {
pub non_blank: bool,
pub ptype: Option<PType>,
pub variable: Variable,
pub default_value: Option<DefaultValue>,
pub default_value: Option<ConstantTermOrList>,
}

impl Display for Parameter {
Expand Down Expand Up @@ -217,17 +212,6 @@ impl Display for PType {
}
}

#[derive(PartialEq, Debug, Clone)]
pub struct DefaultValue {
pub constant_term: ConstantTermOrList,
}

impl Display for DefaultValue {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.constant_term, f)
}
}

#[derive(PartialEq, Debug, Clone)]
pub enum ConstantTermOrList {
ConstantTerm(ConstantTerm),
Expand Down Expand Up @@ -324,8 +308,7 @@ impl Display for ConstantTerm {
#[derive(PartialEq, Debug, Clone)]
pub struct Instance {
pub list_expander: Option<ListExpanderType>,
pub template_name: NamedNode,
pub prefixed_template_name: Option<String>,
pub template_iri: NamedNode,
pub argument_list: Vec<Argument>,
}

Expand All @@ -335,11 +318,7 @@ impl Display for Instance {
std::fmt::Display::fmt(le, f)?;
write!(f, " | ")?;
}
if let Some(prefixed_template_name) = &self.prefixed_template_name {
write!(f, "{prefixed_template_name}")?;
} else {
write!(f, "{}", &self.template_name)?;
}
write!(f, "{}", &self.template_iri)?;
write!(f, "(")?;
for (idx, a) in self.argument_list.iter().enumerate() {
std::fmt::Display::fmt(a, f)?;
Expand Down
35 changes: 17 additions & 18 deletions lib/templates/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ impl TemplateDataset {

let ottr_template = Template {
signature: Signature {
template_name: NamedNode::new_unchecked(OTTR_TRIPLE),
template_prefixed_name: Some("ottr:Triple".to_string()),
iri: NamedNode::new_unchecked(OTTR_TRIPLE),
parameter_list: vec![
ottr_triple_subject,
ottr_triple_predicate,
Expand Down Expand Up @@ -145,29 +144,29 @@ impl TemplateDataset {
pub fn get(&self, template: &str) -> Option<&Template> {
self.templates
.iter()
.find(|&t| t.signature.template_name.as_str() == template)
.find(|&t| t.signature.iri.as_str() == template)
}

pub fn infer_types(&mut self) -> Result<(), TemplateError> {
let template_names: Vec<_> = self
.templates
.iter()
.map(|x| x.signature.template_name.as_str().to_string())
.map(|x| x.signature.iri.as_str().to_string())
.collect();
let mut template_map: HashMap<String, Template> = self
.templates
.drain(..)
.map(|x| (x.signature.template_name.as_str().to_string(), x))
.map(|x| (x.signature.iri.as_str().to_string(), x))
.collect();
let mut affects_map: HashMap<String, Vec<String>> = HashMap::new();
for t in template_map.values() {
for i in &t.pattern_list {
if let Some(v) = affects_map.get_mut(i.template_name.as_str()) {
v.push(t.signature.template_name.as_str().to_string());
if let Some(v) = affects_map.get_mut(i.template_iri.as_str()) {
v.push(t.signature.iri.as_str().to_string());
} else {
affects_map.insert(
i.template_name.as_str().to_string(),
vec![t.signature.template_name.as_str().to_string()],
i.template_iri.as_str().to_string(),
vec![t.signature.iri.as_str().to_string()],
);
}
}
Expand Down Expand Up @@ -218,7 +217,7 @@ impl TemplateDataset {
if let Some(pos) = self
.templates
.iter()
.position(|x| x.signature.template_name == template.signature.template_name)
.position(|x| x.signature.iri == template.signature.iri)
{
self.templates.remove(pos);
}
Expand All @@ -234,18 +233,18 @@ fn infer_template_types(
) -> Result<bool, TemplateError> {
let mut changed = false;
for i in &mut template.pattern_list {
let other = if let Some(t) = templates.get(i.template_name.as_str()) {
let other = if let Some(t) = templates.get(i.template_iri.as_str()) {
t
} else {
return Err(TemplateError::TemplateNotFound(
template.signature.template_name.to_string().clone(),
i.template_name.to_string().clone(),
template.signature.iri.to_string().clone(),
i.template_iri.to_string().clone(),
));
};
if i.argument_list.len() != other.signature.parameter_list.len() {
return Err(TemplateError::InconsistentNumberOfArguments(
template.signature.template_name.as_str().to_string(),
other.signature.template_name.as_str().to_string(),
template.signature.iri.as_str().to_string(),
other.signature.iri.as_str().to_string(),
i.argument_list.len(),
other.signature.parameter_list.len(),
));
Expand All @@ -264,15 +263,15 @@ fn infer_template_types(
if !other_parameter.optional {
changed = changed
|| lub_update(
&template.signature.template_name,
&template.signature.iri,
v,
my_parameter,
&PType::NEList(Box::new(other_ptype.clone())),
)?;
} else {
changed = changed
|| lub_update(
&template.signature.template_name,
&template.signature.iri,
v,
my_parameter,
&PType::List(Box::new(other_ptype.clone())),
Expand All @@ -281,7 +280,7 @@ fn infer_template_types(
} else {
changed = changed
|| lub_update(
&template.signature.template_name,
&template.signature.iri,
v,
my_parameter,
other_ptype,
Expand Down
Loading