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

feat: add just sample to list all forms of random dictionary words #646

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hippietrail
Copy link
Contributor

Modified harper-cli forms to accept a space-separated list of annotated words to support this.

just sample accepts a numeric argument for how many words to choose from the curated dictionary.

I've already fixed some mistakes with wrong affix annotations in the curated dictionary. This provides a way to check randomly to see if anything looks wrong.

It may actually be more useful for the user dictionary. Let me know if I should add that and suggest names for switches. Another possibility as to also have an option that samples from the combined curated+user dictionaries.

The implementation uses the *nix jot command which is included with macOS which does not have shuf. Let me know if this solution is broken for Linux etc.

Example:

% just sampleforms 5
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/harper-cli forms opposite/51+SMYNX sett/14BJZGRS checkbox/1S sushi/14M Ibo/21M`
1/5: opposite/51+SMYNX
  - opposites
  - oppositely
  - oppositions
  - opposite's
  - opposite
  - opposition

2/5: sett/14BJZGRS
  - settings
  - setters
  - setts
  - setter
  - setting
  - sett
  - settable

3/5: checkbox/1S
  - checkboxes
  - checkbox

4/5: sushi/14M
  - sushi's
  - sushi

5/5: Ibo/21M
  - Ibo's
  - Ibo

(sett is a word, but not that common, so might not be a mistake)

Modified `harper-cli forms` to accept a space-separated list of annotated words to support this.

`just sample` accepts a numeric argument for how many words to choose from the curated dictionary.

I've already fixed some mistakes with wrong affix annotations in the curated dictionary. This provides a way to check randomly to see if anything looks wrong.

It may actually be more useful for the user dictionary. Let me know if I should add that and suggest names for switches. Another possibility as to also have an option that samples from the combined curated+user dictionaries.

The implementation uses the *nix `jot` command which is included with macOS which does not have `shuf`. Let me know if this solution is broken for Linux etc.
@@ -259,6 +259,21 @@ getmetadata word:
# Get all the forms of a word using the affixes.
getforms word:
cargo run --bin harper-cli -- forms {{word}}
# Get a random sample of words from Harper's dictionary and list all forms of each.
sampleforms count:
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding set -eo pipefail?

Right now, if jot is not available on the machine (like mine), it silently errors. I'm fine with adding it as a dependency, but I'd like it to error out when it's missing.

Copy link
Contributor Author

@hippietrail hippietrail Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding set -eo pipefail?

Is that as a separate *nix command? I'm a CLI guy but no *nix or shell wizard.

Right now, if jot is not available on the machine (like mine), it silently errors. I'm fine with adding it as a dependency, but I'd like it to error out when it's missing.

Ah I was worried about that. The other solution is to use shuf on machines that have it and jot otherwise, but I'm not sure how to handle that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elijah-potter I just made an alternate PR that should work with either jot or shuf but I'm unable to test. Please give it a try and let me know: #653

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants