Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,223 +0,0 @@
pragma Ada_2022;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Ordered_Sets;
with Ada.Strings.Unbounded.Less_Case_Insensitive;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with AWS.Client; use AWS.Client;
with AWS.Messages; use AWS.Messages;
with AWS.Response;
procedure Rank_Languages_By_Popularity is
use Ada.Strings;
function "+" (S : String) return Unbounded_String
renames To_Unbounded_String;
type A_Language_Count is
record
Count : Natural := 0;
Language : Unbounded_String;
end record;
function "=" (L, R : A_Language_Count) return Boolean is
begin
return L.Language = R.Language;
end "=";
function "<" (L, R : A_Language_Count) return Boolean is
begin
-- Sort by 'Count' and then by Language name
return L.Count < R.Count
or else (L.Count = R.Count
and then Less_Case_Insensitive
(Left => L.Language,
Right => R.Language));
end "<";
package Sets is new Ada.Containers.Ordered_Sets (A_Language_Count);
use Sets;
Counts : Set;
procedure Find_Counts (S : String) is
function Strip_Character (S : String; C : Character) return String is
S_Copy_Str : String (1 .. S'Length);
S_Copy_Index : Natural := 0;
begin
for I in S'Range loop
if S (I) /= C then
S_Copy_Index := S_Copy_Index + 1;
S_Copy_Str (S_Copy_Index) := S (I);
end if;
end loop;
return S_Copy_Str (S_Copy_Str'First .. S_Copy_Index);
end Strip_Character;
function Ignore_Category (L : String) return Boolean is
type Unbounded_String_Array is array (Positive range <>)
of Unbounded_String;
-- This list is quite comprehensive, but not complete
Categories_To_Ignore : Unbounded_String_Array := [
+"Pages with syntax highlighting errors",
+"Programming",
+"Examples needing attention",
+"Tasks needing attention",
+"Language users",
+"Implementations",
+"Solutions by ",
+"Maintenance/OmitCategoriesCreated",
+"Collection Members",
+"Pages with too many expensive parser function calls",
+"Garbage collection",
+" User",
+"SQL User",
+"Typing",
+"Parameter passing",
+"Execution method",
+"Unimplemented tasks by language",
+"Wolfram Language",
+"/Omit",
+"Wren-",
+"WrenGo",
+"Phix/",
+"PhixClass",
+"Basic language learning",
+"Encyclopedia",
+"RCTemplates",
+"SysUtils",
+"Action! ",
+"Text processing",
+"Image processing",
+"Scala Digital Signal Processing",
+"List processing",
+"Digital signal processing",
+"Processing Python",
+"Classic CS problems and programs",
+"Brainf*** related",
+"Data Structures",
+"Perl modules",
+"Perl/",
+"Perl:LWP",
+"Perl 6 related",
+"Flow control",
+"Excessively difficult task",
+"WikiStubs",
+"Impl needed",
+"Recursion"
];
begin
for Category of Categories_To_Ignore loop
declare
Category_At : constant Natural :=
Index (+To_Lower (L),
To_Lower (To_String (Category)));
begin
if Category_At /= 0 then
return True;
end if;
end;
end loop;
return False;
end Ignore_Category;
Title_Str : constant String := "title=""Category:";
End_A_Tag_Str : constant String := "</a>";
Space_Paren_Str : constant String := " (";
Title_At : constant Natural := Index (S, Title_Str);
begin
if Title_At /= 0 then
declare
Closing_Bracket_At : constant Natural :=
Index (S (Title_At + Title_Str'Length .. S'Last), ">");
End_A_Tag_At : constant Natural :=
Index (S (Closing_Bracket_At + 1 .. S'Last), End_A_Tag_Str);
Language : constant String :=
S (Closing_Bracket_At + 1 .. End_A_Tag_At - 1);
Space_Paren_At : constant Natural :=
Index (S (End_A_Tag_At + 1 .. S'Last), Space_Paren_Str);
Space_At : constant Natural :=
Index (S (Space_Paren_At + Space_Paren_Str'Length + 1
.. S'Last),
" ");
Count : constant Natural :=
Natural'Value (
Strip_Character (
S (Space_Paren_At +
Space_Paren_Str'Length
.. Space_At - 1),
','));
begin
if Closing_Bracket_At /= 0
and then End_A_Tag_At /= 0
and then Space_Paren_At /= 0
and then Space_At /= 0
then
begin
if Ignore_Category (Language) = False then
Counts.Insert (New_Item => (Count, +Language));
end if;
exception
when Constraint_Error =>
Put_Line (Standard_Error, "Warning: repeated language: " &
Language);
-- Ignore repeated results.
null;
end;
end if;
-- Recursively parse the string for languages and counts
Find_Counts (S (Space_At + 1 .. S'Last));
end;
end if;
end Find_Counts;
Place : Natural := 1;
procedure Display (C : Cursor) is
begin
Put (Place, Width => 1); Put (". ");
Put (Element (C).Count, Width => 1); Put (" - ");
Put_Line (To_String (Element (C).Language));
Place := Place + 1;
end Display;
Http_Source : constant AWS.Response.Data :=
AWS.Client.Get ("http://rosettacode.org/w/index.php?" &
"title=Special:Categories&limit=5000",
Follow_Redirection => True);
Status : Status_Code;
begin
Put_Line ("Getting website data...");
Status := AWS.Response.Status_Code (Http_Source);
if Status not in Success then
Put_Line ("Unable to retrieve data => Status Code :" &
Image (Status) &
" Reason :" & Reason_Phrase (Status));
raise Connection_Error;
end if;
Put_Line ("Finding categories...");
Find_Counts (AWS.Response.Message_Body (Http_Source));
Put_Line ("Displaying categories...");
Counts.Reverse_Iterate (Display'Access);
Put_Line ("Process complete.");
end Rank_Languages_By_Popularity;

View file

@ -10,7 +10,7 @@ Function DownloadString(url As String) As String
Const BUFFER_SIZE As Integer = 8192
Dim As HINTERNET hInternet, hConnect
Dim As String resultado
Dim As ZString Ptr buffer = Allocate(BUFFER_SIZE)
Dim As ZString * BUFFER_SIZE buffer
Dim As DWORD bytesRead
hInternet = InternetOpen("FreeBASIC", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0)
@ -23,14 +23,13 @@ Function DownloadString(url As String) As String
End If
Do
If InternetReadFile(hConnect, buffer, BUFFER_SIZE - 1, @bytesRead) = 0 Then Exit Do
If InternetReadFile(hConnect, @buffer, BUFFER_SIZE - 1, @bytesRead) = 0 Then Exit Do
If bytesRead = 0 Then Exit Do
resultado &= Left(*buffer, bytesRead)
resultado &= Left(*Cast(ZString Ptr, @buffer), bytesRead)
Loop
InternetCloseHandle(hConnect)
InternetCloseHandle(hInternet)
Deallocate(buffer)
Return resultado
End Function

View file

@ -1,49 +1,46 @@
$define RCLANGS "http://rosettacode.org/mw/api.php?format=xml&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=500&prop=categoryinfo"
$define RCUA "User-Agent: Unicon Rosetta 0.1"
$define RCXUA "X-Unicon: http://unicon.org/"
$define RCLANGS "https://rosettacode.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=500&prop=categoryinfo&format=xml"
link strings
link hexcvt
procedure main()
procedure main(A)
limit := \A[1] # Limit the output?
cnt := create seq()
last := -1
every pair := !reverse(sort(langs := tallyPages(),2)) do {
n := if last ~=:= pair[2] then @cnt else (@cnt,"")
write(right(n,4),": ",left(pair[1],30,". "),right(pair[2],10,". "))
if 0 >= (\limit -:= 1) then break
}
write(*langs, " languages")
end
# Generate page counts for each language
procedure tallyPages(url)
/url := RCLANGS
procedure tallyPages()
counts := table()
continue := ""
while \(txt := ReadURL(url||continue)) do {
while \(txt := ReadURL(RCLANGS||continue)) do {
txt ? {
if tab(find("gcmcontinue=")) then {
continue := "&"||tab(upto('"'))
move(1)
continue ||:= tab(upto('"'))
}
else continue := ""
while tab(find("<page ") & find(s := "title=\"Category:")+*s) do {
lang := tab(upto('"'))
tab(find(s := "pages=\"")+*s)
counts[lang] := numeric(tab(upto('"')))
}
if continue == "" then return counts
continue := getContinue() | break
}
}
return counts
end
procedure getContinue()
gcm := "gcmcontinue="
return (tab(1),"&"||2(tab(find(gcm)),=gcm,="\"")||tab(upto('"')))
end
procedure ReadURL(url) #: read URL into string
page := open(url,"m",RCUA,RCXUA) | stop("Unable to open ",url)
text := ""
if page["Status-Code"] < 300 then while text ||:= reads(page,-1)
else write(&errout,image(url),": ",
page["Status-Code"]," ",page["Reason-Phrase"])
page := open(url,"m-") | stop("Unable to open ",url,"\n",&errno,"->",&errortext)
if page["Status-Code"] < 300 then text := reads(page,-1)
else write(&errout,"ERROR: ",&errout," -> ",&errortext)
close(page)
return text
end

View file

@ -1,27 +0,0 @@
$get1 = (New-Object Net.WebClient).DownloadString("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=700&format=json")
$get2 = (New-Object Net.WebClient).DownloadString("http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000")
$match1 = [regex]::matches($get1, "`"title`":`"Category:(.+?)`"")
$match2 = [regex]::matches($get2, "title=`"Category:([^`"]+?)`">[^<]+?</a>[^\(]*\((\d+) members\)")
$r = 1
$langs = $match1 | foreach { $_.Groups[1].Value.Replace("\","") }
$res = $match2 | sort -Descending {[Int]$($_.Groups[2].Value)} | foreach {
if ($langs.Contains($_.Groups[1].Value))
{
[pscustomobject]@{
Rank = "$r"
Members = "$($_.Groups[2].Value)"
Language = "$($_.Groups[1].Value)"
}
$r++
}
}
1..30 | foreach{
[pscustomobject]@{
"Rank 1..30" = "$($_)"
"Members 1..30" = "$($res[$_-1].Members)"
"Language 1..30" = "$($res[$_-1].Language)"
"Rank 31..60" = "$($_+30)"
"Members 31..60" = "$($res[$_+30].Members)"
"Language 31..60" = "$($res[$_+30].Language)"
}
}| Format-Table -AutoSize

View file

@ -1,20 +0,0 @@
$response = (New-Object Net.WebClient).DownloadString("http://rosettacode.org/wiki/Category:Programming_Languages")
$languages = [regex]::matches($response,'title="Category:(.*?)">') | foreach {$_.Groups[1].Value}
$response = [Net.WebClient]::new().DownloadString("http://rosettacode.org/w/index.php?title=Special:Categories&limit=5000")
$response = [regex]::Replace($response,'(\d+),(\d+)','$1$2')
$members = [regex]::matches($response,'<li><a[^>]+>([^<]+)</a>[^(]*[(](\d+) member[s]?[)]</li>') | foreach { [pscustomobject]@{
Members = [Int]($_.Groups[2].Value)
Language = [String]($_.Groups[1].Value)
}} | where {$languages.Contains($_.Language)} | sort -Descending Members
Get-Date -UFormat "Sample output on %d %B %Y at %R %Z"
$members | Select-Object -First 10 | foreach -Begin {$r, $rank, $count = 0, 0,-1} {
$r++
if ($count -ne $_.Members) {$rank = $r}
$count = $_.Members
$x = $_.Members.ToString("N0",[System.Globalization.CultureInfo]::CreateSpecificCulture('en-US'))
$entry = "($x entries)"
[String]::Format("Rank: {0,2} {1,15} {2}",$rank,$entry,$_.Language)
}

View file

@ -1,40 +0,0 @@
$languages = @{}
$Body = @{
format = 'json'
action = 'query'
generator = 'categorymembers'
gcmtitle = 'Category:Programming Languages'
gcmlimit = '200'
gcmcontinue = ''
continue = ''
prop = 'categoryinfo'
}
$params = @{
Method = 'Get'
Uri = 'http://rosettacode.org/mw/api.php'
Body = $Body
}
while ($true) {
$response = Invoke-RestMethod @params
$response.query.pages.PSObject.Properties | ForEach-Object {
if (($_.value.PSObject.Properties.Name -Contains 'title') -and ($_.value.PSObject.Properties.Name -Contains 'categoryinfo')) {
$languages[$_.value.title.replace('Category:', '')] = $_.value.categoryinfo.size
}
}
if ($response.PSObject.Properties.Name -Contains 'continue') {
$gcmcontinue = $response.continue.gcmcontinue
$params.Body.gcmcontinue = $gcmcontinue
} else {
break
}
}
$members = $languages.GetEnumerator() | sort -Descending value
Get-Date -UFormat "Sample output on %d %B %Y at %R %Z"
$members | Select-Object -First 10 | foreach -Begin {$r, $rank, $count = 0, 0,-1} {
$r++
if ($count -ne $_.Members) {$rank = $r}
$count = $_.Value
$x = $_.Value.ToString("N0",[System.Globalization.CultureInfo]::CreateSpecificCulture('en-US'))
$entry = "($x entries)"
[String]::Format("Rank: {0,2} {1,15} {2}",$rank, $entry, $_.Name)
}

View file

@ -1,118 +0,0 @@
'''''''''''''''''''''''''''''''''''''''''''''
' Rosetta Code/Rank Languages by Popularity '
' VBScript Implementation '
'...........................................'
'API Links (From C Code)
URL1 = "http://www.rosettacode.org/mw/api.php?format=json&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=500&prop=categoryinfo&rawcontinue"
URL2 = "http://www.rosettacode.org/mw/api.php?format=json&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=500&prop=categoryinfo&gcmcontinue="
'Get Contents of the API from the Web...
Function ScrapeGoat(link)
On Error Resume Next
ScrapeGoat = ""
Err.Clear
Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")
objHttp.Open "GET", link, False
objHttp.Send
If objHttp.Status = 200 And Err = 0 Then ScrapeGoat = objHttp.ResponseText
Set objHttp = Nothing
End Function
'HACK: Setup HTML for help of my partner/competitor that is better than me, JavaScript...
Set HTML = CreateObject("HtmlFile")
Set HTMLWindow = HTML.ParentWindow
''''''''''''''''''''
' Main code begins '
'..................'
On Error Resume Next
isComplete = 0 ' 1 -> Complete Already
cntLoop = 0 ' Counts Number of Loops Done
Set outputData = CreateObject("Scripting.Dictionary")
Do
'Scrape Data From API
If cntLoop = 0 Then strData = ScrapeGoat(URL1) Else strData = ScrapeGoat(URL2 & gcmCont)
If Len(strData) = 0 Then
Set HTML = Nothing
WScript.StdErr.WriteLine "Processing of data stopped because API query failed."
WScript.Quit(1)
End If
'Parse JSON HACK
HTMLWindow.ExecScript "var json = " & strData, "JavaScript"
Set ObjJS = HTMLWindow.json
Err.Clear 'Test if Query is Complete Already
batchCompl = ObjJS.BatchComplete
If Err.Number = 438 Then
'Query not yet complete. Get gcmContinue instead.
gcmCont = ObjJS.[Query-Continue].CategoryMembers.gcmContinue
Else
isComplete = 1 'Yes!
End If
'HACK #2: Put all language page ids into a JS array to be accessed by VBScript
HTMLWindow.ExecScript "var langs=new Array(); for(var lang in json.query.pages){langs.push(lang);}" & _
"var nums=langs.length;", "JavaScript"
Set arrLangs = HTMLWindow.langs
arrLength = HTMLWindow.nums
For i = 0 to arrLength - 1
BuffStr = "ObjJS.Query.Pages.[" & Eval("arrLangs.[" & i & "]") & "]"
EachStr = Eval(BuffStr & ".title")
Err.Clear
CntLang = Eval(BuffStr & ".CategoryInfo.Pages")
If InStr(EachStr, "Category:") = 1 And Err.Number = 0 Then
outputData.Add Replace(EachStr, "Category:", "", 1, 1), CntLang
End If
Next
cntLoop = cntLoop + 1
Loop While isComplete = 0
'The outputData now contains the data we need. We should now sort and print it!
'Make a 2D array with copy of outputData
arrRelease = Array()
ReDim arrRelease(UBound(outputData.Keys), 1)
outKeys = outputData.Keys
outItem = outputData.Items
For i = 0 To UBound(outKeys)
arrRelease(i, 0) = outKeys(i)
arrRelease(i, 1) = outItem(i)
Next
'Bubble Sort (Greatest to Least Number of Examples)
For i = 0 to UBound(arrRelease, 1)
For j = 0 to UBound(arrRelease, 1) - 1
If arrRelease(j, 1) < arrRelease(j + 1, 1) Then
temp1 = arrRelease(j + 1, 0)
temp2 = arrRelease(j + 1, 1)
arrRelease(j + 1, 0) = arrRelease(j, 0)
arrRelease(j + 1, 1) = arrRelease(j, 1)
arrRelease(j, 0) = temp1
arrRelease(j, 1) = temp2
End If
Next
Next
'Save contents to file instead to support Unicode Names
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set txtOut = objFSO.CreateTextFile(".\OutVBRC.txt", True, True)
txtOut.WriteLine "As of " & Now & ", RC has " & UBound(arrRelease) + 1 & " languages."
txtOut.WriteLine ""
For i = 0 to UBound(arrRelease)
txtOut.WriteLine arrRelease(i, 1) & " Examples - " & arrRelease(i, 0)
Next
'Successfully Done :)
Set HTML = Nothing
Set objFSO = Nothing
WScript.Quit(0)