'The officers taught at the academy'. This sentence appears unambiguous to us until we are presented with an upgraded version: 'The officers taught at the academy were very demanding'. Functional structures for them will be:
(1) ((at (taught (the officers))) (the academy))
(2) ((were ((at (taught (the officers))) (the academy))) (very demanding))
These structures share common part, namely the whole first sentence. But this common part should be evaluated to different results: in (1) it would be complete clause - sentence, while in (2) it's only a noun phrase. So it appears that the first sentence should actually have two valid interpretations, but we've already understood it unambiguously!
This can be resolved by implying that the whole construction should always have clause type. So when we assume 'taught' having two alternatives and calculate the (1) expression value with both, we could safely remove the noun phrase since it can't be final result. This top-level clausal implication can be even explicated by introducing one more function here, whose name could be '.' (dot). The only thing for it to do could be just to filter clauses out of all its argument's alternatives. But there's another way.
Let's assume that every functional language expression has only one interpretation. It's simple and it looks like humans do the same. So when (1) is considered in its standalone version, it will be unambiguously a clause. But then it appears that the sentence is not finished, and we get 'were' applied to this complex expression, which can't take clauses as arguments. So we now have to evaluate (1) in a different way, knowing now that its context requires it to be noun phrase. It should be not hard to find another alternative of 'taught' that will suit these new requirements: a passive participle.
At the top, a clause type will be expected, on other levels it will depend on a particular function. Function 'were' will want a noun phrase (and so will 'at' and 'the' do), the resulting function '(were ...)' will need a gerund ('very demanding').
Technically, the evaluator has to get the context requirements from somewhere. We can't calculate the expression result part-by-part, starting with '(the officers)' and then applying other functions to it, we should have the whole expression in our hands. It also means that functions don't take arguments as eagerly computed values any more, they take arguments as data instead and evaluate that data by themselves in a right context. Hello, LISP's macros.
Thursday, December 11, 2008
Wednesday, December 10, 2008
Time flies like an arrow: an ambiguity resolution example
Let's suppose we have to analyze a well-known ambiguous phrase 'Time flies like an arrow'. Here all three first words can be sentence predicates. Presented as a function composition, these alternatives will look as follows (in LISP notation, with function separated from its argument by space, both inside parentheses):
(1) 'Time' is a verb: ((like (an arrow)) (time flies))
(2) 'Flies' is a verb: ((like (an arrow)) (flies time))
(3) 'Like' is a verb: ((like (time flies)) (an arrow))
All of these applicative representations are self-disambiguating. Let's list the lexical word ambiguities. 'Time' can be either singular noun or a verb, 'flies' - plural noun or a singular third-person finite verb, 'like' - a verb or an adverb.
The result of '(an arrow)' occurring in all three alternatives is always the same, it means some object (it may be ambiguous, but the context doesn't provide more information, and the fact it's inanimate noun should satisfy us now).
We see 'time' being applied to 'flies' in the first and third variants. The result is ambiguous, it's either an order to time some flies (e.g. measure the time of their flight) or a description of some flies (maybe they fly through time from future to past).
If we exchange the function-argument roles, we get '(flies time)' from the second variant. Here the situation is better: 'flies' as noun doesn't have actants, therefore can't be a function, so only its verb-alternative remains. The latter also can't be applied to verbs in any way, so 'time' is noun there now, and '(flies time)' has clause type.
As for the '(like (an arrow))' construction, of course 'like' here can be an adverb describing the similarity of something to an arrow, but it can also be a verb. It can't be a usual narrative sentence predicate, since then it would require a subject, which should be passed to it as first argument by parser. And '(an arrow)' can't be this subject since it's 3d person singular requiring the verb to end with 's'. But 'like' here can still be imperative or infinitive verb. Both can't be applied then to clause '(flies time)', which disambiguates the second variant completely, giving the usual proverb about time which is flying too fast.
The verb 'like' also has only one direct object, which will be filled by '(an arrow)', so the resulting construction can't be applied to '(time flies)': we remember, it's either an imperative clause, or a noun phrase. This leaves only adverbial alternative for 'like'. It can modify only clause, so '(time flies)' must be really an imperative clause. Congratulations, we've disambiguated (1). We have to measure the flight time of some flies, and do this in a precise way, like an arrow, whatever this could mean.
Only the third variant is left. Here 'like' is applied to '(time flies)' and the result is applied to '(an arrow)' then. Imperative variant of '(time files)' can't be an argument of both verb and noun variants of 'like', and the noun 'like' doesn't have actants. This leaves us with verb 'like' eating noun phrase '(time flies)', which can be its subject when the verb is finite or its object when the verb is imperative or infinitive. An attempt to eat also '(an arrow)' then removes the non-evident imperative and infinitive alternatives, making this interpretation also unambiguous. We will know that all the future-to past flies are fond of some arrow.
(1) 'Time' is a verb: ((like (an arrow)) (time flies))
(2) 'Flies' is a verb: ((like (an arrow)) (flies time))
(3) 'Like' is a verb: ((like (time flies)) (an arrow))
All of these applicative representations are self-disambiguating. Let's list the lexical word ambiguities. 'Time' can be either singular noun or a verb, 'flies' - plural noun or a singular third-person finite verb, 'like' - a verb or an adverb.
The result of '(an arrow)' occurring in all three alternatives is always the same, it means some object (it may be ambiguous, but the context doesn't provide more information, and the fact it's inanimate noun should satisfy us now).
We see 'time' being applied to 'flies' in the first and third variants. The result is ambiguous, it's either an order to time some flies (e.g. measure the time of their flight) or a description of some flies (maybe they fly through time from future to past).
If we exchange the function-argument roles, we get '(flies time)' from the second variant. Here the situation is better: 'flies' as noun doesn't have actants, therefore can't be a function, so only its verb-alternative remains. The latter also can't be applied to verbs in any way, so 'time' is noun there now, and '(flies time)' has clause type.
As for the '(like (an arrow))' construction, of course 'like' here can be an adverb describing the similarity of something to an arrow, but it can also be a verb. It can't be a usual narrative sentence predicate, since then it would require a subject, which should be passed to it as first argument by parser. And '(an arrow)' can't be this subject since it's 3d person singular requiring the verb to end with 's'. But 'like' here can still be imperative or infinitive verb. Both can't be applied then to clause '(flies time)', which disambiguates the second variant completely, giving the usual proverb about time which is flying too fast.
The verb 'like' also has only one direct object, which will be filled by '(an arrow)', so the resulting construction can't be applied to '(time flies)': we remember, it's either an imperative clause, or a noun phrase. This leaves only adverbial alternative for 'like'. It can modify only clause, so '(time flies)' must be really an imperative clause. Congratulations, we've disambiguated (1). We have to measure the flight time of some flies, and do this in a precise way, like an arrow, whatever this could mean.
Only the third variant is left. Here 'like' is applied to '(time flies)' and the result is applied to '(an arrow)' then. Imperative variant of '(time files)' can't be an argument of both verb and noun variants of 'like', and the noun 'like' doesn't have actants. This leaves us with verb 'like' eating noun phrase '(time flies)', which can be its subject when the verb is finite or its object when the verb is imperative or infinitive. An attempt to eat also '(an arrow)' then removes the non-evident imperative and infinitive alternatives, making this interpretation also unambiguous. We will know that all the future-to past flies are fond of some arrow.
Saturday, December 6, 2008
Tuesday, September 16, 2008
Sunday, June 15, 2008
Friday, May 30, 2008
Развод
Приходит мне смска. Написано, что вот, абонентская служба Билайна вас беспокоит, ваш номер заблокирован, перезвоните на такой-то телефон нам в Билайн для поправки ситуации. Проверяю телефон, вроде, звонит, на него тоже звонят, все нормально. Ну и забил.
Через несколько часов звонок с неизвестного номера. Представительный голос. "Это Билайн. Вы смс получали о том-то и том-то? Позвоните, пожалуйста, по указанному телефону, а то вас заблокируют. Тут у нас сервер накрылся, надо вас перерегистрировать, и т.п". Последнее звучит несколько подозрительно, гуглю, ничего похожего не нахожу. Так и быть, звоню. Не менее представительный голос рассказывает еще раз про сервер, спрашивает серию мобилки, дальше процедура будет идти чисто автоматически, надо набирать на телефоне всякие циферки, перемежая их решеточками. Ну я набираю, жмя периодически Enter, и смотря, что там на экране.
Когда, наконец, вижу слова "введите номер абонента, которому хотите перевести деньги", сообщаю, что номер не прошел, благотворительностью заниматься не люблю, поэтому увы, продолжать не буду. Сначала товарищ отнекивался, потом фактически признал, сказал, что не от хорошей жизни занимается, надо же как-то зарабатывать. Дальше мы довольно мило пообщались на тему степени убедительности развода (таки достаточно убедительно, да). Ну и вот.
Интересно, что при общении товарищ достаточно точно назвал сумму на моем счете. Вот и вопрос, откуда он ее узнал. Уж не завелся ли на тель-афоне шпион, посылающий что-нибудь куда-нибудь? И как бы его удалить?
Через несколько часов звонок с неизвестного номера. Представительный голос. "Это Билайн. Вы смс получали о том-то и том-то? Позвоните, пожалуйста, по указанному телефону, а то вас заблокируют. Тут у нас сервер накрылся, надо вас перерегистрировать, и т.п". Последнее звучит несколько подозрительно, гуглю, ничего похожего не нахожу. Так и быть, звоню. Не менее представительный голос рассказывает еще раз про сервер, спрашивает серию мобилки, дальше процедура будет идти чисто автоматически, надо набирать на телефоне всякие циферки, перемежая их решеточками. Ну я набираю, жмя периодически Enter, и смотря, что там на экране.
Когда, наконец, вижу слова "введите номер абонента, которому хотите перевести деньги", сообщаю, что номер не прошел, благотворительностью заниматься не люблю, поэтому увы, продолжать не буду. Сначала товарищ отнекивался, потом фактически признал, сказал, что не от хорошей жизни занимается, надо же как-то зарабатывать. Дальше мы довольно мило пообщались на тему степени убедительности развода (таки достаточно убедительно, да). Ну и вот.
Интересно, что при общении товарищ достаточно точно назвал сумму на моем счете. Вот и вопрос, откуда он ее узнал. Уж не завелся ли на тель-афоне шпион, посылающий что-нибудь куда-нибудь? И как бы его удалить?
Saturday, April 19, 2008
Вредно
Тесты - это зло. Когда я привык их иметь, я отвык думать. Понятия подменились, и вместо того, чтобы стремиться к правильной программе, я стремлюсь к зеленым тестам. При этом я, конечно, стремлюсь и к хорошему покрытию программы этими тестами, что в сумме дает вроде как то, что и надо. Но все равно ощущения странные.
Поскольку тесты обычно есть, я не боюсь ничего менять, надеясь на них. Когда покрытие хорошее, это еще может сойти с рук, а вот когда оно хромает, это фатально. Могу случайно сломать что-нибудь совсем, даже не заметив. Потом, когда до меня это доходит, понимаю, что если б я хоть чуть-чуть подумал, ничего бы не случилось.
Причем когда из-за моих изменений ломается что-нибудь незатестрированное в чужом коде, я даже не испытываю мук совести.
Но только благодаря наличию тестов (имхо) в Идее можно после каждого релиза все переписывать, надеясь на лучшее. И вообще, тесты - это хорошо. Значит, следуя классическому рецепту, перед изменением мира надо изменить себя. Например, научиться иногда думать. Хоть это и сабж.
Поскольку тесты обычно есть, я не боюсь ничего менять, надеясь на них. Когда покрытие хорошее, это еще может сойти с рук, а вот когда оно хромает, это фатально. Могу случайно сломать что-нибудь совсем, даже не заметив. Потом, когда до меня это доходит, понимаю, что если б я хоть чуть-чуть подумал, ничего бы не случилось.
Причем когда из-за моих изменений ломается что-нибудь незатестрированное в чужом коде, я даже не испытываю мук совести.
Но только благодаря наличию тестов (имхо) в Идее можно после каждого релиза все переписывать, надеясь на лучшее. И вообще, тесты - это хорошо. Значит, следуя классическому рецепту, перед изменением мира надо изменить себя. Например, научиться иногда думать. Хоть это и сабж.
Subscribe to:
Posts (Atom)