diff --git a/benches/search.rs b/benches/search.rs index 66faf21..b37a0d5 100644 --- a/benches/search.rs +++ b/benches/search.rs @@ -150,9 +150,10 @@ fn catalog(entries: usize) -> Vec { .collect() } -/// One source's ranked list. Every 25th record carries a DOI that every -/// source shares at that rank, matching the bench's measured 4% of hits -/// found by more than one source. +/// One source's ranked list. A record whose source plus rank is a multiple +/// of 25 carries a DOI shared by every source's record with the same sum, +/// so about 4% of the input records at every list length carry a shared +/// DOI. fn source_list(source: usize, records: usize) -> Vec { (0..records) .map(|rank| { @@ -162,8 +163,9 @@ fn source_list(source: usize, records: usize) -> Vec { ) .describe(Some(format!("{QUERY} {}", phrase(rank)))); dataset.publisher = Some(format!("Publisher {source}")); - if rank % 25 == 0 { - dataset.doi = Some(format!("10.5281/zenodo.{rank}")); + let shared = source + rank; + if shared.is_multiple_of(25) { + dataset.doi = Some(format!("10.5281/zenodo.{shared}")); } dataset }) diff --git a/docs/reference/development.md b/docs/reference/development.md index d1278b5..1a1053c 100644 --- a/docs/reference/development.md +++ b/docs/reference/development.md @@ -79,7 +79,7 @@ just bench-startup --bless # rewrite this machine class's baseline just relevance # score the shipped ranking against the judgments; fails on a regression just relevance variants # every ranking variant on the tuning and held-out halves just relevance pool # worksheets for every unjudged result a ranking puts in its top 10 -just relevance absorb # fold graded worksheets into judgments.tsv +just relevance absorb # fold graded worksheets into judgments.tsv, then delete them just relevance --bless # accept the current scores as the baseline just relevance record # re-record the snapshot from the live sources (network) just relevance record --source huggingface # re-record one source's lists only diff --git a/docs/reference/supply-chain.md b/docs/reference/supply-chain.md index fc06eef..2af205f 100644 --- a/docs/reference/supply-chain.md +++ b/docs/reference/supply-chain.md @@ -34,6 +34,6 @@ Run it with `just zizmor`. Workflows use the smallest permissions they can: - `ci.yml` sets `permissions: {}` at workflow level and grants the `linux` job `contents: read`. -- `release-plz.yml` sets `permissions: {}` and grants each job `contents: read` only. Writes go through the release App's token, minted per job with Contents and Pull requests write and revoked when the job ends. Each job starts with `step-security/harden-runner` in audit mode, which logs its outbound connections. +- `release-plz.yml` sets `permissions: {}` and grants each job `contents: read`, plus `id-token: write` on the `release` job, whose OIDC token crates.io trusted publishing exchanges for a short-lived publish token. Writes go through the release App's token, minted per job with Contents and Pull requests write and revoked when the job ends. Each job starts with `step-security/harden-runner` in audit mode, which logs its outbound connections. Every checkout sets `persist-credentials: false`, including the two in `release-plz.yml`. diff --git a/examples/relevance/pool.rs b/examples/relevance/pool.rs index 446cecf..386056b 100644 --- a/examples/relevance/pool.rs +++ b/examples/relevance/pool.rs @@ -75,10 +75,14 @@ fn fnv(text: &str) -> u64 { } /// Every graded worksheet row folded into judgments.tsv, replacing any -/// older label of the same dataset, and the file rewritten in order. +/// older label of the same dataset, and the file rewritten in order. The +/// worksheets are deleted after, so a later absorb cannot fold a stale grade +/// over a correction made in judgments.tsv; `pool` writes the rows still +/// ungraded again. pub fn absorb(queries: &[Query]) -> Result<()> { let mut labels = snapshot::labels()?; let mut added = 0_usize; + let mut read = Vec::new(); for q in queries { let path = snapshot::worksheets().join(format!("{}.tsv", q.id)); let Some(text) = snapshot::read_if_present(&path)? else { @@ -86,8 +90,13 @@ pub fn absorb(queries: &[Query]) -> Result<()> { }; let folded = fold(&mut labels, &q.id, &text, &path)?; added = added.saturating_add(folded); + read.push(path); } snapshot::write_labels(queries, &mut labels)?; + for path in read { + fs::remove_file(&path) + .with_context(|| format!("removing {}", path.display()))?; + } writeln!( io::stdout().lock(), "absorbed {added} labels; {} in total", diff --git a/scripts/homebrew-formula.sh b/scripts/homebrew-formula.sh index 6c7577c..193d940 100755 --- a/scripts/homebrew-formula.sh +++ b/scripts/homebrew-formula.sh @@ -12,10 +12,23 @@ tag=$1 sums=$2 releases="https://github.com/lmarkmann/dataseek/releases/download/$tag" +# A failure inside the here-document below would not stop the script, so +# every hash is read and checked first. sha() { - cut -d' ' -f1 "$sums/dataseek-$1.tar.gz.sha256" + hash=$(cut -d' ' -f1 "$sums/dataseek-$1.tar.gz.sha256") + case $hash in + *[!0-9a-f]* | "") ;; + *) [ ${#hash} -eq 64 ] && echo "$hash" && return ;; + esac + echo "no valid sha256 for $1 in $sums" >&2 + return 1 } +mac_arm=$(sha aarch64-apple-darwin) +mac_intel=$(sha x86_64-apple-darwin) +linux_arm=$(sha aarch64-unknown-linux-gnu) +linux_intel=$(sha x86_64-unknown-linux-gnu) + cat < Vec { return Vec::new(); } let needles = needles(&terms); - let phrase = terms.join(" "); + let phrase = format!(" {}", terms.join(" ")); let (mut title, mut body) = (String::new(), String::new()); let mut scored: Vec<(u32, &Dataset, usize)> = entries .iter() @@ -184,6 +184,16 @@ mod tests { assert_eq!(hits[0].title, "Rainfall"); } + #[test] + fn the_title_phrase_starts_at_a_word() { + let entries = [ + entry("Terrain gauge network", "rain"), + entry("Gauge data for rain", ""), + ]; + let hits = search(&entries, "rain gauge", 10); + assert_eq!(hits[0].title, "Gauge data for rain"); + } + #[test] fn punctuation_and_case_do_not_matter() { let entries = [entry("CO2-emissions per capita", "")]; diff --git a/src/record.rs b/src/record.rs index 4c84ab3..4422bd1 100644 --- a/src/record.rs +++ b/src/record.rs @@ -110,11 +110,7 @@ fn strip_tags(text: &str, mut push: impl FnMut(char)) { let mut chars = without_controls(text).peekable(); while let Some(c) = chars.next() { match c { - '<' if !in_tag - && chars.peek().is_some_and(|n| { - n.is_alphabetic() || matches!(n, '/' | '!') - }) => - { + '<' if !in_tag && chars.peek().is_some_and(|&n| opens_tag(n)) => { in_tag = true; } '>' if in_tag => { @@ -125,6 +121,31 @@ fn strip_tags(text: &str, mut push: impl FnMut(char)) { _ => {} } } + if in_tag { + without_controls(unclosed_tag(text)) + .filter(|&c| !invisible(c)) + .for_each(push); + } +} + +fn opens_tag(next: char) -> bool { + next.is_alphabetic() || matches!(next, '/' | '!') +} + +/// The text from a `<` that opened a tag no `>` closed, as in "A` would have closed it, so it is the first such `<` after the +/// last `>`. +fn unclosed_tag(text: &str) -> &str { + let tail = text + .rfind('>') + .and_then(|i| text.get(i.saturating_add(1)..)) + .unwrap_or(text); + tail.match_indices('<') + .find_map(|(i, _)| { + let rest = tail.get(i..)?; + rest.chars().nth(1).is_some_and(opens_tag).then_some(rest) + }) + .unwrap_or("") } /// Text built with every run of whitespace as one space and none at either @@ -619,6 +640,8 @@ mod tests { assert_eq!(clean("Children aged <5 years"), "Children aged <5 years"); assert_eq!(clean("PM2.5 < 10 and > 2"), "PM2.5 < 10 and > 2"); assert_eq!(clean("abold cd"), "a bold c d"); + assert_eq!(clean("Ratio of A 0, A 0, A