oop-labs-collection/labs/5/Main.java

115 lines
3.7 KiB
Java
Raw Normal View History

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/>.
*/
import lab5lib.Fetcher;
2023-06-10 15:50:10 +03:00
/**
* Main class of this application that defines the overall flow
* of the work
*
* @since 0.2
* @author Dymik739
*/
public class Main {
2023-06-10 15:50:10 +03:00
/**
* Main method to rule them all.
*
* @since 0.2
* @param args String[] of CLI arguments
*/
public static void main(String[] args) {
2023-06-10 15:50:10 +03:00
boolean demoContent; // defines if the demo string is used
String inputString; // contains initial string
Text text; // contains the Text object used for processing later
String result; // contains responce string
demoContent = parseArgs(args);
2023-06-10 15:50:10 +03:00
inputString = getInput(demoContent);
System.out.println("Processing string: " + inputString);
2023-06-10 15:50:10 +03:00
text = new Text(inputString);
text.cleanFirstSentence();
2023-06-10 15:50:10 +03:00
System.out.println("Cleared text: " + text.toString());
result = text.getSentenceByIndex(0).getUniqueWord();
2023-06-10 15:50:10 +03:00
System.out.println(result);
}
/**
* Method used to get input string. Automatically determines
* the source based on downstream state and demoContent variable.
*
* @since 0.2
* @param demoContent forces method to return premade string.
* @return String containing server responce or the premade string
* (in case if requested or the fetching fails)
*/
private static String getInput(boolean demoContent) {
if (demoContent) {
return "Testing, text to make up words. Testing, text without " +
2023-06-10 15:50:10 +03:00
"specific, up words? Therefore, we don't care about " +
"arteriscs and other useless symbols, as the only reason" +
2023-06-10 15:50:10 +03:00
"to use it is when the code runs horrible. But this time" +
"we sure do care about question and exclamation marks!";
} else {
return receiveText();
}
}
2023-06-10 15:50:10 +03:00
/**
* Method to parse CLI arguments.
*
* @since 0.2
* @param args CLI arguments to process
* @return boolean indicating if the demo content is requested
*/
private static boolean parseArgs(String[] args) {
boolean demoContent = false;
for (String arg : args) {
if ("-d".equals(arg)) {
demoContent = true;
}
}
return demoContent;
}
2023-06-10 15:50:10 +03:00
/**
* More low-level method that proxies request downstream.
*
* @since 0.2
* @return String to upstream; see getInput() method
*/
private static String receiveText() {
try {
return Fetcher.fetchTextFromPython();
} catch (Exception e) {
return "Testing, text to make up words. Testing, text without " +
"specific, up words. Therefore, we don't care about " +
"arteriscs and other useless symbols, as the only reason" +
2023-06-10 15:50:10 +03:00
"to use it is when the code runs horrible. But this time" +
"we sure do care about question and exclamation marks!";
}
}
}