Skip to content

Save to Affix and Dictionary files #103

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

Open
aarondandy opened this issue Mar 5, 2025 · 0 comments
Open

Save to Affix and Dictionary files #103

aarondandy opened this issue Mar 5, 2025 · 0 comments

Comments

@aarondandy
Copy link
Owner

Now that the in memory and builder representations of an Affix or Dictionary (WordList) can be modified in memory (#41), people want to be able to save those changes back to disk.

Between encodings, comments, and ordering I think any hopes of fully saving files while preserving the original loaded content is totally infeasible. Instead, here are some strategies that might be more feasible to implement:

  • Save the WordList and AffixConfig to their respective files in whatever way the developer chooses so long as the data can round-trip 100%
  • Provide dedicated types separate from AffixConfig and WordList that can surgically mutate those files.

As of v6, the AffixConfig is still effectively immutable, so writing to files is only critical for the WordList.

Workaround

To persist WordList mutations, persist "intents" instead of the actual WordList. When making modifications to a WordList, persist those modifications to an implementation specific format. This way, after loading a file pair you can re-play those modifications against the in memory representation.

Example: changes.txt

- poop
+ pewp
var words = WordList.Create...;
foreach (var intent in LoadChangeIntents()) {
  if (intent.Add) {
    words.Add(intent.Word);
  } else {
    words.Remove(intent.Word);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant