115 lines
3.7 KiB
Java
115 lines
3.7 KiB
Java
/*
|
|
* %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;
|
|
|
|
/**
|
|
* Main class of this application that defines the overall flow
|
|
* of the work
|
|
*
|
|
* @since 0.2
|
|
* @author Dymik739
|
|
*/
|
|
public class Main {
|
|
/**
|
|
* Main method to rule them all.
|
|
*
|
|
* @since 0.2
|
|
* @param args String[] of CLI arguments
|
|
*/
|
|
public static void main(String[] args) {
|
|
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);
|
|
inputString = getInput(demoContent);
|
|
|
|
System.out.println("Processing string: " + inputString);
|
|
|
|
text = new Text(inputString);
|
|
text.cleanFirstSentence();
|
|
|
|
System.out.println("Cleared text: " + text.toString());
|
|
result = text.getSentenceByIndex(0).getUniqueWord();
|
|
|
|
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 " +
|
|
"specific, up words? Therefore, we don't care about " +
|
|
"arteriscs and other useless symbols, as the only reason" +
|
|
"to use it is when the code runs horrible. But this time" +
|
|
"we sure do care about question and exclamation marks!";
|
|
} else {
|
|
return receiveText();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* 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" +
|
|
"to use it is when the code runs horrible. But this time" +
|
|
"we sure do care about question and exclamation marks!";
|
|
}
|
|
}
|
|
}
|