Skip to content

Commit 32f8bc3

Browse files
git add --all
1 parent 76e4fc1 commit 32f8bc3

File tree

10 files changed

+195307
-311
lines changed

10 files changed

+195307
-311
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/nx/peter/java/util/Dictionary.java renamed to src/main/java/nx/peter/java/dictionary/Dictionary.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
package nx.peter.java.util;
1+
package nx.peter.java.dictionary;
22

3+
import nx.peter.java.util.FileManager;
4+
import nx.peter.java.util.Random;
5+
import nx.peter.java.util.Util;
36
import nx.peter.java.util.data.*;
47

58
import java.util.ArrayList;
@@ -73,14 +76,14 @@ protected void format() {
7376
}
7477

7578
private Word.PartOfSpeech getPartOfSpeech(char letter) {
76-
return switch (letter) {
77-
case 'n' -> Word.PartOfSpeech.Noun;
78-
case 'v' -> Word.PartOfSpeech.Verb;
79-
case 'j' -> Word.PartOfSpeech.Adjective;
80-
case 'a' -> Word.PartOfSpeech.Adverb;
81-
case 'p' -> Word.PartOfSpeech.Pronoun;
82-
default -> Word.PartOfSpeech.Unknown;
83-
};
79+
switch (letter) {
80+
case 'n': return Word.PartOfSpeech.Noun;
81+
case 'v': return Word.PartOfSpeech.Verb;
82+
case 'j': return Word.PartOfSpeech.Adjective;
83+
case 'a': return Word.PartOfSpeech.Adverb;
84+
case 'p': return Word.PartOfSpeech.Pronoun;
85+
default: return Word.PartOfSpeech.Unknown;
86+
}
8487
}
8588

8689
protected void set(List<WordMeaning> dictionary) {
@@ -104,17 +107,18 @@ protected void setFilePath(Type type) {
104107
}
105108

106109
protected String getFilePath() {
107-
return switch (type) {
108-
case Adjective -> ROOT_PATH + RAW_ADJECTIVE;
109-
case Adverb -> ROOT_PATH + RAW_ADVERB;
110-
case Bank -> ROOT_PATH + RAW_BANK;
111-
case Dictionary -> ROOT_PATH + RAW_DICTIONARY;
112-
case Name -> ROOT_PATH + RAW_NAME;
113-
case Noun -> ROOT_PATH + RAW_NOUN;
114-
case Verb -> ROOT_PATH + RAW_VERB;
115-
case Word -> ROOT_PATH + RAW_WORD;
116-
case Country -> ROOT_PATH + RAW_COUNTRY;
117-
};
110+
switch (type) {
111+
case Adjective: return ROOT_PATH + RAW_ADJECTIVE;
112+
case Adverb: return ROOT_PATH + RAW_ADVERB;
113+
case Bank: return ROOT_PATH + RAW_BANK;
114+
case Dictionary: return ROOT_PATH + RAW_DICTIONARY;
115+
case Name: return ROOT_PATH + RAW_NAME;
116+
case Noun: return ROOT_PATH + RAW_NOUN;
117+
case Verb: return ROOT_PATH + RAW_VERB;
118+
case Word: return ROOT_PATH + RAW_WORD;
119+
case Country: return ROOT_PATH + RAW_COUNTRY;
120+
default: return "";
121+
}
118122
}
119123

120124

src/main/java/nx/peter/java/util/WordDictionary.java renamed to src/main/java/nx/peter/java/dictionary/WordDictionary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package nx.peter.java.util;
1+
package nx.peter.java.dictionary;
22

33
public class WordDictionary extends Dictionary.Builder {
44
public WordDictionary() {
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package nx.peter.java.util;
2+
3+
import nx.peter.java.util.data.*;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class LoremIpsumDictionary {
9+
protected List<Paragraph> paragraphs;
10+
protected String lorem;
11+
12+
public LoremIpsumDictionary() {
13+
initParagraphs();
14+
}
15+
16+
private void initParagraphs() {
17+
paragraphs = new ArrayList<>();
18+
List<String> lines = FileManager.readLines(File.FILES_FOLDER + "lorem_texts.txt");
19+
for (int line = 0; line < lines.size()/2; line += 2)
20+
paragraphs.add(new Paragraph(lines.get(line)));
21+
lorem = Util.toString(lines);
22+
}
23+
24+
public Paragraph getParagraph(int paragraph) {
25+
return paragraph > 0 && paragraph <= getParagraphCount() ? paragraphs.get(paragraph - 1) : new Paragraph();
26+
}
27+
28+
public Paragraph.Paragraphs getParagraphs() {
29+
return new Paragraph.Paragraphs(paragraphs);
30+
}
31+
32+
public Paragraph.Paragraphs getParagraphs(int start, int end) {
33+
Util.MinMax<Integer> m = new Util.MinMax<>(start, end);
34+
List<Paragraph> paragraphs = new ArrayList<>();
35+
if (m.min() > 0 && m.isUnequal() && m.max() <= getParagraphCount())
36+
for (int i = m.min(); i <= m.max(); i++)
37+
paragraphs.add(getParagraph(i));
38+
return new Paragraph.Paragraphs(paragraphs);
39+
}
40+
41+
public int getParagraphCount() {
42+
return paragraphs.size();
43+
}
44+
45+
46+
public Paragraph.Sentences getSentences() {
47+
return getParagraphs().getSentences();
48+
}
49+
50+
public Paragraph.Sentences getSentences(int start, int end) {
51+
Util.MinMax<Integer> m = new Util.MinMax<>(start, end);
52+
List<Sentence> sentences = new ArrayList<>();
53+
if (m.min() > 0 && m.isUnequal() && m.max() <= getSentenceCount())
54+
for (int i = m.min(); i <= m.max(); i++)
55+
sentences.add(getSentence(i));
56+
return new Paragraph.Sentences(sentences);
57+
}
58+
59+
public int getSentenceCount() {
60+
return getSentences().size();
61+
}
62+
63+
public Sentence getSentence(int sentence) {
64+
return sentence > 0 && sentence < getSentenceCount() ? (Sentence) getSentences().get(sentence - 1) : new Sentence();
65+
}
66+
67+
68+
public Paragraph.Words getWords() {
69+
List<Word> words = new ArrayList<>();
70+
for (Paragraph p : paragraphs)
71+
words.addAll(p.getWords().toList());
72+
return new Paragraph.Words(words, getTexts());
73+
}
74+
75+
public Paragraph.Words getWords(int start, int end) {
76+
Util.MinMax<Integer> m = new Util.MinMax<>(start, end);
77+
List<Word> words = new ArrayList<>();
78+
if (m.min() > 0 && m.isUnequal() && m.max() <= getSentenceCount())
79+
for (int i = m.min(); i <= m.max(); i++)
80+
words.add(getWord(i));
81+
return new Letters.Words(words, getTexts());
82+
}
83+
84+
public int getWordCount() {
85+
return getWords().size();
86+
}
87+
88+
public Word getWord(int position) {
89+
return getWords().get(position);
90+
}
91+
92+
93+
public Texts getTexts() {
94+
return new Texts(lorem);
95+
}
96+
97+
public boolean contains(IData data) {
98+
return contains(data != null ? data.get() : null);
99+
}
100+
101+
public boolean contains(CharSequence data) {
102+
if (data != null)
103+
for (Paragraph p : paragraphs)
104+
if (p.contains(data))
105+
return true;
106+
return false;
107+
}
108+
109+
@Override
110+
public String toString() {
111+
return getParagraphs().toString();
112+
}
113+
}

src/main/java/nx/peter/java/util/Statistics.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,45 +587,45 @@ public ITable(Statistics statistics) {
587587
// Update table
588588
for (int column = 1; column <= headings.length; column++) {
589589
switch (column) {
590-
case 1 -> {
590+
case 1: {
591591
List<Integer> numbers = new ArrayList<>();
592592
for (int i = 1; i <= statistics.getOrderedDataSize(); i++)
593593
numbers.add(i);
594594
serialNumber = new ISerialNumber(headings[column - 1], numbers).setTable(this);
595595
}
596-
case 2 -> {
596+
case 2: {
597597
List<Number> data = new ArrayList<>();
598598
for (int i = 1; i <= statistics.getOrderedDataSize(); i++)
599599
data.add(statistics.getOrderedData().get(i));
600600
columns.add(new IColumn(column, headings[column - 1], data).setTable(this));
601601
}
602-
case 3 -> {
602+
case 3: {
603603
List<Number> frequency = new ArrayList<>();
604604
for (int i = 1; i <= statistics.getOrderedDataSize(); i++)
605605
frequency.add(statistics.getRawData().getDataCount().getCount(statistics.getOrderedData().get(i)));
606606
columns.add(new IColumn(column, headings[2], frequency).setTable(this));
607607
}
608-
case 4 -> {
608+
case 4: {
609609
List<Number> fX = new ArrayList<>();
610610
for (int i = 1; i <= statistics.getOrderedDataSize(); i++) {
611611
Number val = statistics.getOrderedData().get(i);
612612
fX.add(Util.product(val, statistics.getRawData().getDataCount().getCount(val)));
613613
}
614614
columns.add(new IColumn(column, headings[column - 1], fX).setTable(this));
615615
}
616-
case 5 -> {
616+
case 5: {
617617
List<Number> mean = new ArrayList<>();
618618
for (int i = 1; i <= statistics.getOrderedDataSize(); i++)
619619
mean.add(statistics.getMean());
620620
columns.add(new IColumn(column, headings[column - 1], mean).setTable(this));
621621
}
622-
case 6 -> {
622+
case 6: {
623623
List<Number> fXMean = new ArrayList<>();
624624
for (int i = 1; i <= statistics.getOrderedDataSize(); i++)
625625
fXMean.add(Util.toNDecimalPlace(Util.diff(statistics.getOrderedData().get(i), statistics.getMean()).doubleValue(), 2));
626626
columns.add(new IColumn(2, headings[1], fXMean).setTable(this));
627627
}
628-
case 7 -> {
628+
case 7: {
629629
List<Number> fXMeanSquare = new ArrayList<>();
630630
for (int i = 1; i <= statistics.getOrderedDataSize(); i++)
631631
fXMeanSquare.add(Util.toNDecimalPlace(Util.pow(Util.diff(statistics.getOrderedData().get(i), statistics.getMean()), 2), 2));

0 commit comments

Comments
 (0)