Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
|
|
@ -9,32 +9,52 @@ class Program
|
|||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string get1 = new WebClient().DownloadString("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json");
|
||||
string get2 = new WebClient().DownloadString("http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000");
|
||||
string get2 = new WebClient().DownloadString("http://www.rosettacode.org/w/index.php?"
|
||||
+"title=Special:Categories&limit=5000"
|
||||
);
|
||||
|
||||
ArrayList langs = new ArrayList();
|
||||
Dictionary<string, int> qtdmbr = new Dictionary<string, int>();
|
||||
|
||||
MatchCollection match1 = new Regex("\"title\":\"Category:(.+?)\"").Matches(get1);
|
||||
MatchCollection match2 = new Regex("title=\"Category:(.+?)\">.+?</a>[^(]*\\((\\d+) members\\)").Matches(get2);
|
||||
string cmcontinue = "";
|
||||
|
||||
foreach (Match lang in match1) langs.Add(lang.Groups[1].Value);
|
||||
do
|
||||
{
|
||||
string get1 = new WebClient().DownloadString("http://www.rosettacode.org/w/api.php?"
|
||||
+"action=query&list=categorymembers"
|
||||
+"&cmtitle=Category:Programming_Languages"
|
||||
+"&cmlimit=500&format=json"
|
||||
+cmcontinue
|
||||
);
|
||||
cmcontinue = "";
|
||||
MatchCollection languageMatch = new Regex("\"title\":\"Category:(.+?)\"").Matches(get1);
|
||||
MatchCollection cmcontinueMatch = new Regex("cmcontinue\":\"([a-z0-9A-Z|]*)\"").Matches(get1);
|
||||
foreach (Match lang in languageMatch) langs.Add(lang.Groups[1].Value);
|
||||
foreach (Match more in cmcontinueMatch) cmcontinue = "&cmcontinue=" + more.Groups[1].Value;
|
||||
}
|
||||
while( cmcontinue != "" );
|
||||
|
||||
MatchCollection match2 =
|
||||
new Regex("title=\"Category:(.+?)\">.+?</a>[^(]*\\(([\\d,.]+) members\\)").Matches(get2);
|
||||
|
||||
foreach (Match match in match2)
|
||||
{
|
||||
if (langs.Contains(match.Groups[1].Value))
|
||||
{
|
||||
qtdmbr.Add(match.Groups[1].Value, Int32.Parse(match.Groups[2].Value));
|
||||
qtdmbr.Add(match.Groups[1].Value, Int32.Parse(match.Groups[2].Value
|
||||
.Replace(",",string.Empty)
|
||||
.Replace(".",string.Empty)));
|
||||
}
|
||||
}
|
||||
|
||||
string[] test = qtdmbr.OrderByDescending(x => x.Value).Select(x => String.Format("{0,3} - {1}", x.Value, x.Key)).ToArray();
|
||||
string[] test =
|
||||
qtdmbr.OrderByDescending(x => x.Value).Select(x => String.Format("{0,4} {1}", x.Value, x.Key)).ToArray();
|
||||
|
||||
int count = 1;
|
||||
|
||||
foreach (string i in test)
|
||||
{
|
||||
Console.WriteLine("{0,3}. {1}", count, i);
|
||||
Console.WriteLine("{0,4}: {1}", count, i);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
Imports System.Collections
|
||||
Imports System.Collections.Generic
|
||||
Imports System.Net
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Module RankLanguagesByPopularity
|
||||
|
||||
Private Class LanguageStat
|
||||
Public name As String
|
||||
Public count As Integer
|
||||
Public Sub New(name As String, count As Integer)
|
||||
Me.name = name
|
||||
Me.count = count
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Private Function CompareLanguages(x As LanguageStat, y As languageStat) As Integer
|
||||
Dim result As Integer = 0
|
||||
If x IsNot Nothing Or y IsNot Nothing Then
|
||||
If x Is Nothing Then
|
||||
result = -1
|
||||
ElseIf y Is Nothing
|
||||
result = 1
|
||||
Else
|
||||
result = - x.count.CompareTo(y.count) ' Sort descending count
|
||||
If result = 0 Then
|
||||
result = x.name.CompareTo(y.name) ' Sort ascending name
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
Return result
|
||||
End Function
|
||||
|
||||
Public Sub Main(ByVal args As String())
|
||||
|
||||
Dim languages As New List(Of LanguageStat)
|
||||
Dim basePage As String = "https://rosettacode.org/wiki/Category:Programming_Languages"
|
||||
Dim nextPage As String = basePage
|
||||
|
||||
Dim nextPageEx = New RegEx("<a href=""/wiki/Category:Programming_Languages([?]subcatfrom=[^""]*)""")
|
||||
Dim languageStatEx = _
|
||||
New Regex(">([^<]+?)</a>[^<]*<span title=""Contains *[0-9,.]* *[a-z]*, *([0-9,.]*) *page")
|
||||
|
||||
Do While nextPage <> ""
|
||||
Dim wc As New WebClient()
|
||||
Dim page As String = wc.DownloadString(nextPage)
|
||||
|
||||
nextPage = ""
|
||||
For Each link In nextPageEx.Matches(page)
|
||||
nextPage = basePage & link.Groups(1).Value
|
||||
Next link
|
||||
|
||||
For Each language In languageStatEx.Matches(page)
|
||||
Dim lCount As Integer = 0
|
||||
Dim lName As String = language.Groups(1).Value
|
||||
Dim countText As String = language.Groups(2).Value.Replace(",", "").Replace(".", "")
|
||||
If Not Integer.TryParse(countText, lCount)
|
||||
Console.Out.WriteLine(lName & "Invalid page count: <<" & countText & ">>")
|
||||
Else
|
||||
languages.Add(New LanguageStat(lName, lCount))
|
||||
End If
|
||||
Next language
|
||||
Loop
|
||||
|
||||
languages.Sort(AddressOf CompareLanguages)
|
||||
|
||||
Dim prevCount As Integer = -1
|
||||
Dim prevPosition As Integer = -1
|
||||
Dim position As Integer = 0
|
||||
For Each stat As LanguageStat In languages
|
||||
position += 1
|
||||
If stat.count <> prevCount Then
|
||||
prevPosition = position
|
||||
prevCount = stat.Count
|
||||
End If
|
||||
Console.Out.WriteLine(prevPosition.ToString.PadLeft(4) & ": " &
|
||||
stat.count.ToString.PadLeft(4) & " " & stat.name)
|
||||
Next stat
|
||||
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
Loading…
Add table
Add a link
Reference in a new issue