Task

Find all    <lang>    tags without a language specified in the text of a page.

Display counts by language section:

Description

<lang>Pseudocode</lang>

=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>

=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>

should display something like

2 bare language tags.

1 in perl
1 in no language



Extra credit

Allow multiple files to be read.   Summarize all results by language:

5 bare language tags.

2 in c ([[Foo]], [[Bar]])
1 in perl ([[Foo]])
2 in no language ([[Baz]])



Extra extra credit

Use the   Media Wiki API   to test actual RC tasks.




 
-module( find_bare_lang_tags ).
 
-export( [task/0] ).
 
task() ->
	{ok, Binary} = file:read_file( "priv/find_bare_lang_tags_1" ),
	Lines = string:tokens( erlang:binary_to_list(Binary), "\n" ),
	{_Lang, Dict} = lists:foldl( fun count_empty_lang/2, {"no language", dict:new()}, Lines ),
	Count_langs = [{dict:fetch(X, Dict), X} || X <- dict:fetch_keys(Dict)],
	io:fwrite( "~p bare language tags.~n", [lists:sum([X || {X, _Y} <- Count_langs])] ),
	[io:fwrite( "~p in ~p~n", [X, Y] ) || {X, Y} <- Count_langs].
 
 
 
count_empty_lang( Line, {Lang, Dict} ) ->
	Empty_lang = string:str( Line, "<lang>" ),
	New_dict = dict_update_counter( Empty_lang, Lang, Dict ),
	New_lang = new_lang( string:str( Line,"=={{header|" ), Line, Lang ),
	{New_lang, New_dict}.
 
dict_update_counter( 0, _Lang, Dict ) -> Dict;
dict_update_counter( _Start, Lang, Dict ) -> dict:update_counter( Lang, 1, Dict ).
 
new_lang( 0, _Line, Lang ) -> Lang;
new_lang( _Start, Line, _Lang ) ->
	Start = string:str( Line, "|" ),
	Stop = string:rstr( Line, "}}==" ),
	string:sub_string( Line, Start+1, Stop-1 ).
 