Skip to content

Save to Affix and Dictionary files #103

Open
@aarondandy

Description

@aarondandy

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);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions