2023-06-10 15:50:10 +03:00
|
|
|
/*
|
|
|
|
* %W% %E% Dymik739
|
|
|
|
* Email: dymik739@109.86.70.81
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 FIOT Dev Team
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2023-06-08 15:31:50 +03:00
|
|
|
|
2023-06-10 15:50:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class representing the text being processed.
|
|
|
|
*
|
|
|
|
* @author Dymik739
|
|
|
|
* @since 0.2
|
|
|
|
*/
|
2023-06-08 15:31:50 +03:00
|
|
|
public class Text {
|
2023-06-10 15:50:10 +03:00
|
|
|
/** contains all the Sentence objects combining into the original text */
|
2023-06-08 15:31:50 +03:00
|
|
|
private Sentence[] sentences;
|
2023-06-10 15:50:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor which allows to create sentence from a string
|
|
|
|
*
|
|
|
|
* @since 0.2
|
|
|
|
* @param input string to be parsed as sentence
|
|
|
|
*/
|
2023-06-08 15:31:50 +03:00
|
|
|
public Text(String input) {
|
2023-06-10 15:50:10 +03:00
|
|
|
String[] rawSentences = input.split("(?<=[.?!])( |$)");
|
2023-06-08 15:31:50 +03:00
|
|
|
Sentence[] newSentences = new Sentence[rawSentences.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < rawSentences.length; i++) {
|
|
|
|
newSentences[i] = new Sentence(rawSentences[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sentences = newSentences;
|
|
|
|
}
|
2023-06-10 15:50:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method that picks a sentence by it's array index
|
|
|
|
*
|
|
|
|
* @since 0.2
|
|
|
|
* @param index sentence id
|
|
|
|
* @return selected Sentence object
|
|
|
|
*/
|
|
|
|
public Sentence getSentenceByIndex(int index) {
|
|
|
|
return sentences[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method for cleaning first sentence from words that are present
|
|
|
|
* in other sentences.
|
|
|
|
*
|
|
|
|
* @since 0.2
|
|
|
|
*/
|
|
|
|
public void cleanFirstSentence() {
|
|
|
|
Word processedWord;
|
2023-06-08 15:31:50 +03:00
|
|
|
|
2023-06-10 15:50:10 +03:00
|
|
|
for (int i = 1; i < sentences.length; i++) {
|
|
|
|
for (int j = 0; j < sentences[i].getLength(); j++) {
|
|
|
|
processedWord = sentences[i].getWordByIndex(j);
|
|
|
|
|
|
|
|
while (sentences[0].index(processedWord) != -1) {
|
|
|
|
sentences[0].removeWord(processedWord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-08 15:31:50 +03:00
|
|
|
|
2023-06-10 15:50:10 +03:00
|
|
|
/**
|
|
|
|
* Method used to get a proper String representation of the text.
|
|
|
|
*
|
|
|
|
* @since 0.2
|
|
|
|
* @return String representation of the text
|
|
|
|
*/
|
|
|
|
@Override
|
2023-06-08 15:31:50 +03:00
|
|
|
public String toString() {
|
|
|
|
String result = "";
|
|
|
|
|
|
|
|
for (Sentence s : this.sentences) {
|
|
|
|
result += s.toString() + " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|