If you're looking to <|optimize your resume for ATS|generate unique articles for SEO|express what the voices in your head are telling you|>, then you <|need|will love|> ambiguity, a templating language for text with multiple <|possibilities|choices|alternatives|>.
First, install the package.
npm install github:panasenco/ambiguity
Then, use it in your JavaScript code:
const ambiguity = require("ambiguity");
const parser = new ambiguity.Parser();
parser.feed("With <|rise of|increase in|> <|productive power|<|economic ||>productivity|>, rent tends to <|rise even higher|even greater increase|>.");
ambiguity_graph = parser.results[0];
console.log(ambiguity_graph.randomString());
This will log a random variation of your ambiguity template, for example:
With increase in productive power, rent tends to even greater increase.
After parsing a string, Ambiguity returns a Graphology graph object with the following additional methods to make usage with genetic algorithms easy:
Function | Description |
---|---|
randomPath() | Returns a random path through the graph as an array of nodes. |
pathToString(nodeArr) | Returns the string corresponding to the provided array of nodes. |
mutatedPath(nodeArr) | "Mutates" the provided path (array of nodes), introducing a 'detour' in the path. |
The above APIs make it easy to use Ambiguity with Genetic.js to optimize your template output to any fitness function. See examples/genetic.js.
Ambiguity compiles your templates into a graph-structured string. The heavy lifting is done by Nearley, Moo, and Graphology.
For example, consider the template a<|b|c|><|d|<|e||>f|g|>h<|i|j|>
. Ambiguity compiles it to the following directed acyclic graph object:
Each path in the graph from the root node to a leaf node represents a string that can be derived from the template.
Ambiguity always creates a blank root node with the ID 'root' that you can begin your traversal from.
Token definitions:
choices_start
:<|
choices_end
:|>
choice_separator
:|
char
: Any other character.