Hello! Please tell me the solution to my problem. I try to make it so that from the text that is read from the file, I get the number of sentences. It works in my code. But! I do not understand how to expand the program to take into account that the dot does not always indicate the end of a sentence. The point can also be used as abbreviations, such as acting (acting).
package ir_ub2; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.nio.file.ReadOnlyFileSystemException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TextCounts { public static void main(String[] args) throws IOException { // datei lesen FileReader fileName = new FileReader("C:\\Users\\Olga\\Desktop\\ub_2\\inputDE.txt"); // wrap a BufferedReader around FileReader BufferedReader reader = new BufferedReader(fileName); int sentenceCount = 0; String line; String terminalSymbol = ".?!"; while ((line = reader.readLine()) != null) { // Continue reading until end of file is reached for (int i = 0; i < line.length(); i++) { if (terminalSymbol.indexOf(line.charAt(i)) != -1) { // If the delimiters string contains the character sentenceCount++; } } } reader.close(); System.out.println("The number of sentences is " + sentenceCount); } }
ув. Иванов
ув. Иванов
from theконец предложения. Начало следующего
конец предложения. Начало следующего
. Only if you enter a list of all possible abbreviations. - andy.37.!?
, and one of these characters, followed by one or more space characters, followed by a capital letter or number. There will be a problem with the initials, well, you can try something like a small letter before the full stop. With the implementation, sorry, I will not help, because I repeat - I do not know Java. A regular pearl style will look something like this:[^AZ][.!?]\s+[AZ]
- andy.37