Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task_3_Ushakova_Lyubov_P3222 #99

Open
wants to merge 2 commits into
base: task-3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/Gradle__com_google_guava_guava_22_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/Gradle__org_apache_commons_commons_lang3_3_4.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_0_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/Gradle__org_opentest4j_opentest4j_1_1_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/modules/osis_main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions .idea/modules/osis_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions osis.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="osis" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/out" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
45 changes: 37 additions & 8 deletions src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,49 @@

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.nio.charset.Charset;
import static java.nio.file.Files.readAllLines;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.io.IOException;


public class WarAndPeaceExercise {

public static String warAndPeace() {
final Path tome12Path = Paths.get("src", "main", "resources", "WAP12.txt");
final Path tome34Path = Paths.get("src", "main", "resources", "WAP34.txt");
public static String warAndPeace() throws IOException {

final Path tome12Path = Paths.get("src", "main", "resources", "WAP12.txt");
final Path tome34Path = Paths.get("src", "main", "resources", "WAP34.txt");

// TODO map lowercased words to its amount in text and concatenate its entries.
// TODO Iff word "котик" occurred in text 23 times then its entry would be "котик - 23\n".
// TODO Entries in final String should be also sorted by amount and then in alphabetical order iff needed.
// TODO Also omit any word with lengths less than 4 and frequency less than 10
//throw new UnsupportedOperationException();
Map<String, Integer> dictionary = new HashMap<>();
Charset set = Charset.forName("windows-1251");
List<String> book = readAllLines(tome12Path, set);
book.addAll(readAllLines(tome34Path, set));
String text = book.toString();
text = text.replaceAll("[^a-zA-Zа-яА-Я]", " ").toLowerCase();
Stream.of(text.split(" "))
.map(String::toString)
.filter(word -> word.length() > 3)
.forEach(word -> dictionary.put(word, dictionary.getOrDefault(word, 0) + 1));
ArrayList<Map.Entry<String, Integer>> words = new ArrayList<>(dictionary.entrySet());
words.sort(Comparator.comparing(Map.Entry::getKey));
words.sort(Map.Entry.<String, Integer>comparingByValue().reversed());
String res = "";
res = words.stream()
.filter(entry -> entry.getValue() > 9)
.map(entry -> entry.getKey() + " - " + entry.getValue())
.collect(Collectors.joining("\n"));

//throw new UnsupportedOperationException();
return res.trim();

// TODO map lowercased words to its amount in text and concatenate its entries.
// TODO Iff word "котик" occurred in text 23 times then its entry would be "котик - 23\n".
// TODO Entries in final String should be also sorted by amount and then in alphabetical order iff needed.
// TODO Also omit any word with lengths less than 4 and frequency less than 10

throw new UnsupportedOperationException();
}

}