Compare commits

..

No commits in common. "example_7" and "master" have entirely different histories.

4 changed files with 0 additions and 4555 deletions

View File

@ -1,15 +0,0 @@
.dub
docs.json
__dummy.html
docs/
/example_7
example_7.so
example_7.dylib
example_7.dll
example_7.a
example_7.lib
example_7-test-*
*.exe
*.o
*.obj
*.lst

View File

@ -1,9 +0,0 @@
{
"authors": [
"alexander"
],
"description": "Основные структуры данных.",
"license": "proprietary",
"name": "example_7",
"targetPath": "bin"
}

View File

@ -1,68 +0,0 @@
import std.algorithm, std.regex, std.range, std.stdio, std.string, std.ascii;
struct PersonaData
{
ulong totalWordsSpoken;
ulong[string] wordCount;
}
void addParagraph(string line, ref PersonaData[string] info)
{
line = strip(line);
auto sentence = line.find(". ");
if (sentence.empty)
{
return;
}
auto persona = line[0 .. $ - sentence.length];
sentence = toLower(strip(sentence[2 .. $]));
auto words = split(sentence, regex("[ \t,.;:?]+"));
auto data = persona in info;
if (data)
{
data.totalWordsSpoken += words.length;
foreach (word; words)
++data.wordCount[word];
}
else
{
PersonaData newData;
newData.totalWordsSpoken = words.length;
foreach (word; words)
newData.wordCount[word] = 1;
info[persona] = newData;
}
}
void printResults(PersonaData[string] info)
{
foreach (persona, data; info)
{
writefln("%20s %6u %6u", persona, data.totalWordsSpoken,
data.wordCount.length);
}
}
void main()
{
PersonaData[string] info;
string currentParagraph;
auto f = File("./source/hamlet.txt", "r");
foreach (line; f.byLine)
{
if (line.startsWith(" ")
&& line.length > 4
&& isAlpha(line[4]))
{
currentParagraph ~= line[3 .. $];
}
else if (line.startsWith(" ")
&& line.length > 2
&& isAlpha(line[2]))
{
addParagraph(currentParagraph, info);
currentParagraph = line[2 .. $].idup;
}
}
printResults(info);
}

File diff suppressed because it is too large Load Diff