Today I decided to find out which are the most common Bulgarian words in the Bulgarian Wikipedia. And I found out. ;) Further down in the post I will explain how I did the analysis and, more interestingly, which are the most common letters and words. Besides a list of how often each letter occurs, there is a list of the top 100 most frequent words (together with their counts) and a list of the 550 most frequent words (without the counts). I have also added the code of the program, an explanation of how it works, and a text file containing every word found, together with the number of times it occurs across the articles of the Bulgarian Wikipedia.
A little statistics
220,681 articles were analysed. In them a total of 46,707,608 words containing only Bulgarian letters were found, of which 714,876 are distinct. The total number of letters in those words is 259,452,643, which works out at an average of 5.55 letters per Bulgarian word. The data is current as of 20 August 2011. The three most common words are "на", "и" and "в". The ten most common letters are: "а", "и", "е", "о", "н", "т", "р", "с", "л" and "в".
How was the analysis done?
Mostly out of curiosity. Well, and a little code. ;) First, so that I would not have to write a web crawler that goes madly around the Wikipedia pages, I did a short piece of research and found something very interesting. Wikipedia regularly backs up all of its data, and most of those backups are public. What is not public? User data, for example. Everything else related to the content is completely public: dumped from the database, exported to XML, compressed, backed up and shared. You can find these backups тук. The dump I used for the analysis is from "2011-08-19 22:37:35", and specifically "Articles, templates, image descriptions, and primary meta-pages", containing the latest versions of the articles in the Bulgarian Wikipedia - exactly 220,681 of them. Here is a direct link to the file: pages-articles.xml.bz2 (size: 147.4 MB). As I mentioned, this archive contains an XML file. To process it I used my favourite language, C#. I knocked together a console application that uses XmlTextReader to parse the data from the XML file. Why did I choose XmlTextReader? Because it processes the file element by element, and for that reason works rather well with huge files - and the XML file is over 1 GB once unpacked. To count the words I had to write a WordsDictionary class, which is really just a wrapper around Dictionary<string, int>. Every character that is not a letter is stripped from each word, and then only the words containing letters from the Bulgarian alphabet alone are kept. All words are lower-cased, so that identical words starting with a capital and with a lower-case letter count as the same word. And one excuse: I make no claim at all that the code is of good quality - the point of writing it was to see the result of its work, not to be able to reuse it. So, here is the body of the Main method:
class Program
{
static void Main(string[] args)
{
WordsDictionary words = new WordsDictionary();
using (XmlTextReader reader =
new XmlTextReader("bgwiki-20110819-pages-articles.xml"))
{
while (reader.Read())
{
if (reader.Name == "title" || reader.Name == "text")
{
string text = reader.ReadInnerXml();
words.AddWords(text);
}
}
}
Console.WriteLine("Parsing ready!");
words.ExportToTextFile("words.txt");
Console.WriteLine("Exporting ready!");
Console.ReadLine();
}
}
And here is the content of the WordsDictionary.
class WordsDictionary
{
Dictionary< string, int > words =
new Dictionary< string, int >();
public void ExportToTextFile(string fileName)
{
using (StreamWriter sw = new StreamWriter(fileName))
{
var sortedList = words.OrderByDescending(x => x.Value);
foreach (var item in sortedList)
{
sw.WriteLine("{0} {1}", item.Key, item.Value);
}
}
}
private void AddWord(string word)
{
if (string.IsNullOrWhiteSpace(word) ||
!word.ContainsOnlyCyrilicChars())
{
return;
}
//Console.WriteLine(word);
if (words.ContainsKey(word))
{
words[word]++;
}
else
{
words.Add(word, 1);
}
}
public void AddWords(string text)
{
text = text.HTMLDecodeSpecialChars();
StringBuilder sb = new StringBuilder(text.Length);
foreach (char ch in text)
{
if (char.IsLetter(ch))
{
sb.Append(ch);
}
else
{
sb.Append(' ');
}
}
text = sb.ToString().ToLower();
MatchCollection collection = Regex.Matches(text, @"[\S]+");
foreach (Match item in collection)
{
this.AddWord(item.Value.Trim());
}
}
}
You may also find the static class useful, in which I define two extension methods on the String class that I use in WordsDictionary.
public static class StringExtensions
{
public static string HTMLDecodeSpecialChars(this string s)
{
return HttpUtility.HtmlDecode(s);
}
public static bool ContainsOnlyCyrilicChars(this string word)
{
char[] bgletters = { 'а', 'б', 'в', 'г', 'д', 'е', 'ж',
'з', 'и', 'й', 'к', 'л', 'м', 'н',
'о', 'п', 'р', 'с', 'т', 'у', 'ф',
'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ь',
'ю', 'я' };
foreach (var ch in word)
{
if (!bgletters.Contains(ch)) return false;
}
return true;
}
}
How often does each letter occur?
Another analysis occurred to me afterwards: to see how often the Bulgarian letters occur in Wikipedia, which to a large extent gives a clear picture of how often the letters occur in Bulgarian as a whole. So, if you are interested in which are the most common letters, here is the list of our favourite 30 letters, together with the count and the percentage of their occurrences:
а => 29403401 times => 11,33%
и => 26352009 times => 10,16%
е => 22625006 times => 8,72%
о => 21607305 times => 8,33%
н => 18812860 times => 7,25%
т => 18343878 times => 7,07%
р => 16328288 times => 6,29%
с => 13654518 times => 5,26%
л => 10384543 times => 4,00%
в => 9972137 times => 3,84%
к => 9397716 times => 3,62%
п => 8942733 times => 3,45%
д => 7756814 times => 2,99%
м => 5906208 times => 2,28%
б => 5726892 times => 2,21%
г => 4740094 times => 1,83%
з => 4382215 times => 1,69%
я => 4367464 times => 1,68%
ъ => 3673393 times => 1,42%
у => 3623023 times => 1,40%
ч => 2484600 times => 0,96%
ц => 2333927 times => 0,90%
й => 1696822 times => 0,65%
ж => 1533117 times => 0,59%
ф => 1517443 times => 0,58%
х => 1108573 times => 0,43%
щ => 1062451 times => 0,41%
ш => 1033321 times => 0,40%
ю => 516766 times => 0,20%
ь => 165126 times => 0,06%
Total: 259,452,643 letters
Which are the 100 most common words?
на => 2299352 times
и => 1228974 times
в => 1155405 times
потребител => 972950 times
е => 843001 times
от => 771623 times
за => 541691 times
се => 534455 times
пр => 502970 times
беседа => 488892 times
б => 478232 times
специални => 475226 times
приноси => 458098 times
с => 415268 times
да => 360815 times
г => 357602 times
категория => 329792 times
по => 311804 times
през => 268270 times
са => 205503 times
като => 187945 times
а => 157099 times
си => 148075 times
не => 142846 times
година => 140927 times
до => 131248 times
българия => 120406 times
шаблон => 118392 times
че => 111265 times
след => 108299 times
име => 108121 times
това => 102096 times
му => 100706 times
при => 96585 times
най => 94397 times
към => 92054 times
български => 88771 times
език => 88496 times
или => 85181 times
картинка => 84771 times
флаг => 81194 times
има => 77141 times
които => 76721 times
но => 75737 times
дата => 71732 times
място => 70713 times
той => 69956 times
софия => 68527 times
който => 68059 times
мъниче => 67803 times
град => 66775 times
н => 66245 times
роден => 65361 times
те => 64738 times
община => 63671 times
във => 63266 times
област => 60594 times
икона => 60303 times
време => 57472 times
години => 56731 times
македония => 55292 times
война => 54894 times
част => 53917 times
виж => 53028 times
век => 52999 times
население => 52339 times
което => 50802 times
село => 50443 times
която => 50163 times
със => 49840 times
много => 48210 times
сащ => 46604 times
описание => 46483 times
други => 45956 times
може => 45390 times
окръг => 44525 times
код => 44177 times
уикипедия => 43859 times
препратки => 43822 times
един => 42952 times
история => 42765 times
външни => 42401 times
също => 41582 times
американски => 41546 times
този => 41256 times
вид => 40615 times
всички => 40306 times
около => 40125 times
та => 39540 times
между => 39029 times
отбор => 38536 times
още => 38478 times
починал => 37560 times
карта => 36234 times
група => 36152 times
инфо => 36071 times
страна => 36061 times
селото => 35585 times
само => 35239 times
го => 35147 times
Notes on the first 100 words
The first few words are, as expected, mostly prepositions and conjunctions, since those are the most used little words in Bulgarian anyway. Among them "пр" appears. I became curious where those 500,000-plus occurrences of these two letters come from. It turned out that the abbreviations "пр.н.е." (BC) and "пр.Хр." (before Christ) are quite common in Wikipedia, which pushes "пр" into the leading places. The words "потребител" (user), "беседа" (talk), "специални" (special), "приноси" (contributions), "категория" (category), "шаблон" (template), "мъниче" (stub) and "картинка" (image) are core Wikipedia terms, which explains how often they occur in the articles. The single letters "б" and "г" come from abbreviations (from names such as "Б." and from "г." for година, meaning year). Quite common are the words "България" (Bulgaria), "български" (Bulgarian), "език" (language), "година" (year), "дата" (date), "място" (place), "София" (Sofia), "град" (city), "роден" (born), "община" (municipality), "област" (province), "икона" (icon), "време" (time) and "война" (war). What stands out is how often "Македония" (Macedonia), "САЩ" (the USA) and "американски" (American) occur in the Bulgarian articles.
Download the full list
I have attached a text file with the full list of all 714,876 words found in the Bulgarian Wikipedia. The format of the file is as follows: on each line there is a word and its number of occurrences, separated by a space. The file is sorted by the number of occurrences of each word in descending order. The encoding of the file is "UTF-8 without BOM", which means you will most likely have to select the UTF-8 encoding by hand if you open the file in some illiterate text editor. ;) You can download the file by clicking тук or on the large picture to the left. Enjoy reading words! You can use the list to learn a new word. An exercise for enthusiasts.
List of the 550 most common words
What follows is a list of the 550 most common words in the Bulgarian Wikipedia, ordered by number of occurrences:
на, и, в, потребител, е, от, за, се, пр, беседа, б, специални, приноси, с, да, г, категория, по, през, са, като, а, си, не, година, до, българия, шаблон, че, след, име, това, му, при, най, към, български, език, или, картинка, флаг, има, които, но, дата, място, той, софия, който, мъниче, град, н, роден, те, община, във, област, икона, време, години, македония, война, част, виж, век, население, което, село, която, със, много, сащ, описание, други, може, окръг, код, уикипедия, препратки, един, история, външни, също, американски, този, вид, всички, около, та, между, отбор, още, починал, карта, група, инфо, страна, селото, само, го, п, м, става, английски, то, под, така, според, ще, източници, както, германия, република, май, август, една, файл, когато, юли, септември, биография, франция, тази, империя, юни, ширина, иван, р, височина, октомври, януари, март, където, души, намира, стр, голяма, ноември, тя, срещу, мини, им, т, април, георги, щати, награда, декември, център, тези, него, площ, футбол, портрет, над, река, км, италия, името, ако, национален, февруари, няколко, съединени, късно, жители, започва, някои, преди, сайт, българска, държава, фк, русия, тях, края, димитър, началото, световна, бъде, две, населението, градове, града, път, край, днес, без, портал, гърция, трябва, селище, състав, заедно, няма, първата, александър, дължина, район, бил, пояснение, бележки, страница, англия, върху, първенство, дем, официален, страната, македоно, регион, провинция, страници, често, филм, европа, я, поради, села, армия, вече, повече, какво, различни, литература, университет, сезон, петър, сорткат, хора, министър, българи, чрез, д, съюз, партия, география, васил, консул, българската, въпреки, два, малко, дясно, система, испания, к, наставка, света, три, данни, едно, северна, футболист, могат, албум, вижте, герб, друго, използва, южна, ги, смъртта, работи, получава, у, сайта, били, организация, статия, св, имат, българско, участва, първи, втората, ти, списък, френски, пфк, там, руски, сред, заглавие, музика, ден, римски, политик, църква, христо, прави, завършва, обаче, управление, формула, марк, пловдив, стефан, училище, информация, общо, никола, др, първа, филми, тук, места, отново, император, член, актьор, генерал, всеки, статистика, син, джон, района, свети, ми, великобритания, части, немски, надразделение, пост, левски, нова, нея, период, все, писател, тип, времето, резултат, тъй, групата, ист, втора, например, известен, освен, бразилия, начин, де, сили, аз, баща, първият, добре, първите, голям, съм, живот, купа, море, крал, превод, докато, мария, пощенски, деца, насам, шаблони, дни, рим, личности, пренасочване, гръцки, революционер, автор, дори, битка, ксн, подс, сочи, своя, защото, нови, връзка, главно, тогава, брой, събития, николай, сърбия, първо, страни, ню, гр, африка, швеция, гео, председател, остров, раждане, уеб, отбори, статии, луций, бъдат, право, варна, била, белгия, семейство, би, човек, култура, лига, умира, планина, имена, играе, против, надморска, езици, обикновено, двете, води, сан, америка, стадион, политика, периода, стара, разположение, големи, почти, актьори, о, фон, дивизия, уебсайт, заради, пред, режисьор, кръг, ссср, опълчение, щата, договор, войната, отбора, номер, щат, текст, представка, голямата, западна, било, острови, групи, световен, борис, голове, награди, значение, първия, печели, изтриване, османската, римска, позиция, михаил, год, остава, ли, цар, цска, статут, статията, полша, малки, областта, играч, москва, съвет, телефонен, работа, игри, президент, всяка, турция, историята, север, times, константин, румъния, гай, препратка, япония, австралия, цел, мача, италиански, стил, египет, изток, й, видове, повечето, род, жени, шампион, въстание, известни, треньор, минути, австрия, шампионат, селища, дава, включва, поле, участие, унгария, степен, тел, манастир, среща, азия, втори, вода, таблицата, административен, родени, нов, използват, етнография, николов, хората, карл, друг, църквата, песен, региона, калифорния, продължава, ред, вероятно, разположен, особено, вморо, живота, пише, сега, исторически, книга, футболисти, своята, власт.