Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 5f2b38f

Browse files
authored
Merge pull request #54 from sdsc-ordes/fix/ontology-sync
fix: ontology sync
2 parents c56ebea + 5e3bb09 commit 5f2b38f

File tree

10 files changed

+413
-376
lines changed

10 files changed

+413
-376
lines changed

src/catplus-common/src/graph/namespaces/cat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace! {
5757
Observation,
5858
optimizationType,
5959
order,
60-
Peak,
60+
peak,
6161
PeakList,
6262
Plate,
6363
ProcessedDataDocument,

src/catplus-common/src/graph/utils.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::graph::namespaces::cat_resource;
12
use base64::{engine::general_purpose, Engine as _};
23
use sha2::{Digest, Sha256};
34
use sophia_api::{
@@ -20,3 +21,9 @@ pub(crate) fn hash_identifier(identifier: &str) -> String {
2021
let result = hasher.finalize();
2122
general_purpose::URL_SAFE_NO_PAD.encode(result)
2223
}
24+
25+
pub fn generate_resource_identifier_uri(resource_id: String) -> SimpleTerm<'static> {
26+
let mut uri = cat_resource::ns.clone().as_str().to_owned();
27+
uri.push_str(&hash_identifier(&resource_id));
28+
IriRef::new_unchecked(uri).try_into_term().expect("Failed to convert to SimpleTerm")
29+
}

src/catplus-common/src/models/agilent.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
graph::{
33
insert_into::{InsertIntoGraph, Link},
4-
namespaces::{allodc, allores, allorole, cat, cat_resource, obo, purl, qb, qudt},
5-
utils::hash_identifier,
4+
namespaces::{allodc, allores, allorole, cat, obo, purl, qb, qudt},
5+
utils::generate_resource_identifier_uri,
66
},
77
models::{core::PeakList, enums::Unit},
88
};
@@ -100,9 +100,6 @@ impl InsertIntoGraph for MeasurementAggregateDocument {
100100
pub struct MeasurementDocument {
101101
#[serde(rename = "measurement identifier")]
102102
pub measurement_identifier: String,
103-
// TO-DO: needs further definition to be integrated
104-
// #[serde(rename = "chromatography column document")]
105-
// pub chromatography_column_document: ChromatographyColumnDocument,
106103
#[serde(rename = "device control aggregate document")]
107104
pub device_control_aggregate_document: DeviceSystemDocument,
108105
#[serde(rename = "sample document")]
@@ -148,23 +145,6 @@ impl InsertIntoGraph for MeasurementDocument {
148145
}
149146
}
150147

151-
#[derive(Clone, Debug, Serialize, Deserialize)]
152-
pub struct ChromatographyColumnDocument {}
153-
154-
impl InsertIntoGraph for ChromatographyColumnDocument {
155-
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
156-
for (pred, value) in
157-
[(rdf::type_, &cat::ChromatographyColumnDocument.as_simple() as &dyn InsertIntoGraph)]
158-
{
159-
value.attach_into(
160-
graph,
161-
Link { source_iri: iri.clone(), pred: pred.as_simple(), target_iri: None },
162-
)?;
163-
}
164-
Ok(())
165-
}
166-
}
167-
168148
#[derive(Clone, Debug, Serialize, Deserialize)]
169149
pub struct DeviceSystemDocument {
170150
#[serde(alias = "device document", alias = "device control document")]
@@ -215,9 +195,7 @@ pub struct DeviceDocument {
215195
impl InsertIntoGraph for DeviceDocument {
216196
fn get_uri(&self) -> SimpleTerm<'static> {
217197
// build URI based on self.device_identifier
218-
let mut uri = cat_resource::ns.clone().as_str().to_owned();
219-
uri.push_str(&hash_identifier(&self.device_identifier));
220-
IriRef::new_unchecked(uri).try_into_term().unwrap()
198+
generate_resource_identifier_uri(self.device_identifier.clone())
221199
}
222200

223201
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
@@ -296,6 +274,11 @@ pub struct AgilentProduct {
296274
}
297275

298276
impl InsertIntoGraph for AgilentProduct {
277+
fn get_uri(&self) -> SimpleTerm<'static> {
278+
//same as in synth.rs set_product_uri function
279+
//same as in bravo.rs get_uri function for BravoProduct
280+
generate_resource_identifier_uri(self.product_identifier.clone())
281+
}
299282
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
300283
for (pred, value) in [
301284
(rdf::type_, &cat::Product.as_simple() as &dyn InsertIntoGraph),

src/catplus-common/src/models/bravo.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
graph::{
33
insert_into::{InsertIntoGraph, Link},
44
namespaces::{alloprop, alloqual, allores, cat, purl},
5+
utils::generate_resource_identifier_uri,
56
},
67
models::{
78
core::{Chemical, Observation, Plate, Well},
@@ -13,6 +14,7 @@ use serde::{Deserialize, Serialize};
1314
use sophia::{
1415
api::ns::{rdf, xsd},
1516
inmem::graph::LightGraph,
17+
iri::IriRef,
1618
};
1719
use sophia_api::term::{SimpleTerm, Term};
1820

@@ -60,7 +62,7 @@ pub struct BravoAction {
6062
pub start_duration: Option<Observation>,
6163
pub ending_duration: Option<Observation>,
6264
pub order: Option<String>,
63-
pub product_identification: ProductIdentification,
65+
pub product_identification: BravoProduct,
6466
}
6567

6668
impl InsertIntoGraph for BravoAction {
@@ -191,14 +193,19 @@ impl InsertIntoGraph for BravoWell {
191193

192194
#[derive(Clone, Debug, Serialize, Deserialize)]
193195
#[serde(rename_all = "camelCase")]
194-
pub struct ProductIdentification {
196+
pub struct BravoProduct {
195197
#[serde(rename = "sampleID")]
196198
pub sample_id: String,
197199
// Peak identifier is added on the action, not on the product
198200
pub peak_identifier: String,
199201
}
200202

201-
impl InsertIntoGraph for ProductIdentification {
203+
impl InsertIntoGraph for BravoProduct {
204+
fn get_uri(&self) -> SimpleTerm<'static> {
205+
//same as in synth.rs set_product_uri function
206+
//same as in agilent.rs get_uri function for AgilentProduct
207+
generate_resource_identifier_uri(self.sample_id.clone())
208+
}
202209
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
203210
for (pred, value) in [
204211
(rdf::type_, &cat::Product.as_simple() as &dyn InsertIntoGraph),

src/catplus-common/src/models/core.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,27 @@ impl InsertIntoGraph for PeakList {
154154
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
155155
for (pred, value) in [
156156
(rdf::type_, &cat::PeakList.as_simple() as &dyn InsertIntoGraph),
157-
(cat::Peak, &self.peak),
157+
(cat::peak, &self.peak),
158158
] {
159159
value.attach_into(
160160
graph,
161161
Link { source_iri: iri.clone(), pred: pred.as_simple(), target_iri: None },
162162
)?;
163163
}
164+
let product = cat::Product.as_simple();
165+
let rdf_type = rdf::type_.as_simple();
166+
167+
let product_object = graph.triples().filter_map(Result::ok).find_map(|[s, p, o]| {
168+
if *p == rdf_type && *o == product {
169+
Some(s.clone())
170+
} else {
171+
None
172+
}
173+
});
174+
175+
if let Some(subject) = product_object {
176+
graph.insert(iri.clone(), cat::hasProduct.as_simple(), subject)?;
177+
}
164178
Ok(())
165179
}
166180
}

src/catplus-common/src/models/synth.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
graph::{
33
insert_into::{InsertIntoGraph, Link},
4-
namespaces::{alloproc, alloprop, alloqual, allores, cat, cat_resource, purl, qudt},
5-
utils::hash_identifier,
4+
namespaces::{alloproc, alloprop, alloqual, allores, cat, purl, qudt},
5+
utils::generate_resource_identifier_uri,
66
},
77
models::{
88
core::{Chemical, Observation, Plate},
@@ -31,12 +31,16 @@ pub struct SynthBatch {
3131
pub actions: Vec<SynthAction>,
3232
}
3333

34+
fn set_product_uri(product_id: String) -> SimpleTerm<'static> {
35+
//same as in agilent.rs get_uri function for AgilentProduct
36+
//same as in bravo.rs get_uri function for BravoProduct
37+
generate_resource_identifier_uri(product_id.clone())
38+
}
39+
3440
impl InsertIntoGraph for SynthBatch {
3541
fn get_uri(&self) -> SimpleTerm<'static> {
3642
// build URI based on self.batch_id
37-
let mut uri = cat_resource::ns.clone().as_str().to_owned();
38-
uri.push_str(&hash_identifier(&self.batch_id));
39-
IriRef::new_unchecked(uri).try_into_term().unwrap()
43+
generate_resource_identifier_uri(self.batch_id.clone())
4044
}
4145

4246
fn insert_into(&self, graph: &mut LightGraph, iri: SimpleTerm) -> anyhow::Result<()> {
@@ -64,7 +68,8 @@ impl InsertIntoGraph for SynthBatch {
6468
// Create the product_id from container_id and position
6569
let product_id =
6670
format!("{}-{}", &well.has_plate.container_id, well.position);
67-
let new_product_uri = well.get_uri();
71+
//let new_product_uri = well.get_uri();
72+
let new_product_uri = set_product_uri(product_id.clone());
6873
for (pred, value) in [
6974
(
7075
rdf::type_,
@@ -169,7 +174,7 @@ impl InsertIntoGraph for SynthAction {
169174
(allores::AFR_0001606, &self.method_name.as_simple()),
170175
(allores::AFR_0001723, &self.equipment_name.as_simple()),
171176
(cat::subEquipmentName, &self.sub_equipment_name.as_simple()),
172-
(cat::speedInRPM, &self.speed_shaker),
177+
(alloprop::AFX_0000211, &self.speed_shaker),
173178
(cat::temperatureTumbleStirrer, &self.temperature_tumble_stirrer),
174179
(alloprop::AFX_0000211, &self.speed_tumble_stirrer),
175180
(cat::vacuum, &self.vacuum),

0 commit comments

Comments
 (0)