Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

chore: rename `affixes.json` to `annotations.json` (#1504)

Andrew Dunbar92b964d0381c
diff --git a/harper-cli/src/main.rs b/harper-cli/src/main.rs
index 58be589e0..9489f405f 100644
--- a/harper-cli/src/main.rs
+++ b/harper-cli/src/main.rs
@@ -352,7 +352,7 @@ fn main() -> anyhow::Result<()> {
let rune_words = format!("1\n{line}");
let dict = MutableDictionary::from_rune_files(
&rune_words,
- include_str!("../../harper-core/affixes.json"),
+ include_str!("../../harper-core/annotations.json"),
)?;
println!("New, from you:");
@@ -445,7 +445,7 @@ fn main() -> anyhow::Result<()> {
use serde_json::Value;
let dict_path = dir.join("dictionary.dict");
- let affixes_path = dir.join("affixes.json");
+ let affixes_path = dir.join("annotations.json");
// Validate old and new flags are exactly one Unicode code point (Rust char)
// And not characters used for the dictionary format
@@ -467,27 +467,27 @@ fn main() -> anyhow::Result<()> {
// Load and parse affixes
let affixes_string = fs::read_to_string(&affixes_path)
- .map_err(|e| anyhow!("Failed to read affixes.json: {e}"))?;
+ .map_err(|e| anyhow!("Failed to read annotations.json: {e}"))?;
let affixes_json: Value = serde_json::from_str(&affixes_string)
- .map_err(|e| anyhow!("Failed to parse affixes.json: {e}"))?;
+ .map_err(|e| anyhow!("Failed to parse annotations.json: {e}"))?;
// Get the nested "affixes" object
let affixes_obj = &affixes_json
.get("affixes")
.and_then(Value::as_object)
- .ok_or_else(|| anyhow!("affixes.json does not contain 'affixes' object"))?;
+ .ok_or_else(|| anyhow!("annotations.json does not contain 'affixes' object"))?;
let properties_obj = &affixes_json
.get("properties")
.and_then(Value::as_object)
- .ok_or_else(|| anyhow!("affixes.json does not contain 'properties' object"))?;
+ .ok_or_else(|| anyhow!("annotations.json does not contain 'properties' object"))?;
// Validate old flag exists and get its description
let old_entry = affixes_obj
.get(&old)
.or_else(|| properties_obj.get(&old))
- .ok_or_else(|| anyhow!("Flag '{old}' not found in affixes.json"))?;
+ .ok_or_else(|| anyhow!("Flag '{old}' not found in annotations.json"))?;
let description = old_entry
.get("#")
@@ -548,7 +548,7 @@ fn main() -> anyhow::Result<()> {
// Verify that the updated affixes string is valid JSON
serde_json::from_str::<Value>(&updated_affixes_string)
- .map_err(|e| anyhow!("Failed to parse updated affixes.json: {e}"))?;
+ .map_err(|e| anyhow!("Failed to parse updated annotations.json: {e}"))?;
// Write changes
fs::write(&dict_path, updated_dict)
diff --git a/harper-core/affixes.json b/harper-core/annotations.json
similarity index 100%
rename from harper-core/affixes.json
rename to harper-core/annotations.json
diff --git a/harper-core/src/spell/mutable_dictionary.rs b/harper-core/src/spell/mutable_dictionary.rs
index 2c94077c2..0ad1146b8 100644
--- a/harper-core/src/spell/mutable_dictionary.rs
+++ b/harper-core/src/spell/mutable_dictionary.rs
@@ -33,7 +33,7 @@ fn uncached_inner_new() -> Arc<MutableDictionary> {
Arc::new(
MutableDictionary::from_rune_files(
include_str!("../../dictionary.dict"),
- include_str!("../../affixes.json"),
+ include_str!("../../annotations.json"),
)
.expect("Curated dictionary should be valid."),
)
@@ -377,7 +377,7 @@ mod tests {
#[test]
fn are_merged_attrs_same_as_spread_attrs() {
- let curated_attr_list = include_str!("../../affixes.json");
+ let curated_attr_list = include_str!("../../annotations.json");
let merged = MutableDictionary::from_rune_files("1\nblork/DGS", curated_attr_list).unwrap();
let spread =
diff --git a/justfile b/justfile
index 3f3f3024b..4eda77c8c 100644
--- a/justfile
+++ b/justfile
@@ -438,10 +438,10 @@ registerlinter module name:
sed -i "/insert_expr_rule!(ChockFull, true);/a \ \ \ \ insert_struct_rule!({{name}}, true);" "$D/lint_group.rs"
just format
-# Print affixes and their descriptions from affixes.json
+# Print affixes and their descriptions from annotations.json
printaffixes:
#! /usr/bin/env node
- const affixesData = require('{{justfile_directory()}}/harper-core/affixes.json');
+ const affixesData = require('{{justfile_directory()}}/harper-core/annotations.json');
const allAffixes = {
...affixesData.affixes || {},
...affixesData.properties || {}
@@ -508,8 +508,8 @@ newest-dict-changes *numCommits:
if (showDiff) console.log(`DIFFSTART\n${diffString}\nDIFFEND`);
// uncomment first line to use in justfile, comment out second line to use standalone
- const affixes = require('{{justfile_directory()}}/harper-core/affixes.json').affixes;
- // const affixes = require('./harper-core/affixes.json').affixes;
+ const affixes = require('{{justfile_directory()}}/harper-core/annotations.json').affixes;
+ // const affixes = require('./harper-core/annotations.json').affixes;
diffString.split("\n").forEach(line => {
const match = line.match(/^(?:\[-(.*?)-\])?(?:\{\+(.*?)\+\})?$/);
diff --git a/packages/web/src/routes/docs/contributors/dictionary/+page.md b/packages/web/src/routes/docs/contributors/dictionary/+page.md
index 649f5de61..c129e481d 100644
--- a/packages/web/src/routes/docs/contributors/dictionary/+page.md
+++ b/packages/web/src/routes/docs/contributors/dictionary/+page.md
@@ -9,15 +9,17 @@ If this happens to you, please open a PR to get them in.
PR [#343](https://github.com/Automattic/harper/pull/343) is a practical example of the ideas described here.
There are two files you need to worry about.
-[`harper-core/dictionary.dict`](https://github.com/Automattic/harper/blob/master/harper-core/dictionary.dict) and [`harper-core/affixes.json`](https://github.com/Automattic/harper/blob/master/harper-core/affixes.json).
+[`harper-core/dictionary.dict`](https://github.com/Automattic/harper/blob/master/harper-core/dictionary.dict) and [`harper-core/annotations.json`](https://github.com/Automattic/harper/blob/master/harper-core/annotations.json) (formerly `affixes.json`).
The first is a list of words, tagged with modifiers defined in the second.
For example, all words, such as "move", tagged with `L`, will be expanded to two dictionary entries, "move" and "movement".
-In `affixes.json`, this expansion rule looks like this:
+In `annotations.json`, this expansion rule looks like this:
-```js title=affixes.json
+```js title=annotations.json
{
"L": {
+ // A description of the rule.
+ "#": "'-ment' suffix",
// Denotes that the area of interest is at the _end_ of the base word.
"kind": "suffix",
// Declare that it is OK to use the result of the expansion with other expansions.
@@ -33,9 +35,9 @@ In `affixes.json`, this expansion rule looks like this:
}
],
// The word metadata that should be applied to the expanded word.
- "adds_metadata": {},
+ "target": {},
// The word metadata that should be applied to the base word.
- "gifts_metadata": {}
+ "base_metadata": {}
}
}
```