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
9 changes: 9 additions & 0 deletions lib/representation/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ pub const XYZ_PREFIX: &str = "xyz";
pub const XYZ_PREFIX_IRI: &str = "http://sparql.xyz/facade-x/data/";
pub const FX_PREFIX: &str = "fx";
pub const FX_PREFIX_IRI: &str = "http://sparql.xyz/facade-x/ns/";
pub const FX_XYZ_PREFIX_IRI: &str = "http://sparql.xyz/facade-x/ns/prefixIRI";
pub const FX_PREFIX_SEP: &str = "http://sparql.xyz/facade-x/ns/prefixSeparator";
pub const FX_ROOT: &str = "http://sparql.xyz/facade-x/ns/root";
pub const FX_CHILD: &str = "http://sparql.xyz/facade-x/ns/child";
pub const FX_CHILD_NUMBER: &str = "http://sparql.xyz/facade-x/ns/childNumber";
pub const FX_XMLNS: &str = "http://sparql.xyz/facade-x/ns/xmlns";
pub const FX_XMLNS_SEP: &str = "http://sparql.xyz/facade-x/ns/xmlnsSeparator";
pub const FX_PREFIX_NAME: &str = "http://sparql.xyz/facade-x/ns/prefixName";
pub const FX_NULL: &str = "http://sparql.xyz/facade-x/ns/null";
pub const OTTR_TRIPLE: &str = "http://ns.ottr.xyz/0.4/Triple";
pub const OTTR_PREFIX: &str = "ottr";
pub const OTTR_PREFIX_IRI: &str = "http://ns.ottr.xyz/0.4/";
Expand Down
17 changes: 7 additions & 10 deletions lib/triplestore/src/map_df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ use oxrdf::NamedNode;
use polars::prelude::{col, lit, DataFrame, IntoLazy};
use polars_core::prelude::{Column, IntoColumn, NamedFrom, Series};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use representation::constants::MAPLIB_PREFIX_IRI;
use representation::constants::{
FX_CHILD, FX_CHILD_NUMBER, FX_ROOT, MAPLIB_PREFIX_IRI, XYZ_PREFIX_IRI,
};
use representation::dataset::NamedGraph;
use representation::polars_to_rdf::polars_type_to_literal_type;
use representation::{BaseRDFNodeType, OBJECT_COL_NAME, SUBJECT_COL_NAME};
use std::collections::HashMap;

const FACADE_X_ROOT: &str = "http://sparql.xyz/facade-x/ns/root";
const FACADE_X_CHILD: &str = "http://sparql.xyz/facade-x/ns/child";
const FACADE_X_CHILD_NUMBER: &str = "http://sparql.xyz/facade-x/ns/childNumber";
const DEFAULT_FACADE_X_DATA_PREFIX: &str = "http://sparql.xyz/facade-x/data/";

impl Triplestore {
pub fn map_df(
&mut self,
Expand Down Expand Up @@ -63,7 +60,7 @@ impl Triplestore {
object_type: base_obj_type.clone(),
predicate: Some(NamedNode::new_unchecked(format!(
"{}{}",
DEFAULT_FACADE_X_DATA_PREFIX,
XYZ_PREFIX_IRI,
uri_encode::encode_uri(c)
))),
graph: named_graph.clone(),
Expand All @@ -86,7 +83,7 @@ impl Triplestore {
.unwrap(),
subject_type: BaseRDFNodeType::IRI,
object_type: BaseRDFNodeType::IRI,
predicate: Some(NamedNode::new_unchecked(FACADE_X_CHILD.to_string())),
predicate: Some(NamedNode::new_unchecked(FX_CHILD.to_string())),
graph: named_graph.clone(),
subject_cat_state: BaseRDFNodeType::IRI.default_input_cat_state(),
object_cat_state: BaseRDFNodeType::IRI.default_input_cat_state(),
Expand All @@ -103,7 +100,7 @@ impl Triplestore {
.unwrap(),
subject_type: BaseRDFNodeType::IRI,
object_type: num_dt.clone(),
predicate: Some(NamedNode::new_unchecked(FACADE_X_CHILD_NUMBER.to_string())),
predicate: Some(NamedNode::new_unchecked(FX_CHILD_NUMBER.to_string())),
graph: named_graph.clone(),
subject_cat_state: BaseRDFNodeType::IRI.default_input_cat_state(),
object_cat_state: num_dt.default_input_cat_state(),
Expand All @@ -112,7 +109,7 @@ impl Triplestore {

let mut root_cols = Vec::new();
root_cols.push(Column::new(SUBJECT_COL_NAME.into(), vec![root_node_uuri]));
root_cols.push(Column::new(OBJECT_COL_NAME.into(), vec![FACADE_X_ROOT]));
root_cols.push(Column::new(OBJECT_COL_NAME.into(), vec![FX_ROOT]));
let root = TriplesToAdd {
df: DataFrame::new(1, root_cols).unwrap(),
subject_type: BaseRDFNodeType::IRI,
Expand Down
16 changes: 5 additions & 11 deletions lib/triplestore/src/map_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use oxrdf::vocab::{rdf, xsd};
use oxrdf::NamedNode;
use polars::prelude::PlSmallStr;
use polars_core::prelude::{AnyValue, Column, DataFrame};
use representation::constants::{FX_CHILD, FX_NULL, FX_ROOT, XYZ_PREFIX_IRI};
use representation::dataset::NamedGraph;
use representation::{BaseRDFNodeType, OBJECT_COL_NAME, SUBJECT_COL_NAME};
use serde_json::Value;
Expand All @@ -23,13 +24,6 @@ const STRING: u8 = 2;
const FLOAT: u8 = 3;
const IRI: u8 = 5;

const JSON_ROOT: &str = "http://sparql.xyz/facade-x/ns/root";
const JSON_CHILD: &str = "http://sparql.xyz/facade-x/ns/child";

const JSON_NULL: &str = "http://sparql.xyz/facade-x/ns/null";

const DEFAULT_JSON_KEYS_PREFIX: &str = "http://sparql.xyz/facade-x/data/";

const ROOT_ELEMENT_PROPERTY: &str = "urn:maplib:rootElement";

struct TripleTableBuilder<'a> {
Expand Down Expand Up @@ -140,14 +134,14 @@ impl Triplestore {
named_graph: &NamedGraph,
transient: bool,
) -> Result<(), TriplestoreError> {
let prefix = NamedNode::new_unchecked(DEFAULT_JSON_KEYS_PREFIX);
let prefix = NamedNode::new_unchecked(XYZ_PREFIX_IRI);
let v: Value = simd_json::serde::from_slice(u8s).unwrap();

let mut pred_map = HashMap::new();
let rdf_type = rdf::TYPE.into_owned();
pred_map.insert(rdf_type.clone(), TripleTableBuilder::new());

let doc_subject = new_iri_typed_subject(JSON_ROOT, &rdf_type, &mut pred_map);
let doc_subject = new_iri_typed_subject(FX_ROOT, &rdf_type, &mut pred_map);

let root_elem_property = NamedNode::new_unchecked(ROOT_ELEMENT_PROPERTY);
pred_map.insert(root_elem_property.clone(), TripleTableBuilder::new());
Expand Down Expand Up @@ -223,7 +217,7 @@ fn process_value(
}
Value::Null => {
let builder = map.get_mut(property.unwrap_or(root_elem_property)).unwrap();
builder.push_iri_iri(subject, JSON_NULL);
builder.push_iri_iri(subject, FX_NULL);
}
Value::Object(obj) => {
let new_subject = if let Some(property) = property {
Expand Down Expand Up @@ -257,7 +251,7 @@ fn process_value(
} else {
subject.to_string()
};
let ch = NamedNode::new_unchecked(JSON_CHILD);
let ch = NamedNode::new_unchecked(FX_CHILD);
for v in arr.into_iter() {
add_new_property(&ch, map);
process_value(
Expand Down
41 changes: 15 additions & 26 deletions lib/triplestore/src/map_xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,17 @@ use polars_core::prelude::IntoColumn;
use quick_xml::escape::unescape;
use quick_xml::events::Event;
use quick_xml::Reader;
use representation::constants::{
FX_CHILD, FX_CHILD_NUMBER, FX_PREFIX_NAME, FX_PREFIX_SEP, FX_ROOT, FX_XMLNS, FX_XMLNS_SEP,
FX_XYZ_PREFIX_IRI, XYZ_PREFIX_IRI,
};
use representation::dataset::NamedGraph;
use representation::series_builder::{ensure_pair, PredMap};
use representation::{BaseRDFNodeType, OBJECT_COL_NAME, SUBJECT_COL_NAME};
use std::collections::HashMap;
use std::io::Cursor;
use std::sync::Arc;

const XML_ROOT: &str = "http://sparql.xyz/facade-x/ns/root";
const XML_CHILD: &str = "http://sparql.xyz/facade-x/ns/child";
const XML_XMLNS: &str = "http://sparql.xyz/facade-x/ns/xmlns";
const XML_XMLNS_SEP: &str = "http://sparql.xyz/facade-x/ns/xmlnsSeparator";

const XML_PREFIX: &str = "http://sparql.xyz/facade-x/ns/prefix";
const XML_PREFIX_NAME: &str = "http://sparql.xyz/facade-x/ns/prefixName";
const XML_PREFIX_SEP: &str = "http://sparql.xyz/facade-x/ns/prefixSeparator";

const XML_PREFIX_IRI: &str = "http://sparql.xyz/facade-x/ns/prefixIRI";

const XML_CHILD_NUMBER: &str = "http://sparql.xyz/facade-x/ns/childNumber";

const DEFAULT_XML_DATA_PREFIX: &str = "http://sparql.xyz/facade-x/data/";

struct Frame {
subject: String,
next_child: usize,
Expand All @@ -51,7 +40,7 @@ impl Triplestore {
let string_type = Arc::new(BaseRDFNodeType::Literal(xsd::STRING.into_owned()));
datatypes_map.insert(xsd::STRING.as_str().to_string(), string_type.clone());
let mut prefix_map: HashMap<String, NamedNode> = HashMap::new();
let mut base_prefix = NamedNode::new_unchecked(DEFAULT_XML_DATA_PREFIX);
let mut base_prefix = NamedNode::new_unchecked(XYZ_PREFIX_IRI);
let mut stack: Vec<Frame> = Vec::new();
let mut buf = Vec::new();
loop {
Expand Down Expand Up @@ -157,10 +146,10 @@ fn open_element(
let parent_subject = parent.subject.clone();
let n = parent.next_child;
parent.next_child += 1;
push_iri_object(pred_map, XML_CHILD, &parent_subject, &subject);
push_iri_u32(pred_map, XML_CHILD_NUMBER, &subject, n as u32);
push_iri_object(pred_map, FX_CHILD, &parent_subject, &subject);
push_iri_u32(pred_map, FX_CHILD_NUMBER, &subject, n as u32);
} else {
push_iri_object(pred_map, rdf::TYPE.as_str(), &subject, XML_ROOT);
push_iri_object(pred_map, rdf::TYPE.as_str(), &subject, FX_ROOT);
}
let mut new_base_prefix = None;
let mut introduced_prefixed_namespaces = Vec::new();
Expand All @@ -184,10 +173,10 @@ fn open_element(
TriplestoreError::XMLError(format!("Error parsing {}: {}", value, e.to_string()))
})?;
let use_sep = use_sep(nn.as_str());
push_iri_object(pred_map, XML_XMLNS, &subject, nn.as_str());
push_iri_object(pred_map, FX_XMLNS, &subject, nn.as_str());
push_typed_text(
pred_map,
XML_XMLNS_SEP,
FX_XMLNS_SEP,
&subject,
use_sep,
&BaseRDFNodeType::Literal(xsd::STRING.into_owned()),
Expand All @@ -201,11 +190,11 @@ fn open_element(
})?;

let prefix_subject = new_iri_subject();
push_iri_object(pred_map, XML_PREFIX, &subject, &prefix_subject);
push_iri_object(pred_map, XML_PREFIX_IRI, &prefix_subject, nn.as_str());
push_iri_object(pred_map, XYZ_PREFIX_IRI, &subject, &prefix_subject);
push_iri_object(pred_map, FX_XYZ_PREFIX_IRI, &prefix_subject, nn.as_str());
let use_sep = use_sep(nn.as_str());
push_typed_text(pred_map, XML_PREFIX_SEP, &prefix_subject, use_sep, &string)?;
push_typed_text(pred_map, XML_PREFIX_NAME, &prefix_subject, pre, &string)?;
push_typed_text(pred_map, FX_PREFIX_SEP, &prefix_subject, use_sep, &string)?;
push_typed_text(pred_map, FX_PREFIX_NAME, &prefix_subject, pre, &string)?;
let previous = prefix_map.insert(pre.to_string(), nn);
introduced_prefixed_namespaces.push((pre.to_string(), previous));
} else if key == "xml:lang" {
Expand Down Expand Up @@ -254,7 +243,7 @@ fn push_text_child(
return Ok(());
};
let subject = frame.subject.clone();
push_typed_text(pred_map, XML_CHILD, &subject, text, string_type)?;
push_typed_text(pred_map, FX_CHILD, &subject, text, string_type)?;
Ok(())
}

Expand Down
9 changes: 4 additions & 5 deletions py_maplib/src/py_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::error::PyMaplibError;
use crate::mutexes::{
add_prefixes_mutex, add_template_mutex, add_virtualization_mutex, create_index_mutex,
detach_graph_mutex, get_predicate_iris_mutex, get_predicate_mutex, infer_mutex, insert_mutex,
map_default_mutex, map_json_mutex, map_mutex, map_triples_mutex, map_xml_mutex, query_mutex,
read_mutex, read_template_mutex, reads_mutex, size_mutex, truncate_graph_mutex, update_mutex,
validate_mutex, write_cim_xml_mutex, write_native_parquet_mutex, write_triples_mutex,
writes_mutex, map_df_mutex
map_default_mutex, map_df_mutex, map_json_mutex, map_mutex, map_triples_mutex, map_xml_mutex,
query_mutex, read_mutex, read_template_mutex, reads_mutex, size_mutex, truncate_graph_mutex,
update_mutex, validate_mutex, write_cim_xml_mutex, write_native_parquet_mutex,
write_triples_mutex, writes_mutex,
};
use crate::shacl::{PyValidationReport, SHACL_RESULTS_QUERY};
use crate::{
Expand Down Expand Up @@ -253,7 +253,6 @@ impl PyModel {
})
}


/// Starts a graph explorer session.
///
/// To run from Jupyter Notebook use:
Expand Down
Loading