User:Vegan416/BludProgram

A quick and dirty C# program to check number of comments and text length per user in Talk page discussion. This can help measuring the two basic objective measurements related to accusations of bludgeoning as per WP:BLUD. Maybe in the future I'll try to add measurements for more complex ways of bludding.

Usage (offline. I still don't know Lua, and I'm not familiar with the Wikipedia scripting environment):


 * 1) Copy all text of the discussion from Source Editor to a simple text file and save file.
 * 2) Make sure all comments are signed properly. If they are not sign them properly in the text file.
 * 3) Run the program with the filename as command line parameter

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Collections;

namespace Blud { class Program {       public class usernameData : IComparable {           public int commentsNum; public int textLen;

public int CompareTo(object incomingobject) {

// Storing incoming object in temp variable of                 // current class type usernameData incomingUsernameData = incomingobject as usernameData;

return this.textLen.CompareTo(incomingUsernameData.textLen); }        }

static void Main(string[] args) {           StreamReader sr = new StreamReader(args[0]); string text = sr.ReadToEnd; StreamWriter sw = new StreamWriter(args[0]+".out.txt"); //sw.Write(text); int curIndex = 0; int sigsNum = 0; int textLen = 0; Dictionary usernamesTable = new Dictionary; while (curIndex < text.Length) {               int startOfSignature = text.IndexOf("[[User talk:", curIndex);                if (startOfSignature >= 0)                {                    int startOfUsername = startOfSignature + "[[User talk:".Length;                    int endOfUsername = text.IndexOf("|", startOfUsername);                    string username = text.Substring(startOfUsername, endOfUsername - startOfUsername);                    int endOfComment = text.IndexOf("(UTC)", endOfUsername) + "(UTC)".Length;                    textLen += endOfComment - curIndex;                    //sw.WriteLine(username);                    if (usernamesTable.ContainsKey(username))                    {                        usernamesTable[username].commentsNum++;                        usernamesTable[username].textLen += endOfComment - curIndex;                    }                    else                    {                        usernamesTable[username]=new usernameData;                        usernamesTable[username].commentsNum = 1;                        usernamesTable[username].textLen = endOfComment - curIndex;                    }                    curIndex = endOfComment;                    sigsNum++;                }                else                {                    curIndex = text.Length;                }            }            sw.WriteLine("Total Signature Number: "+ sigsNum.ToString);            sw.WriteLine("Total Text Length: " + textLen.ToString);            //sw.WriteLine("Total Text Length: " + text.Length.ToString);

List> usernameList = usernamesTable.OrderByDescending(kp => kp.Value).ToList;

foreach (KeyValuePair usernameNode in usernameList) {               sw.Write(usernameNode.Key.PadRight(25) + "comments: " + usernameNode.Value.commentsNum.ToString.PadLeft(4)); sw.Write("(" + (usernameNode.Value.commentsNum*100/sigsNum).ToString.PadLeft(3) + "%). Text Length: "); sw.WriteLine(usernameNode.Value.textLen.ToString.PadLeft(7) + " (" + (usernameNode.Value.textLen*100/textLen).ToString.PadLeft(3) + "%)."); }           sw.Flush; }   } }