I have a ruby gem that calls a Natural Language Processing API to manipulate text. In the gem we process the API response to return the text back in a formatted way. However, there are cases where we want the ability to just pattern match the text passed in to just return a canned response we know is correct.
What is an efficient data matching structure for adding pre-generated responses to my gem that bypasses the API? I envision this file or data structure getting pretty large. I could do a simple ruby hash lookup but this is a bit unwieldy as it gets larger. Ideally the structure is easy for a team member to add, such as a .txt
file like:
This is
a sentence.
This is
a second sentence.
whereby I can send in a string like This is a sentence.
and it searches the file to return:
This is
a sentence.
How can I code this efficiently in Ruby?