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

Fix/anno mapper #125

Merged
merged 2 commits into from
Aug 14, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- mapping annotations now correctly extracts the id of the node to apply a new annotation to

## [0.3.1] - 2023-08-04

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion src/manipulator/map_annos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@

pub const MODULE_NAME: &str = "map_annotations";

#[derive(Deserialize)]

Check warning on line 22 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

22 line is not covered with tests
pub struct MapAnnos {
rule_file: PathBuf,
}

impl Module for MapAnnos {
fn module_name(&self) -> &str {
MODULE_NAME
}

Check warning on line 30 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

28-30 lines are not covered with tests
}

impl Manipulator for MapAnnos {
fn manipulate_corpus(
&self,
graph: &mut graphannis::AnnotationGraph,
workflow_directory: &std::path::Path,
tx: Option<crate::workflow::StatusSender>,
) -> Result<(), Box<dyn std::error::Error>> {
let read_from_path = {
let p = Path::new(&self.rule_file).to_path_buf();
if p.is_relative() {
workflow_directory.join(p)

Check warning on line 43 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

34-43 lines are not covered with tests
} else {
p

Check warning on line 45 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

45 line is not covered with tests
}
};
let mapping = read_config(read_from_path.as_path())?;
self.run(graph, mapping, &tx)?;
Ok(())
}

Check warning on line 51 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

48-51 lines are not covered with tests
}

impl MapAnnos {
Expand Down Expand Up @@ -77,7 +77,10 @@
graphannis::corpusstorage::ResultOrder::NotSorted,
)?;
for m in search_results {
let matching_nodes = m.split(' ').map(|s| s.to_string()).collect_vec();
let matching_nodes = m
.split(' ')
.filter_map(|s| s.rsplit("::").last())
.collect_vec();
let target = rule.target - 1;
if let Some(node_name) = matching_nodes.get(target) {
update.add_event(UpdateEvent::AddNodeLabel {
Expand All @@ -86,7 +89,7 @@
anno_name: rule.name.to_string(),
anno_value: rule.value.to_string(),
})?;
}

Check warning on line 92 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

92 line is not covered with tests
}
}
graph.apply_update(&mut update, |_| {})?;
Expand All @@ -94,11 +97,11 @@
}
}

fn read_config(path: &Path) -> Result<Mapping, Box<dyn std::error::Error>> {
let config_string = fs::read_to_string(path)?;
let m: Mapping = toml::from_str(config_string.as_str())?;
Ok(m)
}

Check warning on line 104 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

100-104 lines are not covered with tests

#[derive(Deserialize)]
struct Mapping {
Expand Down Expand Up @@ -235,14 +238,14 @@
for (e_qname, g_qname) in e_name_iter.zip(g_name_iter) {
assert_eq!(
e_qname, g_qname,
"Differing annotation keys between expected and generated graph: `{:?}` vs. `{:?}`",

Check warning on line 241 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

241 line is not covered with tests
e_qname, g_qname
);
}
assert_eq!(
e_anno_names.len(),
g_anno_names.len(),
"Expected graph and generated graph do not contain the same number of annotation keys."

Check warning on line 248 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

248 line is not covered with tests
);
let e_c_list = e_g
.get_all_components(None, None)
Expand All @@ -257,9 +260,9 @@
assert_eq!(
e_c_list.len(),
g_c_list.len(),
"components expected:\n{:?};\ncomponents are:\n{:?}",
&e_c_list,
&g_c_list

Check warning on line 265 in src/manipulator/map_annos.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

263-265 lines are not covered with tests
);
for c in e_c_list {
let candidates = g.get_all_components(Some(c.get_type()), Some(c.name.as_str()));
Expand Down
Loading