Авторизация:
E-Mail: Пароль:
Закрыть
RU | EN

Генератор текста. Цепь Маркова

Опубликовано: 2006-07-31 20:15:34
Этот текст доступен по адресу: http://ontext.info/299
%3C%3F%0D%0A%0D%0Afunction+cmpLinks%28%24a%2C+%24b%29%0D%0A%7B%0D%0A+++if+%28%24a%5B0%5D+%3D%3D+%24b%5B0%5D%29+%7B%0D%0A+++++++return+0%3B%0D%0A+++%7D%0D%0A+++return+%28%24a%5B0%5D+%3C+%24b%5B0%5D%29+%3F+-1+%3A+1%3B%0D%0A%7D%0D%0A%0D%0Aclass+GenText%0D%0A%7B%0D%0A%0D%0Aprivate+static+%24loaded%3B%0D%0Aprivate+static+%24dictionary+%3D+array%28%29%3B%0D%0Aprivate+static+%24links+%3D+array%28%29%3B%0D%0Aprivate+static+%24clinks%3B%0D%0A%0D%0Aprivate+function+getFirstLink%28%24num%29%0D%0A%7B%0D%0A%09%24l+%3D+-1%3B%0D%0A++++%24u+%3D+self%3A%3A%24clinks%3B%0D%0A++++while+%28%24l%2B1+%3C+%24u%29%0D%0A%09%7B%0D%0A++++++++%24m+%3D+floor%28%28%24l+%2B+%24u%29+%2F+2%29%3B%0D%0A++++++++if+%28self%3A%3A%24links%5B%24m%5D%5B0%5D+%3C+%24num%29%0D%0A++++++++++++%24l+%3D+%24m%3B%0D%0A++++++++else%0D%0A++++++++++++%24u+%3D+%24m%3B%0D%0A%09%7D%0D%0A%09if%28+%24u+%3D%3D+self%3A%3A%24clinks+%29%0D%0A%09%09%24u+%3D+0%3B%0D%0A%09return+%24u%3B%0D%0A%7D%0D%0A%0D%0Aprivate+function+load%28%29%0D%0A%7B%0D%0A%09if%28+%21empty%28self%3A%3A%24loaded%29+%29%0D%0A%09%09return+false%3B%0D%0A%09%24str+%3D+file_get_contents%28%27txt%2F4markov%27%29%3B%0D%0A%09%24str+%3D+preg_replace%28%22%23%5B%5Cr%5Cn%5D%23%22%2C%22%22%2C%24str%29%3B%0D%0A%09preg_match_all%28%22%23%28%28%5C%22%5B%5E%5C%22%5D%2B%5C%22%29%7C%28%5C%28%5B%5E%5C%29%5D%2B%5C%29%29%7C%28%5B%5E%5C%28%5C%29%5C%22%27%5Cs%5D%2B%29%29%28%5Cs%2B%7C%5Cz%29%23%22%2C%24str%2C%24parts%29%3B%0D%0A%09%24words+%3D+%24parts%5B1%5D%3B%0D%0A%09%24count+%3D+count%28%24words%29%3B%0D%0A%09%24prev_num+%3D+0%3B%0D%0A%09for%28+%24i+%3D+0%3B+%24i+%3C+%24count%3B+%24i%2B%2B+%29%0D%0A%09%7B%0D%0A%09%09%24num+%3D+array_search%28%24words%5B%24i%5D%2Cself%3A%3A%24dictionary%2C1%29%3B%0D%0A%09%09if%28+%24num+%3D%3D%3D+false+%29%0D%0A%09%09%7B%0D%0A%09%09%09%24num+%3D+count%28self%3A%3A%24dictionary%29%3B%0D%0A%09%09%09self%3A%3A%24dictionary%5B%24num%5D+%3D+%24words%5B%24i%5D%3B%0D%0A%09%09%7D%0D%0A%09%09if%28+%24i+%3E+0+%29%0D%0A%09%09%09self%3A%3A%24links%5B%5D+%3D+array%28%24prev_num%2C%24num%29%3B%0D%0A%09%09%24prev_num+%3D+%24num%3B%0D%0A%09%7D%0D%0A%09usort%28self%3A%3A%24links%2C%27cmpLinks%27%29%3B%0D%0A%09self%3A%3A%24clinks+%3D+count%28self%3A%3A%24links%29%3B%0D%0A%7D%0D%0A%0D%0Apublic+function+genRaw%28%24word%2C%24count%2C%24percent%29%0D%0A%7B%0D%0A%09if%28+empty%28self%3A%3A%24laoded%29+%29%0D%0A%09%09self%3A%3Aload%28%29%3B%0D%0A%09%09%0D%0A%09%24percent+%2F%3D+100%3B%0D%0A%0D%0A%09%24totalCount+%3D+0%3B%0D%0A%09%24wordCount+%3D+0%3B%0D%0A%09%0D%0A%09%24wordIdx+%3D+array%28%29%3B%0D%0A%09%24cd+%3D+count%28self%3A%3A%24dictionary%29%3B%0D%0A%09for%28+%24i+%3D+0%3B+%24i+%3C+%24cd%3B+%24i%2B%2B+%29%0D%0A%09%09if%28+%21strncmp%28%24word%2Ctrim%28self%3A%3A%24dictionary%5B%24i%5D%2C%27%22%28%27%29%2Cstrlen%28%24word%29%29+%29%0D%0A%09%09%09%24wordIdx%5B%5D+%3D+%24i%3B%0D%0A%09if%28+empty%28+%24wordIdx%29+%29%0D%0A%09%7B%0D%0A%09%09echo+%22Can%27t+find+%22.%24word.%22+in+source+text.%3Cbr%2F%3E%22%3B%0D%0A%09%09return+false%3B%0D%0A%09%7D%0D%0A%09%09%0D%0A%09%24num+%3D+0%3B%09%0D%0A%09%24text+%3D%27%27%3B%0D%0A%09for%28+%24i+%3D+0%3B+%24i+%3C+%24count%3B+%24i%2B%2B+%29%0D%0A%09%7B%0D%0A%09%09%24text+.%3D+%27+%27.self%3A%3A%24dictionary%5B%24num%5D%3B%09%0D%0A%09%09%24totalCount%2B%2B%3B%0D%0A%09%09if%28+in_array%28%24num%2C%24wordIdx%29+%29%0D%0A%09%09%09%24wordCount%2B%2B%3B%0D%0A%09%09%24first+%3D+self%3A%3AgetFirstLink%28%24num%29%3B%0D%0A%09%09%24last+%3D+%24first%3B%0D%0A%09%09%24foundWord+%3D+false%3B%0D%0A%09%09while%28+%24last+%3C+self%3A%3A%24clinks+%26%26+self%3A%3A%24links%5B%24last%5D%5B0%5D+%3D%3D+%24num+%29%0D%0A%09%09%7B%0D%0A%09%09%09if%28+in_array%28self%3A%3A%24links%5B%24last%5D%5B1%5D%2C%24wordIdx%29+%29%0D%0A%09%09%09%09%24foundWord+%3D+self%3A%3A%24links%5B%24last%5D%5B1%5D%3B%0D%0A%09%09%09%24last%2B%2B%3B%0D%0A%09%09%7D%0D%0A%09%09if%28+%28%24foundWord+%21%3D%3D+false+%26%26+%24wordCount+%2F+%24totalCount+%3C+%24percent+%2A+1.5%29+%29%0D%0A%09%09%09%24num+%3D+%24foundWord%3B%0D%0A%09%09else+if%28+%24wordCount%2F%24totalCount+%3C+%24percent+%26%26+%24totalCount+%3E+10%29%0D%0A%09%09%09%24num+%3D+%24wordIdx%5Brand%280%2Ccount%28%24wordIdx%29-1%29%5D%3B%0D%0A%09%09else%0D%0A%09%09%09%24num+%3D+self%3A%3A%24links%5Brand%28%24first%2C%24last-1%29%5D%5B1%5D%3B%0D%0A%09%7D%0D%0A%09echo+%24text%3B%0D%0A%09echo+%27%3Cbr%2F%3E%3Cbr%2F%3E%27%3B%0D%0A%09echo+%27Percent%3A+%27.%28%24wordCount%2F%24totalCount+%2A+100+%29.%27%3Cbr%2F%3E%27%3B%0D%0A%7D%0D%0A%0D%0A%7D%0D%0A%0D%0A%3F%3E

Зарегистрируйтесь на ontext.info для получения дополнительных возможностей по работе с сервисом.