Тестируя программу, мы применили ее к нескольким текстам. Первым стал короткий рассказ Германа Мелвилла “Bartleby”. Здесь иллюстрируется составной запрос AndQuery, для которого подходящие слова расположены в соседних строках. (Отметим, что слова, заключенные между символами косой черты, предполагаются набранными курсивом.)
Введите запрос. Пожалуйста, разделяйте все его элементы пробелами.
Запрос (или весь сеанс) завершается точкой ( . ).
== John && Jacob && Astor
john ( 3 ) lines match
jacob ( 3 ) lines match
john && jacob ( 3 ) lines match
astor ( 3 ) lines match
john && jacob && astor ( 5 ) lines match
Requested query: john && jacob && astor
( 34 ) All who know me consider me an eminently /safe/ man. The late
John Jacob
( 35 ) Astor, a personage little given to poethic enthusiasm, had no
hesitation in
( 38 ) my profession by the late John Jacob Astor, a name which, I admit
I love to
( 40 ) bullion. I will freely add that I was not insensible to the late
John Jacob
( 41 ) Astor's good opinion.
Следующий запрос, в котором тестируются скобки и составные операторы, обращен к тексту новеллы "Heart of Darkness" Джозефа Конрада:
==horror || ( absurd && mystery ) || ( North && Pole )
horror ( 5 ) lines match
absurd ( 8 ) lines match
mystery ( 12 ) lines match
( absurd && mystery ) ( 1 ) lines match
horror || ( absurd && mystery ) ( 6 ) lines match
north ( 2 ) lines match
pole ( 7 ) lines match
( north && pole ) ( 1 ) lines match
horror || ( absurd && mystery ) || ( north && pole )
( 7 ) lines match
Requested query: horror || ( absurd && mystery ) || ( north && pole )
( 257 ) up I will go there.' The North Pole was one of these
( 952 ) horros. The heavy pole had skinned his poor nose
( 3055 ) some lightless region of subtle horrors, where pure,
( 3673 ) " 'The horror! The horror!'
( 3913 ) the whispered cry, 'The horror! The horror! '
( 3957 ) absurd mysteries not fit for a human being to behold.
( 4088 ) wind. 'The horror! The horror!'
Последний запрос был обращен к отрывку из романа Генри Джеймса "Portrait of a Lady". В нем иллюстрируется составной запрос в применении к большому текстовому файлу:
==clever && trick || devious
clever ( 46 ) lines match
trick ( 12 ) lines match
clever && trick ( 2 ) lines match
devious ( 1 ) lines match
clever && trick || devious ( 3 ) lines match
Requested query: clever && trick || devious
( 13914 ) clever trick she had guessed. Isabel, as she herself grew older
( 13935 ) lost the desire to know this lady's clever trick. If she had
( 14974 ) desultory, so devious, so much the reverse of processional.
There were
Упражнение 17.23
Реализованная нами обработка запроса пользователя обладает одним недостатком: она не применяет к каждому слову те же предварительные фильтры, что и программа, строящая вектор позиций (см. разделы 6.9 и 6.10). Например, пользователь, который хочет найти слово "maps", обнаружит, что в нашем представлении текста распознается только “map”, поскольку существительные во множественном числе приводятся к форме в единственном числе. Модифицируйте функцию query_text() так, чтобы она применяла эквивалентные фильтры к словам запроса.
Упражнение 17.24