From bed0680b704c9a0acabcc97f0f237c54d6e03a6b Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Thu, 4 Aug 2022 19:23:25 +0200 Subject: [PATCH] fix in reading context rules --- bindings/python/Cargo.toml | 2 +- src/lib.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index ce50129..0bca7fb 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -9,7 +9,7 @@ license = "GPL-3.0+" name = "analiticcl-python" readme = "README.md" repository = "https://github.com/proycon/analiticcl" -version = "0.4.3" #also change version in dependencies below +version = "0.4.2" #also change version in dependencies below [lib] name = "analiticcl" diff --git a/src/lib.rs b/src/lib.rs index 25854e7..30dc021 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -496,8 +496,8 @@ impl VariantModel { let f_buffer = BufReader::new(f); let mut linenr = 0; for line in f_buffer.lines() { - linenr += 1; if let Ok(line) = line { + linenr += 1; if !line.is_empty() && !line.starts_with('#') { let fields: Vec<&str> = line.split("\t").collect(); if fields.len() < 2 { @@ -505,9 +505,13 @@ impl VariantModel { } let pattern: &str = fields.get(0).unwrap(); + if pattern.is_empty() { + continue; + } + let score = fields.get(1).unwrap().parse::(); if let Err(_) = score { - return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("context rule score should be a floating point value above or below 1.0 ({}, line {})", filename,linenr))); + return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("context rule score should be a floating point value above or below 1.0, got {} ({}, line {})", fields.get(1).unwrap(), filename,linenr))); } let score = score.unwrap(); @@ -524,11 +528,11 @@ impl VariantModel { if tag.len() == 1 && tagoffset.len() == 0 { tagoffset.push("0:"); } else if tag.len() != tagoffset.len() { - return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Multiple tags are specified for a context rule, expected the same number of tag offsets! (semicolon separated) ({}, line {}", filename, linenr))); + return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Multiple tags are specified for a context rule, expected the same number of tag offsets! (semicolon separated) ({}, line {})", filename, linenr))); } if let Err(error) = self.add_contextrule(pattern, score, tag, tagoffset) { - return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Error adding context rule: {} ({}, line {}", error, filename, linenr))); + return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Error adding context rule: {} ({}, line {})", error, filename, linenr))); } }