Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -0,0 +1,41 @@
|
|||
( ( get-page
|
||||
=
|
||||
. sys$(str$("wget -q -O wget.out \"" !arg \"))
|
||||
& get$("wget.out",HT ML)
|
||||
)
|
||||
& get-page$"http://rosettacode.org/wiki/Category:Programming_Tasks"
|
||||
: ? (table.?) ?tasklist (.table.) ?
|
||||
& 0:?list
|
||||
& whl
|
||||
' ( !tasklist
|
||||
: ?
|
||||
( a
|
||||
. (href.@(?:"/wiki/" ?href)) (title.?title)
|
||||
& get-page$(str$("http://rosettacode.org/wiki/" !href))
|
||||
: ?task
|
||||
& 0:?cnt
|
||||
& whl
|
||||
' ( !task
|
||||
: ?
|
||||
( (span.(class.mw-headline) (id.?))
|
||||
?span
|
||||
(.span.)
|
||||
?task
|
||||
& !span
|
||||
: ?
|
||||
( a
|
||||
. (href.@(?:"/wiki/Category:" ?))
|
||||
(title.@(?:"Category:" ?))
|
||||
)
|
||||
@
|
||||
(.a.)
|
||||
?
|
||||
)
|
||||
& 1+!cnt:?cnt
|
||||
)
|
||||
& (!cnt.!title)+!list:?list
|
||||
)
|
||||
?tasklist
|
||||
)
|
||||
& lst$(list,taskfreq,NEW)
|
||||
)
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
use HTTP;
|
||||
use XML;
|
||||
|
||||
class RosettaCount {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
taks_xml := HttpGet("http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml");
|
||||
parser := XmlParser->New(taks_xml);
|
||||
if(parser->Parse()) {
|
||||
task_names := parser->FindElements("/api/query/categorymembers/cm");
|
||||
if(task_names <> Nil) {
|
||||
each(i : task_names) {
|
||||
task_name := task_names->Get(i)->As(XmlElement)->GetAttribute("title")->GetValue();
|
||||
task_url := "http://rosettacode.org/mw/index.php?title=";
|
||||
task_url->Append(task_name);
|
||||
task_url->Append("&action=raw");
|
||||
|
||||
task := HttpGet(task_url);
|
||||
counts := task->FindAll("=={{header|");
|
||||
if(counts->Size() > 0) {
|
||||
IO.Console->Print(UrlUtility->Decode(task_name))->Print(": ")->PrintLine(counts->Size());
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function : HttpGet(url : String) ~ String {
|
||||
xml := "";
|
||||
|
||||
client := HttpClient->New();
|
||||
lines := client->Get(url);
|
||||
each(i : lines) {
|
||||
xml->Append(lines->Get(i)->As(String));
|
||||
};
|
||||
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,25 @@
|
|||
import java.net.{URL, URLEncoder}
|
||||
import scala.io.Source.fromURL
|
||||
import scala.language.postfixOps
|
||||
|
||||
val allTasksURL = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
|
||||
val allTasks = xml.parsing.XhtmlParser(fromURL(new URL(allTasksURL)))
|
||||
object TaskCount extends App {
|
||||
import java.net.{ URL, URLEncoder }
|
||||
import scala.io.Source.fromURL
|
||||
|
||||
val regexExpr = "(?i)==\\{\\{header\\|".r
|
||||
def oneTaskURL(title: String) = "http://www.rosettacode.org/w/index.php?title=%s&action=raw" format URLEncoder.encode(title.replace(' ', '_'), "UTF-8")
|
||||
def count(title: String) = regexExpr findAllIn fromURL(new URL(oneTaskURL(title)))(io.Codec.UTF8).mkString length
|
||||
System.setProperty("http.agent", "*")
|
||||
val allTasksURL =
|
||||
"http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
|
||||
val allTasks = xml.parsing.XhtmlParser(fromURL(new URL(allTasksURL)))
|
||||
|
||||
val counts = for (task <- allTasks \\ "cm" \\ "@title" map (_.text)) yield scala.actors.Futures.future((task, count(task)))
|
||||
val regexExpr = "(?i)==\\{\\{header\\|".r
|
||||
|
||||
counts map (_.apply) map Function.tupled("%s: %d examples." format (_, _)) foreach println
|
||||
println("\nTotal: %d examples." format (counts map (_.apply._2) sum))
|
||||
def oneTaskURL(title: String) = {
|
||||
println(s"Check $title")
|
||||
"http://www.rosettacode.org/w/index.php?title=%s&action=raw" format URLEncoder.encode(title.replace(' ', '_'), "UTF-8")
|
||||
}
|
||||
|
||||
def count(title: String) = regexExpr findAllIn fromURL(new URL(oneTaskURL(title)))(io.Codec.UTF8).mkString length
|
||||
|
||||
val counts = for (task <- allTasks \\ "cm" \\ "@title" map (_.text)) yield scala.actors.Futures.future((task, count(task)))
|
||||
|
||||
counts map (_.apply) map Function.tupled("%s: %d examples." format (_, _)) foreach println
|
||||
println("\nTotal: %d examples." format (counts map (_.apply._2) sum))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue