Rosetta Code/Find bare lang tags: Difference between revisions
Content deleted Content added
Added missing "getStr" |
|||
Line 1,101: | Line 1,101: | ||
Total bare <lang> for language J: (3) |
Total bare <lang> for language J: (3) |
||
Total bare <lang> for language Mathematica: (1)</pre> |
Total bare <lang> for language Mathematica: (1)</pre> |
||
=={{header|Objek}}== |
|||
With extra credit |
|||
<lang objeck>use Web.HTTP; |
|||
use Query.RegEx; |
|||
use Collection.Generic; |
|||
class Program { |
|||
function : Main(args : String[]) ~ Nil { |
|||
master_tasks := ProcessTasks(["100_doors", "99_bottles_of_beer", "Filter", "Array_length", "Greatest_common_divisor", "Greatest_element_of_a_list", "Greatest_subsequential_sum"]); |
|||
"---"->PrintLine(); |
|||
PrintTasks(master_tasks); |
|||
} |
|||
function : ProcessTasks(tasks : String[]) ~ MultiMap<String, String> { |
|||
master_tasks := MultiMap->New()<String, String>; |
|||
each(i : tasks) { |
|||
task := tasks[i]; |
|||
"Processing '{$task}'..."->PrintLine(); |
|||
matches := ProcessTask(task); |
|||
langs := matches->GetKeys()<String>; |
|||
each(j : langs) { |
|||
master_tasks->Insert(langs->Get(j), task); |
|||
}; |
|||
}; |
|||
return master_tasks; |
|||
} |
|||
function : ProcessTask(task : String) ~ Set<String> { |
|||
langs := Set->New()<String>; |
|||
header_regex := RegEx->New("==\\{\\{header\\|(\\w|/|-|_)+\\}\\}=="); |
|||
lang_regex := RegEx->New("<(\\s)*lang(\\s)*>"); |
|||
url := "http://rosettacode.org/mw/index.php?action=raw&title={$task}"; |
|||
lines := HttpClient->New()->GetAll(url)->Split("\n"); |
|||
last_header : String; |
|||
each(i : lines) { |
|||
line := lines[i]; |
|||
# get header |
|||
header := header_regex->FindFirst(line); |
|||
if(<>header->IsEmpty()) { |
|||
last_header := HeaderName(header); |
|||
}; |
|||
# get language |
|||
lang := lang_regex->FindFirst(line); |
|||
if(lang->Size() > 0) { |
|||
if(last_header <> Nil) { |
|||
langs->Insert("{$last_header}"); |
|||
} |
|||
else { |
|||
langs->Insert("no language"); |
|||
}; |
|||
}; |
|||
}; |
|||
return langs; |
|||
} |
|||
function : HeaderName(lang_str : String) ~ String { |
|||
start := lang_str->Find('|'); |
|||
if(start > -1) { |
|||
start += 1; |
|||
end := lang_str->Find(start, '}'); |
|||
return lang_str->SubString(start, end - start); |
|||
}; |
|||
return ""; |
|||
} |
|||
function : PrintTasks(tasks : MultiMap<String, String>) ~ Nil { |
|||
keys := tasks->GetKeys()<String>; |
|||
each(i : keys) { |
|||
buffer := ""; |
|||
key := keys->Get(i); |
|||
values := tasks->Find(key)<String>; |
|||
count := values->Size(); |
|||
buffer += "{$count} in {$key} ("; |
|||
each(j : values) { |
|||
value := values->Get(j); |
|||
buffer += "[[{$value}]]"; |
|||
if(j + 1 < values->Size()) { |
|||
buffer += ", "; |
|||
}; |
|||
}; |
|||
buffer += ")"; |
|||
buffer->PrintLine(); |
|||
}; |
|||
} |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Processing '100_doors'... |
|||
Processing '99_bottles_of_beer'... |
|||
Processing 'Filter'... |
|||
Processing 'Array_length'... |
|||
Processing 'Greatest_common_divisor'... |
|||
Processing 'Greatest_element_of_a_list'... |
|||
Processing 'Greatest_subsequential_sum'... |
|||
--- |
|||
1 in 11l ([[100_doors]]) |
|||
1 in Bracmat ([[Greatest_element_of_a_list]]) |
|||
1 in C1R ([[100_doors]]) |
|||
3 in ERRE ([[Greatest_common_divisor]], [[Greatest_element_of_a_list]], [[Greatest_subsequential_sum]]) |
|||
5 in EasyLang ([[100_doors]], [[Filter]], [[Array_length]], [[Greatest_common_divisor]], [[Greatest_element_of_a_list]]) |
|||
1 in Forth ([[Array_length]]) |
|||
1 in J ([[Array_length]]) |
|||
1 in Klingphix ([[99_bottles_of_beer]]) |
|||
1 in Mathprog ([[Greatest_subsequential_sum]]) |
|||
1 in MiniScript ([[Greatest_element_of_a_list]]) |
|||
1 in OCaml ([[99_bottles_of_beer]]) |
|||
1 in PHP ([[Greatest_subsequential_sum]]) |
|||
1 in PostScript ([[100_doors]]) |
|||
2 in Ring ([[Filter]], [[Greatest_common_divisor]]) |
|||
1 in Scilab ([[100_doors]]) |
|||
2 in Ursa ([[100_doors]], [[99_bottles_of_beer]]) |
|||
1 in gnuplot ([[Greatest_common_divisor]]) |
|||
1 in ooRexx ([[Greatest_element_of_a_list]]) |
|||
4 in uBasic/4tH ([[100_doors]], [[99_bottles_of_beer]], [[Greatest_common_divisor]], [[Greatest_element_of_a_list]]) |
|||
</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |