From a81f01103feb1dd52035dc0e5d846b29d60879f1 Mon Sep 17 00:00:00 2001 From: dima0808 <52035263+dima0808@users.noreply.github.com> Date: Wed, 31 May 2023 18:47:09 +0200 Subject: [PATCH] Add files via upload --- lab5/lab5.iml | 11 ++++ lab5/out/production/lab5/lab5/Letter.class | Bin 0 -> 391 bytes lab5/out/production/lab5/lab5/Main.class | Bin 0 -> 5246 bytes .../production/lab5/lab5/Punctuation.class | Bin 0 -> 406 bytes lab5/out/production/lab5/lab5/Sentence.class | Bin 0 -> 649 bytes lab5/out/production/lab5/lab5/Text.class | Bin 0 -> 630 bytes lab5/out/production/lab5/lab5/Word.class | Bin 0 -> 620 bytes lab5/src/lab5/Letter.java | 5 ++ lab5/src/lab5/Main.java | 38 +++++++++++ lab5/src/lab5/Punctuation.java | 5 ++ lab5/src/lab5/Sentence.java | 62 ++++++++++++++++++ lab5/src/lab5/Text.java | 21 ++++++ lab5/src/lab5/Word.java | 28 ++++++++ 13 files changed, 170 insertions(+) create mode 100644 lab5/lab5.iml create mode 100644 lab5/out/production/lab5/lab5/Letter.class create mode 100644 lab5/out/production/lab5/lab5/Main.class create mode 100644 lab5/out/production/lab5/lab5/Punctuation.class create mode 100644 lab5/out/production/lab5/lab5/Sentence.class create mode 100644 lab5/out/production/lab5/lab5/Text.class create mode 100644 lab5/out/production/lab5/lab5/Word.class create mode 100644 lab5/src/lab5/Letter.java create mode 100644 lab5/src/lab5/Main.java create mode 100644 lab5/src/lab5/Punctuation.java create mode 100644 lab5/src/lab5/Sentence.java create mode 100644 lab5/src/lab5/Text.java create mode 100644 lab5/src/lab5/Word.java diff --git a/lab5/lab5.iml b/lab5/lab5.iml new file mode 100644 index 0000000..9465dd8 --- /dev/null +++ b/lab5/lab5.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/lab5/out/production/lab5/lab5/Letter.class b/lab5/out/production/lab5/lab5/Letter.class new file mode 100644 index 0000000000000000000000000000000000000000..7fe3e5adfefd9bebd644d95e7cb01ab2c9787322 GIT binary patch literal 391 zcmYk2yH3ME5Jm6!5hu3uAV4T+D3cVpqTrEwt-GXEJ!LO~Ve}7sDd?|t6}M>4K)8Fq-Ib|cWi`obpFgiB#~J4{xS7y$LPiE- z8$;R=)rz{VyUS0=^7I4FThlY99l@mKU(`GDOsHmUHx4kR;=P8-6>*58jv3GkYxeRT Y&MN~0HLlkr{RZQ=4IM^s+;q+U0CM6x_W%F@ literal 0 HcmV?d00001 diff --git a/lab5/out/production/lab5/lab5/Main.class b/lab5/out/production/lab5/lab5/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..b80468ff8fde9b4fca8ea274fc2868a8ffa86c0b GIT binary patch literal 5246 zcmaJ_d3+pY8Ga_&&1^Q46Sif6+M!J$cK{*6h8EJ$+CY-FY?_$1iqqXmGVNq$nIp7d zQM8H&-d9@{v7%K#uo<5nQ zPS(hH1eg-9+SDn-({$CfP1DF2o}V==byD*k!&S$$jA0rsS2`iKIhyY3mZwe{s+~3L zHZ|wyomwE#xdeKlul8Qsz7 z_JUc{XVeUeQM>e1H3;Hl>Aq`cHB)yx)a||zpjvuH)m=|DnNHvBh$D_F8H$2x)JUi_ zwLMpM4rqoYA)aw`1~R1YXT4T8^)D7N%`8~s-Oc@hv=HbPICTo@(IBCA%&@XMEQ3Le z*iP1!u&Sv@v^hlbJ;UtmH(al~66YczV}*j1IIn~)=>smyN|M+%dUV+szR0S7d zjf8W8h)c~$kaNPg$pj^q%gL~e#)4{KtjBS*10v2i)}lOyOC*%-X5O38BBND78`?`_ z4w5S&>gGsc370HqW!KVb2*geWm*O%B5n?cH=Qb@9WDKulLU+5ZqGVSp=)$WcR2%L# z-y$P4&#+%Ew4E}prmI2Gi=>6&ZUxt1J=;1np*cPDI?~kF+#APLxK_-7>%>NH^Kcb5 zqF2WC3N~T0gqk413nigjS~hz|Uc-UW-Mmwn*`lBiH%O@R>|S9=q*g#T?;>hH_XFSh zb&u?i<3?O7V{3ubf{JkrV!LqYCYER^B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WIc8q@?`|1o!QwF2BFk%EK-G)PX_)KZ(DHAo cU&ayjT!1R!cf|Y){>rB~SAWAl@Gm6)527|=82|tP literal 0 HcmV?d00001 diff --git a/lab5/out/production/lab5/lab5/Punctuation.class b/lab5/out/production/lab5/lab5/Punctuation.class new file mode 100644 index 0000000000000000000000000000000000000000..aac5b332eaacecd442a0954871c0999a0e6d9e53 GIT binary patch literal 406 zcmZ8dyH3ME5S;TPPK-%RfKbp-CN6MA#iOy5Dgq>s`?ImaMaGtlov)%n0wGcG0elo< z&US&&NxM6{b8|cQ{qy++;1WkJ444iq4>kq@{zh(Pn9E`v-XxnWtpx@bs!;WnfH_~p zBMdQe;Ck4BM|v)kv+%Yl(z=ngDhmO7EAu835Rrg2j}|dgR6ejXS*aqsZl02?x|d1L z&U96#GLL1YH13;L{ivSx?7#N8z;K<_ai`C1_=0;^HdUG}m6r4WEOM%i;DqZMG%6Um zFe`(#ja|ku(UMrt-QWWvIDUuo+Hxk0W0;Km8f}@!Cz^F^>|sj8d#x(XVjl;+X2>i! bvx7G{FDwjbxk20XS{bh+^fCg6Eo=4*)V4x| literal 0 HcmV?d00001 diff --git a/lab5/out/production/lab5/lab5/Sentence.class b/lab5/out/production/lab5/lab5/Sentence.class new file mode 100644 index 0000000000000000000000000000000000000000..d168417b9ed6b9619a1a7c6a8751e81158d45861 GIT binary patch literal 649 zcmZuu%TB^T6g^W4rR6CoJ{K;G0w#9l3S?t+)#w64+_rUsLrO7aYT{pMqA_vd2l!FO z+lNFdX*ze#opaB*bLZ>(;}gIc_6#VXF#R?$>Rr(n{U5#R$GPe{Xp3!{=>mI*Bdm)s=8m(1|ARQGteFhqYS_vCX ztP`TTRDFZ?kxP=PF8o@w+r(DtW)g}x`R*&UXWA&SQ6WxNVuM5^pBf}hZ`1is%-;P0 Dh0BLe literal 0 HcmV?d00001 diff --git a/lab5/out/production/lab5/lab5/Text.class b/lab5/out/production/lab5/lab5/Text.class new file mode 100644 index 0000000000000000000000000000000000000000..12270048e818f7ed70f74de1c6163209f5da210e GIT binary patch literal 630 zcmZWmOHaZ;7@UPdZFvfc&x1w}fQdbM0=bxYYV-ghUJGt;Ni7D7(SN0h#>9g^z#nCt zZHtMJru)67Gt+Ose?GqeoMYcc3TYEY9vNf>%46@*b9^rtIoE@+9EJkfwhC0(5lGh? zeG6-_OxStkkQcCgZ*b=Hr6^(9cN(HAf-CbuLgxhjxX^ZS9E_Pl}5PQ{%JJ-_cwm9CSf5#A}f$;I^A zCW&kRkBMvb$Z9}vxxcbKoN(pcwNWCVE(SbS_$Sk+=Qs@Pz~ z?-KS+=2|806#w*U%(k$ds5z`OCewU_`NAX>31y>ZArgp5GKoNJdWZAf2)*|U5(7m*ACp-#J=>V{zwTFdU7UJUm)9R z4^6DVG+>obL`lF5T<^rbo`+)rBk+~-!v#s4m?cs&upPNjT>=MkGILcF`T~2Y>z)&{ zIPrM5PjsV|f^^$Mf!x`A%<-xtXZ}TW=lS84>jmu8o%zTOhHfZzy=>;xt)!P?Lar^6 zxcL|Pc>jYwOe>~MX#>{8SBXm!*IVthNr8iZ%`^{L2J1L4N3SrRS!J=xv%(1S&&%E(y9FFHJNQ-bE#&t(wKbb1;!JTOe|E0o8?#_A;~WV64P6}-;U8c--1Sa(EtDd literal 0 HcmV?d00001 diff --git a/lab5/src/lab5/Letter.java b/lab5/src/lab5/Letter.java new file mode 100644 index 0000000..cb78fdc --- /dev/null +++ b/lab5/src/lab5/Letter.java @@ -0,0 +1,5 @@ +package lab5; + +public record Letter(char value) { + +} diff --git a/lab5/src/lab5/Main.java b/lab5/src/lab5/Main.java new file mode 100644 index 0000000..10ffc25 --- /dev/null +++ b/lab5/src/lab5/Main.java @@ -0,0 +1,38 @@ +package lab5; + +import java.util.*; + +public class Main { + + public static void main(String[] args) { + String inputText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tempor dictum velit, vitae sollicitudin mauris facilisis et. Praesent mi odio, pretium eget sem ac, ultricies eleifend elit. Maecenas vulputate efficitur risus, a ornare lorem sollicitudin vitae. Pellentesque rhoncus posuere risus eu placerat. Maecenas luctus felis ac interdum sodales. Quisque nec est lectus."; + + // Створений Text об'єкт + Text text = new Text(inputText); + + // Пошук у першому реченні слів, яких немає в наступних реченнях + List result = findUniqueWords(text); + System.out.println("Unique words in the first sentence: " + result); + } + + public static List findUniqueWords(Text text) { + if (text.getSentences().isEmpty()) { + throw new IllegalArgumentException("Text must contain at least one sentence."); + } + + Sentence firstSentence = text.getSentences().get(0); + List wordsInFirstSentence = firstSentence.getStringWords(); + + Set uniqueWords = new HashSet<>(wordsInFirstSentence); + + for (int i = 1; i < text.getSentences().size(); i++) { + Sentence sentence = text.getSentences().get(i); + List wordsInCurrentSentence = sentence.getStringWords(); + + wordsInCurrentSentence.forEach(uniqueWords::remove); + } + + return new ArrayList<>(uniqueWords); + } + +} diff --git a/lab5/src/lab5/Punctuation.java b/lab5/src/lab5/Punctuation.java new file mode 100644 index 0000000..037612a --- /dev/null +++ b/lab5/src/lab5/Punctuation.java @@ -0,0 +1,5 @@ +package lab5; + +public record Punctuation(char value) { + +} diff --git a/lab5/src/lab5/Sentence.java b/lab5/src/lab5/Sentence.java new file mode 100644 index 0000000..b1638e4 --- /dev/null +++ b/lab5/src/lab5/Sentence.java @@ -0,0 +1,62 @@ +package lab5; + +import java.util.ArrayList; +import java.util.List; + +public class Sentence { + private final List wordsAndPunctuations; + + public Sentence(String stringSentence) { + List wordsAndPunctuations = new ArrayList<>(); + StringBuilder word = new StringBuilder(); + + for (int i = 0; i < stringSentence.length(); i++) { + char ch = stringSentence.charAt(i); + + if (Character.isLetterOrDigit(ch)) { + word.append(ch); + } else if (Character.isWhitespace(ch)) { + if (word.length() > 0) { + wordsAndPunctuations.add(new Word(word.toString())); + word.setLength(0); + } + } else if (String.valueOf(ch).matches(".*\\p{Punct}.*")) { + if (word.length() > 0) { + wordsAndPunctuations.add(new Word(word.toString())); + word.setLength(0); + } + wordsAndPunctuations.add(new Punctuation(ch)); + } + } + + if (word.length() > 0) { + wordsAndPunctuations.add(new Word(word.toString())); + } + + this.wordsAndPunctuations = wordsAndPunctuations; + } + + public List getWordsAndPunctuations() { + return wordsAndPunctuations; + } + + + public List extractWords() { + List words = new ArrayList<>(); + for (Object element : getWordsAndPunctuations()) { + if (element instanceof Word) { + words.add((Word) element); + } + } + return words; + } + + public List getStringWords() { + List wordStrings = new ArrayList<>(); + for (Word word : extractWords()) { + wordStrings.add(word.getStringWord()); + } + return wordStrings; + } + +} diff --git a/lab5/src/lab5/Text.java b/lab5/src/lab5/Text.java new file mode 100644 index 0000000..f765e7c --- /dev/null +++ b/lab5/src/lab5/Text.java @@ -0,0 +1,21 @@ +package lab5; + +import java.util.ArrayList; +import java.util.List; + +public class Text { + private final List sentences; + + public Text(String stringText) { + this.sentences = new ArrayList<>(); + String[] splitText = stringText.split("(?<=[!.?])\\s*"); + for (String sentence : splitText) { + getSentences().add(new Sentence(sentence)); + } + } + + public List getSentences() { + return sentences; + } + +} diff --git a/lab5/src/lab5/Word.java b/lab5/src/lab5/Word.java new file mode 100644 index 0000000..7f3638e --- /dev/null +++ b/lab5/src/lab5/Word.java @@ -0,0 +1,28 @@ +package lab5; + +import java.util.ArrayList; +import java.util.List; + +public class Word { + private final String stringWord; + private final List letters; + + public Word(String stringWord) { + List letters = new ArrayList<>(); + char[] chars = stringWord.toCharArray(); + for (char c : chars) { + letters.add(new Letter(c)); + } + this.letters = letters; + this.stringWord = stringWord; + } + + public List getLetters() { + return letters; + } + + public String getStringWord() { + return stringWord; + } + +}