Create a Text Search Tool Using Feature Extraction
Train a feature extractor from sentences of Alice in Wonderland:
In[1]:=
alice = ExampleData[{"Text", "AliceInWonderland"}];
sentences = TextSentences[alice];
fe = FeatureExtraction[sentences]
Out[1]=
Generate a NearestFunction on the extracted features of the dataset.
In[2]:=
nf = Nearest[fe[sentences] -> Automatic]
Out[2]=
Construct a function that displays the nearest sentence in Alice in Wonderland and use it on a few sentences.
In[3]:=
nearestalice = sentences[[First@nf[fe[#]]]] &;
In[4]:=
nearestalice["Alice and the Rabbit"]
Out[4]=
In[5]:=
nearestalice["Off her head"]
Out[5]=