harper icon indicating copy to clipboard operation
harper copied to clipboard

After #2630 is merged, the metadata for "it", "It", and "IT" are all the same and "it" is considered a noun.

Open hippietrail opened this issue 1 month ago • 2 comments

PR #2630 was merged the other day which I understand includes fixing the case-folding in the dictionary.

But I found that it still carries metadata as a noun as well as a pronoun.

The entries in dictionary.dict:

IT/Ng4              # removed `5`. nouns can qualify nouns. makes `it` an adjective which interferes with heuristics
It/4                # abbreviation for Italy/Italian. "biological force", "Id", and "desirable quality" senses too marginal
it/~Ia3so*          # I~pronoun a~personal 3~person .~singular s~subject o~object *~3pers-sing-subj

Compare that with the output from the harper-cli query on the metadata:

% just get-metadata it It IT
cargo run --bin harper-cli -- metadata it It IT
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.88s
     Running `target/debug/harper-cli metadata it It IT`
it: NI 📦👤
{
  "noun": {
    "is_proper": null,
    "is_singular": null,
    "is_plural": null,
    "is_countable": null,
    "is_mass": null,
    "is_possessive": null
  },
  "pronoun": {
    "is_personal": true,
    "is_singular": true,
    "is_plural": null,
    "is_possessive": null,
    "is_reflexive": null,
    "person": "Third",
    "is_subject": true,
    "is_object": true
  },
  "verb": null,
  "adjective": null,
  "adverb": null,
  "conjunction": null,
  "determiner": null,
  "affix": null,
  "preposition": false,
  "swear": null,
  "abbreviation": true,
  "dialects": "",
  "orth_info": "LOWERCASE | TITLECASE | ALLCAPS",
  "common": true,
  "derived_from": {
    "inner": []
  },
  "np_member": null,
  "pos_tag": null
}
It: NI 📦👤
{
  "noun": {
    "is_proper": null,
    "is_singular": null,
    "is_plural": null,
    "is_countable": null,
    "is_mass": null,
    "is_possessive": null
  },
  "pronoun": {
    "is_personal": true,
    "is_singular": true,
    "is_plural": null,
    "is_possessive": null,
    "is_reflexive": null,
    "person": "Third",
    "is_subject": true,
    "is_object": true
  },
  "verb": null,
  "adjective": null,
  "adverb": null,
  "conjunction": null,
  "determiner": null,
  "affix": null,
  "preposition": false,
  "swear": null,
  "abbreviation": true,
  "dialects": "",
  "orth_info": "LOWERCASE | TITLECASE | ALLCAPS",
  "common": true,
  "derived_from": {
    "inner": []
  },
  "np_member": null,
  "pos_tag": null
}
IT: NI 📦👤
{
  "noun": {
    "is_proper": null,
    "is_singular": null,
    "is_plural": null,
    "is_countable": null,
    "is_mass": null,
    "is_possessive": null
  },
  "pronoun": {
    "is_personal": true,
    "is_singular": true,
    "is_plural": null,
    "is_possessive": null,
    "is_reflexive": null,
    "person": "Third",
    "is_subject": true,
    "is_object": true
  },
  "verb": null,
  "adjective": null,
  "adverb": null,
  "conjunction": null,
  "determiner": null,
  "affix": null,
  "preposition": false,
  "swear": null,
  "abbreviation": true,
  "dialects": "",
  "orth_info": "LOWERCASE | TITLECASE | ALLCAPS",
  "common": true,
  "derived_from": {
    "inner": []
  },
  "np_member": null,
  "pos_tag": null
}

Am I misunderstanding what the PR brought? IT is marked as a noun, but it and It are not, yet they all gain noun metadata. @86xsk?

hippietrail avatar Oct 23 '26 11:10 hippietrail

I believe this arises from

let meta = curated_dictionary.get_word_metadata_str(&word);

In the metadata subcommand in harper-cli main.rs

get_word_metadata is implemented as

    fn get_word_metadata(&self, word: &[char]) -> Option<Cow<'_, DictWordMetadata>> {
        let mut found_words = self.word_map.get_case_folded_chars(word);
        let first = &found_words.next()?.metadata;

        if let Some(second) = found_words.next() {
            let mut first = first.clone();
            first.merge(&second.metadata);
            found_words.for_each(|entry| {
                first.merge(&entry.metadata);
            });
            Some(Cow::Owned(first))
        } else {
            Some(Cow::Borrowed(first))
        }
    }

i.e. it merges the metadata for all case-variants of the word.[^1]

If it called get_word_metadata_exact instead, it would only return the metadata for the exact case of the word.


Document's parsing uses get_word_metadata too. I think I did at one point explore with making it use exact-casing as well, but it's difficult to handle ambiguous casing. For instance, if 'It' was at the start of a sentence, what metadata should it have? And what about text written in all caps, or all lowercase? I think it's certainly possible to engineer a decent solution for this though, and I'll probably take a crack at it at some point if someone doesn't beat me to it.

Regarding the PR, it introduced optional case-sensitivity to the API, and used that as a base it fix some casing-related bugs, but it wasn't a complete solution.

[^1]: get_word_metadata could certainly be documented better. I think at one point I had it named get_word_metadata_merged, but I guess I undid that to make the PR smaller and preserve backwards compatibility.

86xsk avatar Oct 24 '26 00:10 86xsk

If it called get_word_metadata_exact instead, it would only return the metadata for the exact case of the word.

Awesome. Thanks. I'll be able to adjust just get-metadata pretty quickly then. I might even rename the other function very explicitly to get_case_folded_word_metadata to make it stand out when tweaking old code to work with their natural case.

Document's parsing uses get_word_metadata too. I think I did at one point explore with making it use exact-casing as well, but it's difficult to handle ambiguous casing. For instance, if 'It' was at the start of a sentence, what metadata should it have? And what about text written in all caps, or all lowercase? I think it's certainly possible to engineer a decent solution for this though, and I'll probably take a crack at it at some point if someone doesn't beat me to it.

Exactly. I would've designed the dictionary system around natural case, titlecase, and all caps being minimal requirements from the beginning and with a mind to having all lowercase working ideally. But now it's possible to get there from here.

Regarding the PR, it introduced optional case-sensitivity to the API, and used that as a base it fix some casing-related bugs, but it wasn't a complete solution.

No worries, I still think it's one of the most important PRs to get merged.

hippietrail avatar Oct 24 '26 01:10 hippietrail