91 lines
2.7 KiB
Text
91 lines
2.7 KiB
Text
( get-page
|
|
= url type
|
|
. !arg:(?url.?type)
|
|
& sys$(str$("wget -q -O wget.out \"" !url \"))
|
|
& get$("wget.out",!type) { Type can be JSN, X ML, HT ML or just ML. }
|
|
)
|
|
& ( get-langs
|
|
= arr lang
|
|
. :?arr
|
|
& !arg:? (.h2.) ?arg (h2.?) ? { Only analyse part of page between the h2 elements. }
|
|
& whl
|
|
' ( !arg
|
|
: ?
|
|
( a
|
|
. ?
|
|
( title
|
|
. @(?:"Category:" ?):?lang
|
|
& !lang !arr:?arr
|
|
)
|
|
?
|
|
)
|
|
?arg
|
|
)
|
|
& !arr
|
|
)
|
|
& ( get-cats
|
|
= page langs list count pat li A Z
|
|
. !arg:(?page.?langs)
|
|
& 0:?list
|
|
& whl
|
|
' ( !langs:%?lang ?langs
|
|
& { Use macro substitution to create a fast pattern. }
|
|
' ( ?
|
|
(a.? (title.$lang) ?) { $lang is replaced by the actual language. }
|
|
?
|
|
(.a.)
|
|
@(?:? #?count " " ?)
|
|
)
|
|
: (=?pat)
|
|
& ( !page
|
|
: ?A
|
|
( (li.) ?li (.li.) ?Z
|
|
& !li:!pat
|
|
)
|
|
& !A !Z:?page { Remove found item from page. (Not necessary at all.)}
|
|
& !count
|
|
| 0 { The language has no examples. }
|
|
.
|
|
)
|
|
\L !lang { Bracmat normalizes a\Lx+b\Ly+a\Lz to a\L(x*z)+b\Ly, so }
|
|
+ !list { it's easy to collect categories with the same count. }
|
|
: ?list
|
|
)
|
|
& !list
|
|
)
|
|
& get-cats
|
|
$ ( get-page
|
|
$ ( "http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000"
|
|
. HT,ML
|
|
)
|
|
. get-langs
|
|
$ ( get-page
|
|
$ ( "http://rosettacode.org/wiki/Category:Programming_Languages"
|
|
. HT ML
|
|
)
|
|
)
|
|
)
|
|
: ?cats
|
|
& :?list
|
|
& whl
|
|
' ( !cats:(?count.)\L?tiedcats+?cats
|
|
& :?ties
|
|
& whl
|
|
' ( !tiedcats:@(?:"Category:" ?name)*?tiedcats
|
|
& !ties !name:?ties
|
|
)
|
|
& (!count.!ties) !list:?list
|
|
)
|
|
& 1:?rank
|
|
& whl
|
|
' ( !rank:?tiedRank
|
|
& !list:(?count.?ties) ?list
|
|
& whl
|
|
' ( !ties:%?name ?ties
|
|
& @(!tiedRank:? [?len) { We want some padding for the highest ranks. }
|
|
& @(" ":? [!len ?sp) { Skip blanks up to the length of the rank. }
|
|
& out$(str$(!sp !tiedRank ". " !count " - " !name))
|
|
& 1+!rank:?rank
|
|
)
|
|
)
|
|
& ;
|