0
votes

I'm using Bass Jobsen's Bootstrap 3 Typeahead, but for a non-standard use-case. I have a text input field where I expect full sentences and would like to help my users create them. I've used the matcher and updater functions suggested in this answer to append suggested words to the end of the sentence.

My problem is in defining context-specific autocomplete, so that if the general sentences I'd expect my users to type are something like, "I see the table in front of the chair." I could filter down the possible suggestions based on what types of words have already been used. For example, never suggest "see" after "table".

I plan on checking the input box on change, then reloading the source data for typeahead based on the current text in the input box. But, is there a more elegant solution than reloading the JSON source dynamically? Is there a way for me to load it all at once, then have the matcher apply only to a subset of the data?

1
You need a suggestion engine, Bootstrap 3 Typeahead is not built for suggestion the way you want it. You're best looking into the original typeahead and grabbing the bundled version. You should also look into integrating Hogan.js to compile your json.Panoply

1 Answers

1
votes

The 'source' option accepts a function. There, you can dynamically construct the possible items (sentences) any way you want: via an API call to a server or using data you had loaded before, or simply just data you loaded with the initial page load. The current query is the first parameter. You can return any number of sentences. You can also provide a sorter callback to sort them.

I have no idea how you want to create the possible sentences given the query, but if it's from a probabilistic model you want to look into Markov Models.