Skip to content

Commit

Permalink
Merge branch 'unrecognized' into origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomaz-Vieira committed Sep 19, 2024
2 parents c70ac69 + 544ea4a commit 35952d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
7 changes: 5 additions & 2 deletions bioimg_runtime/src/zoo_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{

use bioimg_spec::rdf::{
self, author::Author2, file_reference::FsPathComponent, maintainer::Maintainer, model::{
legacy::Version_0_4_X_OrEarlier, ModelRdfV0_5, RdfTypeModel
unsupported::{UnrecognizedRdf, Version_0_4_X_OrEarlier}, ModelRdfV0_5, RdfTypeModel
}, non_empty_list::NonEmptyList, version::Version_0_5_x, FileReference, FsPath, HttpUrl, LicenseId, ResourceName, Version
};
use bioimg_spec::rdf::model as modelrdf;
Expand Down Expand Up @@ -61,7 +61,9 @@ pub enum ModelLoadingError{
#[error("Invalid input/output configurtation: {0}")]
TensorValidationError(#[from] TensorValidationError),
#[error("Unsupported legacy model version: {version}")]
UnsupportedLegacyModel{version: Version_0_4_X_OrEarlier}
UnsupportedLegacyModel{version: Version_0_4_X_OrEarlier},
#[error("Unrecognized rdf data: {inner}")]
UnrecognizedRdf{inner: UnrecognizedRdf},
}

pub struct ZooModel {
Expand Down Expand Up @@ -102,6 +104,7 @@ impl ZooModel{
let model_rdf = match model_rdf{
modelrdf::ModelRdf::Legacy(legacy_model) => return Err(ModelLoadingError::UnsupportedLegacyModel { version: legacy_model.format_version }),
modelrdf::ModelRdf::V05(modern_model) => modern_model,
modelrdf::ModelRdf::Unrecognized(inner) => return Err(ModelLoadingError::UnrecognizedRdf { inner })
};

let covers: Vec<CoverImage> = model_rdf.covers.into_iter()
Expand Down
8 changes: 5 additions & 3 deletions bioimg_spec/src/rdf/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use self::legacy::UnsupportedLegacyModel;
use self::unsupported::UnsupportedLegacyModel;

use super::BoundedString;

Expand All @@ -18,7 +18,7 @@ pub mod time_unit;
pub mod weights;
pub mod run_mode;
pub mod dataset_descr;
pub mod legacy;
pub mod unsupported;
pub mod model_rdf_0_5;

pub use axes::{
Expand All @@ -31,6 +31,7 @@ pub use axes::input_axes::{InputAxis, InputAxisGroup, SpaceInputAxis, TimeInputA
pub use axes::output_axes::{OutputAxis, OutputAxisGroup, SpaceOutputAxis, TimeOutputAxis};
pub use axis_size::{AnyAxisSize, AxisSizeReference, FixedAxisSize, ParameterizedAxisSize, QualifiedAxisId, ResolvedAxisSize};
pub use input_tensor::InputTensorDescr;
use unsupported::UnrecognizedRdf;
pub use output_tensor::OutputTensorDescr;
pub use space_unit::SpaceUnit;
pub use tensor_id::TensorId;
Expand Down Expand Up @@ -85,5 +86,6 @@ pub type ModelRdfName = BoundedString<5, 1024>;
#[serde(untagged)]
pub enum ModelRdf{
Legacy(UnsupportedLegacyModel),
V05(ModelRdfV0_5)
V05(ModelRdfV0_5),
Unrecognized(UnrecognizedRdf),
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@ pub struct UnsupportedLegacyModel{
/// The `format_version` is important for any consumer software to understand how to parse the fields.
pub format_version: Version_0_4_X_OrEarlier,
}

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct UnrecognizedRdf{
#[serde(default)]
pub format_version: Option<String>
}

impl Display for UnrecognizedRdf{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(format_version) = &self.format_version{
write!(f, "This seems like a model RDF from a version that is not supported by this program: {format_version}. ")
}else{
write!(f, "Data doesn't look like a model RDF; It even lacks the 'format_version' field")
}
}
}

0 comments on commit 35952d7

Please sign in to comment.