Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add hci converter #23

Merged
merged 28 commits into from
Feb 19, 2025
Merged

feat: add hci converter #23

merged 28 commits into from
Feb 19, 2025

Conversation

sabinem
Copy link
Member

@sabinem sabinem commented Feb 14, 2025

This PR adds the HCI converter together with tests:

An example for the expected HCI input data is provided at examples/0-HCI.json

The commands for running the converters was changed:

  • run synth-converter with just run-synth examples/1-Synth.json examples/1-Synth.ttl
  • run hci-converter with just run-hci examples/0-HCI.json examples/0-HCI.ttl
  • run tests with just test

Note: We are not checking enums yet and leave that to the Shacl Validation: such as

   sh:property [sh:path allo-qual:AFQ_0000111 ;
                sh:xone ([ sh:hasValue "Solid"]
                        [sh:hasValue "Liquid"]) ; ] ; #state of matter / dispense state 

We only check them where they are of importance for the transformation such as to identify the action type in a batch. The validation of the values is currently left to the Shacl Validation, which makes the parsing a bit lighter and is okay from my perspective.

TODOs

@sabinem sabinem mentioned this pull request Feb 14, 2025
@sabinem sabinem requested review from cmdoret and vancauwe February 14, 2025 05:33
@cmdoret cmdoret changed the title Feat/add hci converter feat: add hci converter Feb 14, 2025
Copy link
Member

@cmdoret cmdoret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Got a few questions, but no major issue 👍

Copy link
Contributor

@vancauwe vancauwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work !
It's also nice to see that the catplus-common fits in nicely.
I have one suggestion that would be nice-to-have for subsequent edits, but I can also take care of the small change during Agilent parser.

@sabinem
Copy link
Member Author

sabinem commented Feb 17, 2025

@cmdoret Thanks a lot for your review and most of your point make a lot of sense. As a general rule, I think it would be good to not add commits on a PR that you review, since that makes it harder to continue to work on it. At least in case you add a commit you should also point that out in a comment. I just noticed this when I tried to push my changes and had to first put them on another branch in order to pull the changed upstream first. It is okay for now, just maybe for next time.

@sabinem
Copy link
Member Author

sabinem commented Feb 18, 2025

@vancauwe , @cmdoret With these changes it does not make sense to have a synth converter and an hci converter anymore: I will make just one metadata-converter that takes an extra argument synth or hci, since the difference between the two is now just one or two lines of code: it is just the name of the struct it parses.

@cmdoret
Copy link
Member

cmdoret commented Feb 18, 2025

@sabinem indeed sorry about that, I will set up formatting and CI to at least notify and check that the PR is formatted before accepting merges (without creating commits).

Copy link
Member

@cmdoret cmdoret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good to me! I only have a minor suggestion and a nitpick which we can keep for a later PR.
Feel free to merge :)

cargo run --bin hci-converter "{{root_dir}}/{{input_file}}" "{{root_dir}}/{{output_file}}" {{args}}
run input_type input_file output_file *args:
cd "{{root_dir}}/src/converter" && \
cargo run --bin converter "{{input_type}}" "{{root_dir}}/{{input_file}}" "{{root_dir}}/{{output_file}}" {{args}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cargo run --bin converter "{{input_type}}" "{{root_dir}}/{{input_file}}" "{{root_dir}}/{{output_file}}" {{args}}
cargo run --bin converter "{{input_type}}" "{{input_file}}" "{{output_file}}" {{args}}

suggestion: the command is already executed from the root dir, I don't think we need to prefix individual arguments. Removing those prefixes also allows to specify external files via absolute path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmdoret I tried this but it did not work for me.

The current command is like this:

run input_type input_file output_file *args:
    cd "{{root_dir}}/src/converter" && \
    cargo run --bin converter "{{input_type}}" "{{root_dir}}/{{input_file}}" "{{root_dir}}/{{output_file}}" {{args}}

It works from everywhere in the projects directory tree and you first go down to {{root_dir}}/src/converter and then it searches from there if you don't add {{root_dir}} again. So I leave it as it is now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: the CLI is much better like this, I think this is a good design that we can keep building on.

"jsonld" => {
graph_builder.serialize_to_jsonld().context("Failed to serialize to JSON-LD")?
}
_ => graph_builder.serialize_to_turtle().context("Failed to serialize to Turtle")?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: I would expect "nt" to return ntriples, but it would silently return ttl.
nitpick: match "turtle" to the proper serializer and panic or return an error in the default case.

Comment on lines +16 to +25
macro_rules! ns_entries_direct { // For rdf and xsd
($msg:expr, $($ns:ident),*) => {
vec![
$(
(stringify!($ns), $ns.get("").expect(&$msg)),
)*
]
};
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: smart solution! looks like a good use of macros 👍

@sabinem
Copy link
Member Author

sabinem commented Feb 19, 2025

@cmdoret I followed up on your suggestions. Please dev review again.

@sabinem sabinem force-pushed the feat/add-hci-converter branch from b110af1 to 5f69d07 Compare February 19, 2025 09:24
@sabinem sabinem merged commit 7481178 into main Feb 19, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants