Skip to content

Commit

Permalink
Rename to Elinor (#4)
Browse files Browse the repository at this point in the history
* rename

* rename

* minor
  • Loading branch information
kampersanda authored Sep 15, 2024
1 parent ca541d4 commit 488d9c8
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 71 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Build ireval-evaluate
run: cargo build --release -p ireval-evaluate
- name: Build elinor-evaluate
run: cargo build --release -p elinor-evaluate
- name: Run correctness test
run: python scripts/compare_with_trec_eval.py target/release/ireval-evaluate
run: python scripts/compare_with_trec_eval.py target/release/elinor-evaluate
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ireval"
name = "elinor"
version = "0.1.0"
edition = "2021"

Expand All @@ -17,7 +17,7 @@ maplit = "1.0.2"
rstest = "0.22.0"

[workspace]
members = ["ireval-evaluate"]
members = ["elinor-evaluate"]

[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "katex.html"]
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Information Retrieval Evaluation Library in Rust
# Elinor: Evaluation Library in Information Retrieval

<p align="left">
<a href="https://github.com/kampersanda/ireval/actions/workflows/rust.yml?query=branch%3Amain"><img src="https://img.shields.io/github/actions/workflow/status/kampersanda/ireval/rust.yml?branch=main&style=flat-square" alt="actions status" /></a>
<a href="https://github.com/kampersanda/elinor/actions/workflows/rust.yml?query=branch%3Amain"><img src="https://img.shields.io/github/actions/workflow/status/kampersanda/elinor/rust.yml?branch=main&style=flat-square" alt="actions status" /></a>
&nbsp;
<a href="https://crates.io/crates/ireval"><img src="https://img.shields.io/crates/v/ireval.svg?style=flat-square" alt="Crates.io version" /></a>
<a href="https://crates.io/crates/elinor"><img src="https://img.shields.io/crates/v/elinor.svg?style=flat-square" alt="Crates.io version" /></a>
&nbsp;
<a href="https://docs.rs/ireval"><img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square" alt="docs.rs docs" /></a>
<a href="https://docs.rs/elinor"><img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square" alt="docs.rs docs" /></a>
</p>

This is a Rust library for evaluating information retrieval systems,
Elinor is a Rust library for evaluating information retrieval systems,
which is inspired by [ranx](https://github.com/AmenRa/ranx).

## Features
Expand All @@ -22,7 +22,7 @@ which is inspired by [ranx](https://github.com/AmenRa/ranx).

## Documentation

See https://docs.rs/ireval/.
See https://docs.rs/elinor/.

Or, you can build and open the documentation locally
by running the following command:
Expand All @@ -37,7 +37,7 @@ A simple routine to prepare Qrels and Run data
and evaluate them using Precision@3, MAP, MRR, and nDCG@3:

```rust
use ireval::{QrelsBuilder, RunBuilder, Metric};
use elinor::{QrelsBuilder, RunBuilder, Metric};

// Construct Qrels data.
let mut qb = QrelsBuilder::new();
Expand Down Expand Up @@ -68,7 +68,7 @@ let metrics = vec![
];

// Evaluate the qrels and run data.
let evaluated = ireval::evaluate(&qrels, &run, metrics.iter().cloned())?;
let evaluated = elinor::evaluate(&qrels, &run, metrics.iter().cloned())?;

// Macro-averaged scores.
for metric in &metrics {
Expand All @@ -81,7 +81,7 @@ for metric in &metrics {
// => ndcg@3: 0.4751
```

Other examples are available in the [`examples`](https://github.com/kampersanda/ireval/tree/main/examples) directory.
Other examples are available in the [`examples`](https://github.com/kampersanda/elinor/tree/main/examples) directory.

## Licensing

Expand Down
4 changes: 2 additions & 2 deletions ireval-evaluate/Cargo.toml → elinor-evaluate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "ireval-evaluate"
name = "elinor-evaluate"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.17", features = ["derive"] }
ireval = { path = ".." }
elinor = { path = ".." }
6 changes: 3 additions & 3 deletions ireval-evaluate/src/main.rs → elinor-evaluate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::path::Path;
use std::path::PathBuf;

use clap::Parser;
use ireval::trec;
use ireval::Metric;
use elinor::trec;
use elinor::Metric;

#[derive(Parser, Debug)]
#[command(version, about)]
Expand All @@ -28,7 +28,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let run = trec::parse_run_from_trec(load_lines(&args.run_file)?.into_iter())?;

let metrics = all_metrics(&args.ks);
let evaluated = ireval::evaluate(&qrels, &run, metrics.iter().cloned())?;
let evaluated = elinor::evaluate(&qrels, &run, metrics.iter().cloned())?;

for metric in &metrics {
let score = evaluated.mean_scores[metric];
Expand Down
8 changes: 4 additions & 4 deletions examples/from_trec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use ireval::Metric;
use elinor::Metric;

fn main() -> Result<()> {
// <QueryID> <Dummy> <DocID> <Relevance>
Expand All @@ -23,8 +23,8 @@ q_2 0 d_4 3 0.1 SAMPLE
"
.trim();

let qrels = ireval::trec::parse_qrels_from_trec(qrels_data.lines())?;
let run = ireval::trec::parse_run_from_trec(run_data.lines())?;
let qrels = elinor::trec::parse_qrels_from_trec(qrels_data.lines())?;
let run = elinor::trec::parse_run_from_trec(run_data.lines())?;

let metrics = vec![
Metric::Hits { k: 3 },
Expand All @@ -37,7 +37,7 @@ q_2 0 d_4 3 0.1 SAMPLE
Metric::NDCG { k: 3 },
Metric::NDCGBurges { k: 3 },
];
let evaluated = ireval::evaluate(&qrels, &run, metrics.iter().cloned())?;
let evaluated = elinor::evaluate(&qrels, &run, metrics.iter().cloned())?;

println!("=== Mean scores ===");
for metric in &metrics {
Expand Down
8 changes: 4 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use ireval::Metric;
use ireval::QrelsBuilder;
use ireval::RunBuilder;
use elinor::Metric;
use elinor::QrelsBuilder;
use elinor::RunBuilder;

fn main() -> Result<()> {
let mut qb = QrelsBuilder::new();
Expand All @@ -27,7 +27,7 @@ fn main() -> Result<()> {
"mrr".parse()?,
"ndcg@3".parse()?,
];
let evaluated = ireval::evaluate(&qrels, &run, metrics.iter().cloned())?;
let evaluated = elinor::evaluate(&qrels, &run, metrics.iter().cloned())?;

println!("=== Mean scores ===");
for metric in &metrics {
Expand Down
22 changes: 11 additions & 11 deletions scripts/compare_with_trec_eval.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Script to check the correctness of ireval by comparing its output with trec_eval.
Script to check the correctness of elinor by comparing its output with trec_eval.
Usage:
$ python3 ./scripts/compare_with_trec_eval.py ./target/release/ireval-evaluate
$ python3 ./scripts/compare_with_trec_eval.py ./target/release/elinor-evaluate
"""

import argparse
Expand Down Expand Up @@ -36,10 +36,10 @@ def run_trec_eval() -> dict[str, str]:
return parsed


def run_ireval(ireval_exe: str) -> dict[str, str]:
def run_elinor(elinor_exe: str) -> dict[str, str]:
ks = [0, 1, 5, 10, 15, 20, 30, 100, 200, 500, 1000]
command = (
f"{ireval_exe} -q trec_eval-9.0.8/test/qrels.test -r trec_eval-9.0.8/test/results.test"
f"{elinor_exe} -q trec_eval-9.0.8/test/qrels.test -r trec_eval-9.0.8/test/results.test"
+ "".join([f" -k {k}" for k in ks])
)
result = subprocess.run(command, capture_output=True, shell=True)
Expand All @@ -54,12 +54,12 @@ def run_ireval(ireval_exe: str) -> dict[str, str]:

if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("ireval_exe")
p.add_argument("elinor_exe")
args = p.parse_args()

download_trec_eval()
trec_results = run_trec_eval()
ireval_results = run_ireval(args.ireval_exe)
elinor_results = run_elinor(args.elinor_exe)

ks = [5, 10, 15, 20, 30, 100, 200, 500, 1000]

Expand All @@ -82,12 +82,12 @@ def run_ireval(ireval_exe: str) -> dict[str, str]:

failed_rows = []

print("trec_metric\tireval_metric\ttrec_score\tireval_score\tmatch")
for trec_metric, ireval_metric in metric_pairs:
print("trec_metric\telinor_metric\ttrec_score\telinor_score\tmatch")
for trec_metric, elinor_metric in metric_pairs:
trec_score = trec_results[trec_metric]
ireval_score = ireval_results[ireval_metric]
match = trec_score == ireval_score
row = f"{trec_metric}\t{ireval_metric}\t{trec_score}\t{ireval_score}\t{match}"
elinor_score = elinor_results[elinor_metric]
match = trec_score == elinor_score
row = f"{trec_metric}\t{elinor_metric}\t{trec_score}\t{elinor_score}\t{match}"
if not match:
failed_rows.append(row)
print(row)
Expand Down
6 changes: 3 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Error handling for Ireval.
//! Error handling for Elinor.
use thiserror::Error;

/// Error types for Ireval.
/// Error types for Elinor.
#[derive(Error, Debug, PartialEq, Eq)]
pub enum EmirError {
pub enum ElinorError {
/// Error when an entry is duplicated.
#[error("{0}")]
DuplicateEntry(String),
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! # Information Retrieval Evaluation Library
//! # Elinor: Evaluation Library in Information Retrieval
//!
//! This is a Rust library for evaluating information retrieval systems,
//! Elinor is a Rust library for evaluating information retrieval systems,
//! which is inspired by [ranx](https://github.com/AmenRa/ranx).
//!
//! ## Features
Expand All @@ -24,7 +24,7 @@
//!
//! ```
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use ireval::{QrelsBuilder, RunBuilder, Metric};
//! use elinor::{QrelsBuilder, RunBuilder, Metric};
//!
//! // Construct Qrels data.
//! let mut qb = QrelsBuilder::new();
Expand Down Expand Up @@ -55,7 +55,7 @@
//! ];
//!
//! // Evaluate the qrels and run data.
//! let evaluated = ireval::evaluate(&qrels, &run, metrics.iter().cloned())?;
//! let evaluated = elinor::evaluate(&qrels, &run, metrics.iter().cloned())?;
//!
//! // Macro-averaged scores.
//! for metric in &metrics {
Expand All @@ -70,7 +70,7 @@
//! # }
//! ```
//!
//! Other examples are available in the [`examples`](https://github.com/kampersanda/ireval/tree/main/examples) directory.
//! Other examples are available in the [`examples`](https://github.com/kampersanda/elinor/tree/main/examples) directory.
#![deny(missing_docs)]

pub mod errors;
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn evaluate<K, M>(
qrels: &Qrels<K>,
run: &Run<K>,
metrics: M,
) -> Result<Evaluated<K>, errors::EmirError>
) -> Result<Evaluated<K>, errors::ElinorError>
where
K: Clone + Eq + std::hash::Hash + std::fmt::Display,
M: IntoIterator<Item = Metric>,
Expand Down
18 changes: 9 additions & 9 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::str::FromStr;

use regex::Regex;

use crate::errors::EmirError;
use crate::errors::ElinorError;
use crate::GoldScore;
use crate::Qrels;
use crate::Run;
Expand All @@ -32,7 +32,7 @@ pub(crate) const RELEVANT_LEVEL: GoldScore = 1;
/// instantiating a [`Metric`] from a string, as follows:
///
/// ```rust
/// use ireval::Metric;
/// use elinor::Metric;
///
/// assert_eq!("hits".parse::<Metric>(), Ok(Metric::Hits { k: 0 }));
/// assert_eq!("hits@3".parse::<Metric>(), Ok(Metric::Hits { k: 3 }));
Expand All @@ -42,7 +42,7 @@ pub(crate) const RELEVANT_LEVEL: GoldScore = 1;
/// formatting a [`Metric`] into a string, as follows:
///
/// ```rust
/// use ireval::Metric;
/// use elinor::Metric;
///
/// assert_eq!(format!("{}", Metric::Hits { k: 0 }), "hits");
/// assert_eq!(format!("{}", Metric::Hits { k: 3 }), "hits@3");
Expand Down Expand Up @@ -252,19 +252,19 @@ fn format_metric(name: &str, k: usize) -> String {
}

impl FromStr for Metric {
type Err = EmirError;
type Err = ElinorError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let re = Regex::new(r"^(?<metric>[a-z1-9_]+)(@(?<k>\d+))?$").unwrap();
let caps = re
.captures(s)
.ok_or_else(|| EmirError::InvalidFormat(s.to_string()))?;
.ok_or_else(|| ElinorError::InvalidFormat(s.to_string()))?;
let name = caps.name("metric").unwrap().as_str();
let k = caps
.name("k")
.map(|m| m.as_str().parse::<usize>())
.transpose()
.map_err(|_| EmirError::InvalidFormat(s.to_string()))?
.map_err(|_| ElinorError::InvalidFormat(s.to_string()))?
.unwrap_or(0);
match name {
"hits" => Ok(Self::Hits { k }),
Expand All @@ -278,7 +278,7 @@ impl FromStr for Metric {
"ndcg" => Ok(Self::NDCG { k }),
"dcg_burges" => Ok(Self::DCGBurges { k }),
"ndcg_burges" => Ok(Self::NDCGBurges { k }),
_ => Err(EmirError::InvalidFormat(s.to_string())),
_ => Err(ElinorError::InvalidFormat(s.to_string())),
}
}
}
Expand All @@ -288,13 +288,13 @@ pub fn compute_metric<K>(
qrels: &Qrels<K>,
run: &Run<K>,
metric: Metric,
) -> Result<HashMap<K, f64>, EmirError>
) -> Result<HashMap<K, f64>, ElinorError>
where
K: Clone + Eq + std::hash::Hash + std::fmt::Display,
{
for query_id in run.query_ids() {
if qrels.get_map(query_id).is_none() {
return Err(EmirError::MissingEntry(format!("Query ID: {query_id}")));
return Err(ElinorError::MissingEntry(format!("Query ID: {query_id}")));
}
}
let mut results = HashMap::new();
Expand Down
10 changes: 5 additions & 5 deletions src/relevance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;
use std::fmt::Display;
use std::hash::Hash;

use crate::errors::EmirError;
use crate::errors::ElinorError;

/// Data to store a relevance score for a document.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -139,14 +139,14 @@ impl<K, T> RelevanceStoreBuilder<K, T> {
///
/// # Errors
///
/// * [`EmirError::DuplicateEntry`] if the query-document pair already exists.
pub fn add_score(&mut self, query_id: K, doc_id: K, score: T) -> Result<(), EmirError>
/// * [`ElinorError::DuplicateEntry`] if the query-document pair already exists.
pub fn add_score(&mut self, query_id: K, doc_id: K, score: T) -> Result<(), ElinorError>
where
K: Eq + Hash + Clone + Display,
{
let rels = self.map.entry(query_id.clone()).or_default();
if rels.contains_key(&doc_id) {
return Err(EmirError::DuplicateEntry(format!(
return Err(ElinorError::DuplicateEntry(format!(
"Query: {query_id}, Doc: {doc_id}"
)));
}
Expand Down Expand Up @@ -281,7 +281,7 @@ mod tests {
b.add_score('a', 'x', 1).unwrap();
assert_eq!(
b.add_score('a', 'x', 2),
Err(EmirError::DuplicateEntry("Query: a, Doc: x".to_string()))
Err(ElinorError::DuplicateEntry("Query: a, Doc: x".to_string()))
);
}
}
Loading

0 comments on commit 488d9c8

Please sign in to comment.