Skip to content

Commit 73271ee

Browse files
authored
Merge pull request #316 from korpling/intermediate-relannis-version
Support "mappings" column in intermediate relANNIS format
2 parents bc80342 + e79b261 commit 73271ee

5 files changed

Lines changed: 65 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Fixed
9+
10+
- Correctly map the `mappings` column for older `resolver_vis_map.tab` files
11+
that do have a `visibility` column.
12+
813
## [3.7.0] - 2025-03-18
914

1015
### Fixed

graphannis/src/annis/db/corpusstorage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ impl CorpusStorage {
12321232
///
12331233
/// - `corpus_name` - The name of the corpus to write to the ZIP file.
12341234
/// - `use_corpus_subdirectory` - If true, the corpus is written into a sub-directory inside the ZIP file.
1235-
/// This is useful when storing multiple corpora inside the same file.
1235+
/// This is useful when storing multiple corpora inside the same file.
12361236
/// - `zip` - A [writer](zip::ZipWriter) for the already created ZIP file.
12371237
/// - `progress_callback` - A callback function to which the export progress is reported to.
12381238
pub fn export_to_zip<W, F>(

graphannis/src/annis/db/exec/nodesearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl NodeSearchSpec {
121121
| NodeSearchSpec::NotExactTokenValue { .. }
122122
| NodeSearchSpec::RegexTokenValue { .. }
123123
| NodeSearchSpec::NotRegexTokenValue { .. }
124-
| NodeSearchSpec::AnyToken { .. } => (
124+
| NodeSearchSpec::AnyToken => (
125125
Some(TOKEN_KEY.ns.clone().into()),
126126
Some(TOKEN_KEY.name.clone().into()),
127127
),

graphannis/src/annis/db/relannis.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,16 @@ where
484484
));
485485

486486
let mut resolver_tab_csv = postgresql_import_reader(resolver_tab_path.as_path())?;
487-
488487
let mut rules_by_order: Vec<(i64, bool, VisualizerRule)> = DEFAULT_VISUALIZER_RULES.clone();
489488

490-
let order_col = if is_annis_33 { 7 } else { 6 };
491-
let mapping_col = if is_annis_33 { 8 } else { 7 };
492-
493489
for result in resolver_tab_csv.records() {
494490
let line = result?;
495491

492+
let has_visibility_column = is_annis_33 || line.len() == 9;
493+
494+
let order_col = if has_visibility_column { 7 } else { 6 };
495+
let mapping_col = if has_visibility_column { 8 } else { 7 };
496+
496497
let layer = get_field(&line, 2, "namespace", &resolver_tab_path)?.map(|l| l.to_string());
497498
let element =
498499
get_field(&line, 3, "element", &resolver_tab_path)?.and_then(|e| match e.as_ref() {
@@ -503,7 +504,11 @@ where
503504
let vis_type = get_field_not_null(&line, 4, "vis_type", &resolver_tab_path)?;
504505
let display_name = get_field_not_null(&line, 5, "display_name", &resolver_tab_path)?;
505506

506-
let visibility = get_field_not_null(&line, 6, "visibility", &resolver_tab_path)?;
507+
let visibility = if has_visibility_column {
508+
get_field_not_null(&line, 6, "visibility", &resolver_tab_path)?
509+
} else {
510+
"hidden".into()
511+
};
507512

508513
let order = get_field(&line, order_col, "order", &resolver_tab_path)?
509514
.map(|order| order.parse::<i64>().unwrap_or_default())

graphannis/src/annis/db/relannis/tests.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,54 @@ fn trim_resolver_mappings() {
114114
);
115115
}
116116

117+
#[test]
118+
fn missing_visibility_column_in_resolver() {
119+
let parent = create_temporary_corpus_dir_file(
120+
r#"somecorpus NULL syntax node tree syntax (tree) 1 test: true; anothertest:false
121+
somecorpus NULL NULL NULL discourse document (text) 2 NULL"#,
122+
"resolver_vis_map.tab",
123+
);
124+
let mut config = CorpusConfiguration::default();
125+
load_resolver_vis_map(parent.path(), &mut config, false, &|_| {}).unwrap();
126+
127+
assert_eq!(8, config.visualizers.len());
128+
129+
let syntax_vis = &config.visualizers[1];
130+
assert_eq!("syntax (tree)", syntax_vis.display_name);
131+
assert_eq!(VisualizerVisibility::Hidden, syntax_vis.visibility);
132+
assert_eq!(2, syntax_vis.mappings.len());
133+
assert_eq!("true", syntax_vis.mappings.get("test").unwrap());
134+
assert_eq!("false", syntax_vis.mappings.get("anothertest").unwrap());
135+
136+
let doc_vis = &config.visualizers[2];
137+
assert_eq!("document (text)", doc_vis.display_name);
138+
assert_eq!(VisualizerVisibility::Hidden, doc_vis.visibility);
139+
assert_eq!(0, doc_vis.mappings.len());
140+
}
141+
142+
#[test]
143+
fn old_resolver_with_visibility_column() {
144+
let parent = create_temporary_corpus_dir_file(
145+
r#"somecorpus NULL NULL NULL kwic kwic removed 0 NULL
146+
somecorpus NULL inline node grid annos (grid) visible 1 hide_tok: true; annos: learner, ZH1, ZH1Diff, ZH2, ZH2Diff"#,
147+
"resolver_vis_map.tab",
148+
);
149+
let mut config = CorpusConfiguration::default();
150+
load_resolver_vis_map(parent.path(), &mut config, false, &|_| {}).unwrap();
151+
152+
assert_eq!(6, config.visualizers.len());
153+
154+
let grid_vis = &config.visualizers[0];
155+
assert_eq!("annos (grid)", grid_vis.display_name);
156+
assert_eq!(VisualizerVisibility::Visible, grid_vis.visibility);
157+
assert_eq!(2, grid_vis.mappings.len());
158+
assert_eq!("true", grid_vis.mappings.get("hide_tok").unwrap());
159+
assert_eq!(
160+
"learner, ZH1, ZH1Diff, ZH2, ZH2Diff",
161+
grid_vis.mappings.get("annos").unwrap()
162+
);
163+
}
164+
117165
#[test]
118166
fn parse_virtual_tokenization_mapping() {
119167
let parent = create_temporary_corpus_dir_file(

0 commit comments

Comments
 (0)