What would be the code pattern to get all the original terms that were normalized?
For example, in your 'Tax Avoidance' example below the term avoidance has a count of 17. What 17 un-normalized, original text content resulted in the one avoidance term?
hey Mario, good question. Yeah, you'll need to do a frequency-count yourself, if you want to keep references to the original terms. It would be pretty cool to be able to grab them all, as a compromise match.
Luckily, all the normalized forms appear in .json() results.
cheers
maybe this should be a new plugin, or a change to the topk api, if you can figure out what the API would look like for it. I'm not totally sure what it would look like, as a feature.
You can see where the use case for my question comes up with this forked notebook that utilizes a Word Cloud as a selector into a body of text: https://observablehq.com/d/e0c32a26d720d8c9
The original notebook was normalizing the text into for the Word Cloud's content. When selecting a normalized contraction ("I'm beginning" => "am beginning") the object does not expose the original de-normalized term to perform a select within the original text.
hey, that's an attractive application! Nice stuff.
Yeah, matching on contractions is tricky. Luckily, the offsets will still work, to the original text, so if you do:
doc.compute('offsets').match('am beginning').json()
it will start at 'beginning'.
In your position, I would just compute the frequency counts myself, using the .json() output. That's all it does internally:
https://github.com/spencermountain/compromise/blob/master/src/1-one/output/api/out.js#L64
let me know if I can help.
cheers