Skip to content

Commit

Permalink
Fix blank node bug
Browse files Browse the repository at this point in the history
  • Loading branch information
magbak committed Dec 16, 2023
1 parent 433f339 commit 63a5c70
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
6 changes: 4 additions & 2 deletions maplib/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ fn create_remapped(
let mut existing = vec![];
let mut new = vec![];
let mut rename_map: HashMap<&String, Vec<&String>> = HashMap::new();
let mut out_blank_node_counter = blank_node_counter;

for (original, target) in instance
.argument_list
Expand Down Expand Up @@ -624,7 +625,7 @@ fn create_remapped(
new_series.push(series);
new_dynamic_columns.insert(target_colname.clone(), primitive_column);
new_dynamic_from_constant.push(target_colname);
blank_node_counter += input_df_height;
out_blank_node_counter = max(out_blank_node_counter, blank_node_counter+input_df_height);
} else if original.list_expand {
let (expr, primitive_column) =
create_dynamic_expression_from_static(target_colname, ct, &target.ptype)?;
Expand Down Expand Up @@ -701,12 +702,13 @@ fn create_remapped(
"Creating remapped took {} seconds",
now.elapsed().as_secs_f32()
);
println!("Remapped {}", lf.clone().collect().unwrap());
Ok((
lf.collect().unwrap(),
new_dynamic_columns,
new_constant_columns,
new_unique_subsets,
blank_node_counter,
out_blank_node_counter,
))
}

Expand Down
3 changes: 2 additions & 1 deletion representation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ oxrdf = {version = "0.1.7", features = ["oxsdatatypes"]}
polars-core = "0.34.2"
chrono = "0.4"
spargebra = "0.2.8"
bigdecimal = "0.4.1"
bigdecimal = "0.4.1"
polars-arrow = "0.34.2"
8 changes: 4 additions & 4 deletions representation/src/literals.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::{LANG_STRING_LANG_FIELD, LANG_STRING_VALUE_FIELD};
use chrono::{DateTime, NaiveDateTime, Utc};
use oxrdf::vocab::rdf::LANG_STRING;
use oxrdf::vocab::xsd;
use oxrdf::NamedNodeRef;
use oxrdf::vocab::{rdf, xsd};
use oxrdf::{Literal, NamedNodeRef};
use polars_core::datatypes::TimeUnit;
use polars_core::prelude::{AnyValue, DataType, Field};
use std::str::FromStr;
use polars_arrow::offset::Offset;
use polars_arrow::scalar::Utf8Scalar;

//This code is copied and modified from Chrontext, which has identical licensing
pub fn sparql_literal_to_any_value<'a, 'b>(
Expand Down Expand Up @@ -59,15 +61,13 @@ pub fn sparql_literal_to_any_value<'a, 'b>(
}
}
} else if datatype == LANG_STRING {
println!("VALUE: {}", value);
let val = AnyValue::Utf8(value);
let lang = AnyValue::Utf8(language.unwrap());
let polars_fields: Vec<Field> = vec![
Field::new(LANG_STRING_VALUE_FIELD, DataType::Utf8),
Field::new(LANG_STRING_LANG_FIELD, DataType::Utf8),
];
let av = AnyValue::StructOwned(Box::new((vec![val, lang], polars_fields)));
println!("AV {:?}", av);
av
} else {
todo!("Not implemented! {:?}", datatype)
Expand Down
2 changes: 1 addition & 1 deletion triplestore/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate core;

mod constants;
pub(crate) mod conversion;
pub mod conversion;
pub mod errors;
mod export_triples;
mod io_funcs;
Expand Down
4 changes: 2 additions & 2 deletions triplestore/src/sparql/sparql_to_polars.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chrono::NaiveDate;
use oxrdf::vocab::xsd;
use oxrdf::vocab::{rdf, xsd};
use oxrdf::{BlankNode, Literal, NamedNode, Term};
use polars::export::chrono::{DateTime, NaiveDateTime, Utc};
use polars::prelude::{LiteralValue, NamedFrom, Series, TimeUnit};
Expand Down Expand Up @@ -29,7 +29,7 @@ pub fn sparql_literal_to_polars_literal_value(lit: &Literal) -> LiteralValue {
let value = lit.value();
let literal_value = if datatype == xsd::STRING {
LiteralValue::Utf8(value.to_string())
} else if datatype == xsd::UNSIGNED_INT {
} else if datatype == xsd::UNSIGNED_INT {
let u = u32::from_str(value).expect("Integer parsing error");
LiteralValue::UInt32(u)
} else if datatype == xsd::UNSIGNED_LONG {
Expand Down

0 comments on commit 63a5c70

Please sign in to comment.