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

More error massages #43

Merged
merged 1 commit into from
Oct 25, 2024
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: 2 additions & 2 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl FromStr for Metric {
let re = Regex::new(r"^(?<metric>[a-z1-9_]+)(@(?<k>\d+))?$").unwrap();
let caps = re
.captures(s)
.ok_or_else(|| ElinorError::InvalidFormat(s.to_string()))?;
.ok_or_else(|| ElinorError::InvalidFormat(format!("Unsupported metric: {s}")))?;
let name = caps.name("metric").unwrap().as_str();
let k = caps
.name("k")
Expand Down Expand Up @@ -328,7 +328,7 @@ where
{
for query_id in pred_rels.query_ids() {
if true_rels.get_map(query_id).is_none() {
return Err(ElinorError::MissingEntry(format!("Query ID: {query_id}")));
return Err(ElinorError::MissingEntry(format!("true_rels[{query_id}]")));
}
}
let mut results = BTreeMap::new();
Expand Down
6 changes: 4 additions & 2 deletions src/relevance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<K, T> RelevanceStoreBuilder<K, T> {
let rels = self.map.entry(query_id.clone()).or_default();
if rels.contains_key(&doc_id) {
return Err(ElinorError::DuplicateEntry(format!(
"Query: {query_id}, Doc: {doc_id}"
"Input query-doc pair must be unique, but got query_id={query_id}, doc_id={doc_id}"
)));
}
rels.insert(doc_id, score);
Expand Down Expand Up @@ -393,7 +393,9 @@ mod tests {
b.add_record('a', 'x', 1).unwrap();
assert_eq!(
b.add_record('a', 'x', 2),
Err(ElinorError::DuplicateEntry("Query: a, Doc: x".to_string()))
Err(ElinorError::DuplicateEntry(
"Input query-doc pair must be unique, but got query_id=a, doc_id=x".to_string()
))
);
}
}
23 changes: 15 additions & 8 deletions src/trec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ where
let line = line.as_ref();
let rows = line.split_whitespace().collect::<Vec<_>>();
if rows.len() < 4 {
return Err(ElinorError::InvalidFormat(line.to_string()));
return Err(ElinorError::InvalidFormat(format!(
"Qrels line must have four columns at least, but got {line}"
)));
}
let query_id = rows[0].to_string();
let doc_id = rows[2].to_string();
let score = rows[3]
.parse::<i32>()
.map_err(|_| ElinorError::InvalidFormat(format!("Invalid score: {}", rows[3])))?;
let score = rows[3].parse::<i32>().map_err(|_| {
ElinorError::InvalidFormat(format!(
"The fourth column must be i32, but got {}",
rows[3]
))
})?;
let score = TrueScore::try_from(score.max(0)).unwrap();
b.add_record(query_id, doc_id, score)?;
}
Expand Down Expand Up @@ -106,13 +111,15 @@ where
let line = line.as_ref();
let rows = line.split_whitespace().collect::<Vec<_>>();
if rows.len() < 5 {
return Err(ElinorError::InvalidFormat(line.to_string()));
return Err(ElinorError::InvalidFormat(format!(
"Run line must have five columns at least, but got {line}"
)));
}
let query_id = rows[0].to_string();
let doc_id = rows[2].to_string();
let score = rows[4]
.parse::<PredScore>()
.map_err(|_| ElinorError::InvalidFormat(format!("Invalid score: {}", rows[4])))?;
let score = rows[4].parse::<PredScore>().map_err(|_| {
ElinorError::InvalidFormat(format!("The fifth column must be f32, but got {}", rows[4]))
})?;
b.add_record(query_id, doc_id, score)?;
}
Ok(b.build())
Expand Down
Loading