The function GetWord() takes the tags as an argument and returns the word.
Shouldn't GetWord() return multiple words? What if there are multiple words with the same tags?
Hello: Tags: Greeting, Polite
Hi: Tags: Greeting
The 'best' way to implement this varies depending on the scope of this problem. There's already several solutions out there that can perform a map/reduce query, and that is perfect for situations like this. However, you do make this sound like a homework/exercise problem, in which using a 3rd party library/database probably wouldn't make sense, or beyond of what was being asked.