witch-house / pronoun.is

Show people how to use pronouns!
http://pronoun.is
GNU Affero General Public License v3.0
929 stars 103 forks source link

Minimum unambiguous path function #16

Closed morganastra closed 9 years ago

morganastra commented 9 years ago

This is mostly useful for generating links for the front page and maybe tweets

duckinator commented 9 years ago

I don't actually do Clojure, so I wrote it in Ruby, ported it to Clojure, then didn't test the Clojure version. (As you do.)

Might be helpful.

Clojure version which may or may not work: https://gist.github.com/duckinator/32027b103da48c7bc9da

Ruby code I based it on which I can confirm does actually work: https://gist.github.com/duckinator/8679b7e96a43648e8756

(I got bored.)

duckinator commented 9 years ago

(Consider all of that code public domain; do what you'd like with it. I was just trying to entertain myself. :D)

morganastra commented 9 years ago

Cool, thanks

This doesn't compile because you're trying to use a set function on a lazy seq (which is actually surprising to me; the usual clojure behavior in that situation is to compile and then do something totally unexpected :p)

Anyway, I'm pretty sure you just want filter - at least, if I change it to that it works.

Another weird thing is that if you give it an input that isn't actually in the dictionary, but starts with something that is, it'll return the minimum unambiguous path for the latter. For example:

pronouns.web> (u/minimum-unambiguous-path pronouns-table ["he" "her" "hirs"])
"he"

That's a pathological example, but consider the plethora of pronoun sets that start with "ze". I'm not actually sure if that's a real problem though, depends on how this gets used.