adelevie / walverine

Extract case law citations with Node
Other
55 stars 9 forks source link

Replacement functionality, or index #10

Open konklone opened 10 years ago

konklone commented 10 years ago

It's impossible to do find/replace with walverine results right now, because there's not a reliable match index brought back for results, no regexes exposed for Citation to use, and there's no replacement functionality built into Walverine itself.

Either would work, and I'm honestly not sure which is better from Citation's end.

As of issue press time, I'm planning to go with a solution that does a second pass over the whole string for replacement. It'll first detect all cites without replacing, then re-pass doing a split() on a string with the same combined regex, and join the string back together using the original detected cites (after replacement) as the joining hinges.

This approach would require walverine to offer its own replacement feature, or to expose a Citation-like API, with some sort of final regex(es) I could combine alongside other citators'.

If walverine instead only returned a match index, and Citation implemented replacement by using detected indices of all results, and then bookkeeping those indices (and updating them) as strings are replaced and the length is changed -- then I could also do it that way.

I'm not sure what's better!