Guest User

jayjay http://he.tel - Sort words by popularity count.

a guest
Apr 9th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.84 KB | None | 0 0
  1.             ## SORT WORDS BY POPULARITY COUNT ##
  2. /*======================================================================================
  3.  Author:       Jason Whitehead (http://he.tel)  
  4.  Copyright:    GPL (C) 2003-2012
  5.  
  6.  This program is free software; you can redistribute it and/or modify it under the
  7.  terms of the GNU General Public License as published by the Free Software Foundation;
  8.  either version 2 of the License, or (at your option) any later version.
  9.  
  10.  THIS SCRIPT IS PROVIDED AS IS, WITHOUT ANY WARRANTY OR GUARANTEE OF ANY KIND USAGE!
  11. ======================================================================================*/
  12.  
  13. <pre>
  14. <?php
  15. //----------------------------------------------------------------------------
  16. function array_unchunk($foobar) {
  17. return call_User_Func_Array('array_merge',$foobar); }
  18. //----------------------------------------------------------------------------
  19. $text = "sort_words_by_popularity_count.txt";
  20. $input = file($text, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
  21. $arr1 = array_filter($input);
  22. foreach($arr1 as &$Val1) {
  23. $Val1 = trim(strip_tags($Val1));
  24. $Val1 = preg_replace("/[^a-zA-Z-']/", " ", $Val1);
  25. $Val1 = explode(" ", $Val1); }
  26. unset($Val1);
  27. $arr2 = array_filter(array_unchunk($arr1));
  28. foreach($arr2 as &$Val2) {
  29. $Val2 = trim($Val2, "-'");
  30. if(strlen($Val2)==1) {
  31. $Val2 = preg_replace("/[^AIai]/", " ", $Val2); }
  32. $count = preg_match_all("/[A-Z]/", $Val2, $null);
  33. if($count<=strlen($Val2)-$count) {
  34. $Val2 = preg_replace("/([A-Z])/", " $1", $Val2); }
  35. $Val2 = explode(" ", $Val2); }
  36. unset($Val2);
  37. $arr3 = array_filter(array_unchunk($arr2));
  38. foreach($arr3 as &$Val3) {
  39. $Val3 = str_ireplace(array("\n","\t","\r","\0","\x0B"), "", $Val3); }
  40. unset($Val3);
  41. $result = array_count_values(array_filter($arr3));
  42. arsort($result);
  43. print_r($result);
  44. ?>
  45. </pre>
  46.  
  47.  
  48. #(below) add this to notepad, save as 'sort_words_by_popularity_count.txt'
  49. //----------------------------------------------------------------------------
  50. cURL
  51. URL
  52. Curl
  53. URLs
  54. URL's
  55.  cURL
  56.  URL
  57.  Curl
  58.  URLs
  59. URL's<br>
  60.  URL's
  61. cURL    URL Curl    URLs    URL's
  62. ThisWord ThisIsThe  Way
  63. ~
  64. HelloWorldThisTextRequiresAWhiteSpaceToSeparate!
  65. 'hello'
  66. -hello-
  67. -h
  68. k-
  69. 'L'
  70. -J-
  71.  
  72. A
  73. a
  74. i
  75. I
  76. 1
  77. f
  78. I'm
  79. couldn't
  80. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  81.           "http://www.w3.org/TR/html4/strict.dtd">
  82. <html lang="en">
  83. <head>
  84.  <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
  85.  <title>Regular expressions in Perl - a summary with examples</title>
  86.  <link rel="stylesheet" type="text/css" href="../basic.css">
  87. <style type="text/css">
  88. h2 { text-align: center; margin-left:0; }
  89. th a:link, th a:visited { text-decoration: none ; }
  90. .rpad { padding-right: 0.2em; }
  91. </style>
  92. </head>
  93.  
  94. <body>
  95.  
  96. <h1>
  97. Regular expressions in Perl
  98. </h1>
  99.  
  100. <P>This document presents a tabular <strong>summary</strong> of the
  101. <a href=
  102. "http://perldoc.perl.org/perlre.html"
  103. title="perlre - Perl regular expression - section in the Perl manual"
  104. >regular expression (regexp) syntax</a>
  105. in
  106. <a href="." title="Material on Perl by J. Korpela">Perl</a>,
  107. then illustrates it with a collection of annotated
  108. <strong><a href="#ex">examples</a></strong>.</P>
  109.  
  110. <table border="0" cellpadding="0" cellspacing="15"><tr><td valign="top">
  111. <h2>Metacharacters</h2>
  112.  
  113.  
  114.  
  115.  
  116.  
  117. <span class="citation book">Neufeld, Michael (1996). <a rel="nofollow" class="external text" href="http://www.amazon.com/gp/reader_some_text_here_and_here/067477650X/ref=sib_dp_pt/103-1097535-3692624#reader-link"><i>The Rocket and the Reich: Peenemünde and the Coming of the Ballistic Missile Era</i></a>. <a href="/wiki/Cambridge,_Massachusetts" title="Cambridge, Massachusetts">Cambridge, Massachusetts</a>: <a href="/wiki/Harvard_University_Press" title="Harvard University Press">Harvard University Press</a>. <a href="/wiki/International_Standard_Book_Number" title="International Standard Book Number">ISBN</a>&nbsp;<a href="/wiki/Special:BookSources/0-674-77650-X" title="Special:BookSources/0-674-77650-X">0-674-77650-X</a><span class="printonly">. <a rel="nofollow" class="external free" href="http://www.amazon.com/gp/reader/067477650X/ref=sib_dp_pt/103-1097535-3692624#reader-link">http://www.amazon.com/gp/reader/067477650X/ref=sib_dp_pt/103-1097535-3692624#reader-link</a></span>.</span>
  118. 'foo'
  119. false
  120.      -1
  121. null
  122. true
  123. and
  124. 1234er
  125. 6789
  126. fh45-987uuu_jkhkjl4444
  127. if
  128. is
  129. go_to
  130. A new drug has been shown to combat the lethal spread of prostate cancer by 'kettling' tumours.
  131.  
  132. Although at an early stage of development, researchers hope it can be given at diagnosis to avoid aggressive treatments.
  133.  
  134. The drug, called KBU2046, is designed to disable proteins that keep prostate cancer cells moving.
  135.  
  136. Scientists in the US tested it on mice given transplants of aggressive human prostate cancer cells.
  137.  
  138. Over a period of five weeks, the drug inhibited movement of the cells and prevented them spreading to the lung.
  139.  
  140. The spread of cancer around the body, known as metastasis, is usually what kills cancer patients.
  141.  
  142. Prostate cancer in humans most often targets the bone, but may also spread to the liver, brain or lungs.
  143.  
  144. Scientists found that KBU2046 was non-toxic to healthy human cells and appeared to have no harmful side effects.
  145.  
  146. Professor Raymond Bergan, who led the study at Northwestern University in Chicago, said: 'This is an extremely promising new therapeutic that locks down aggressive prostate cancer cells so they don't move.
  147.  
  148. 'The spread of prostate cancer is what kills men. Cancer cells have a switch that tells them to keep moving all the time. This drug turns it off.'
  149.  
  150. The findings were presented at the annual meeting of the American Association for Cancer Research in Chicago.
  151.  
  152. Prof Bergan added: 'We envision that this drug, if shown to be effective in clinical trials, could be used to treat men diagnosed with prostate cancer, so they wouldn't need more aggressive procedures. Or, the drug could augment the effectiveness of surgery and radiation.'
  153.  
  154. Each year around 36,000 men in the UK are diagnosed with prostate cancer, and 10,000 die from the disease.
  155.    
  156.    
  157.    
  158.    
  159.    
  160. .
  161. 0
  162. 1
  163. 2
  164. 3
  165. 4
  166. 5
  167. 6
  168. 7
  169. 8
  170. 9
  171. !
  172. "
  173. #
  174. $
  175. %
  176. &
  177. '
  178. (
  179. )
  180. *
  181. +
  182. ,
  183. -
  184. /
  185. :
  186. ;
  187. <
  188. =
  189. >
  190. ?
  191. @
  192. A
  193. B
  194. C
  195. D
  196. E
  197. F
  198. G
  199. H
  200. I
  201. J
  202. K
  203. L
  204. M
  205. N
  206. O
  207. P
  208. Q
  209. R
  210. S
  211. T
  212. U
  213. V
  214. W
  215. X
  216. Y
  217. Z
  218. [
  219. \
  220. ]
  221. ^
  222. _
  223. `
  224. a
  225. b
  226. c
  227. d
  228. e
  229. f
  230. g
  231. h
  232. i
  233. j
  234. k
  235. l
  236. m
  237. n
  238. o
  239. p
  240. q
  241. r
  242. s
  243. t
  244. u
  245. v
  246. w
  247. x
  248. y
  249. z
  250. {
  251. |
  252. }
  253. ~
  254. ¡
  255. ¢
  256. £
  257. ¤
  258. ¥
  259. ¦
  260. §
  261. ¨
  262. ©
  263. ª
  264. «
  265. ¬
  266. ®
  267. ¯
  268. °
  269. ±
  270. ²
  271. ³
  272. ´
  273. µ
  274. ·
  275. ¸
  276. ¹
  277. º
  278. »
  279. ¼
  280. ½
  281. ¾
  282. ¿
  283. À
  284. Á
  285. Â
  286. Ã
  287. Ä
  288. Å
  289. Æ
  290. Ç
  291. È
  292. É
  293. Ê
  294. Ë
  295. Ì
  296. Í
  297. Î
  298. Ï
  299. Ð
  300. Ñ
  301. Ò
  302. Ó
  303. Ô
  304. Õ
  305. Ö
  306. ×
  307. Ø
  308. Ù
  309. Ú
  310. Û
  311. Ü
  312. Ý
  313. Þ
  314. ß
  315. à
  316. á
  317. â
  318. ã
  319. ä
  320. å
  321. æ
  322. ç
  323. è
  324. é
  325. ê
  326. ë
  327. ì
  328. í
  329. î
  330. ï
  331. ð
  332. ñ
  333. ò
  334. ó
  335. ô
  336. õ
  337. ö
  338. ÷
  339. ø
  340. ù
  341. ú
  342. û
  343. ü
  344. ý
  345. þ
  346. ÿ
  347. Œ
  348. Š
  349. Ÿ
  350. Ž
  351. ƒ
  352. ˆ
  353. ˜
  354.  
  355.  
  356. //----------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment