Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The objective of this assignment is to get you familiar with regular expression,

ID: 3746291 • Letter: T

Question

The objective of this assignment is to get you familiar with regular expression, word tokenization and sentence segmentation. Given a text document, your goal is to segment the document into separate sentences using Java. An example input/output pair is provided below.

Input:

It also means that we've got to make sure that young people like yourself are able to afford a college education. Earlier, Governor Romney talked about—he wants to make Pell grants and other education accessible for young people. Well, the truth of the matter is, is that that's exactly what we've done. We've expanded Pell grants for millions of people, including millions of young women all across the country. We did it by taking $60 billion that was going to banks and lenders as middlemen for the student loan program, and we said, let's just cut out the middleman. Let's give the money directly to students. And as a consequence, we've seen millions of young people be able to afford college, and that's going to make sure that young women are going to be able to compete in that marketplace.

Output:

1. It also means that we've got to make sure that young people like yourself are able to afford a college education.

2. Earlier, Gov. Romney talked about—he wants to make Pell grants and other education accessible for young people.

3. Well, the truth of the matter is, is that that's exactly what we've done.

4. We've expanded Pell grants for millions of people, including millions of young women all across the country.

5. We did it by taking $60.3 billion that was going to banks and lenders as middlemen for the student loan program, and we said, let's just cut out the middleman.

6. Let's give the money directly to students.

7. And as a consequence, we've seen millions of young people be able to afford college, and that's going to make sure that young women are going to be able to compete in that marketplace.

-------

Your program should process the input.txt file and generate an output.txt file. Each line of the output file should start with the sentence number followed by the sentence as shown in the above example.

Explanation / Answer


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class LineSegment {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader reader = new BufferedReader( new FileReader( "D:\inputFile.txt") );
File file = new File("D:\outputFile.txt");
FileWriter fr = new FileWriter(file, true);
while (reader.ready()) { //While there are content left to read
String line = reader.readLine(); //Read the next line from the file
String[] tokens = line.split( "\." ); //splitting based on (.)
int i=1;
for (String token : tokens){
String l=i+"."+token.trim()+"."; //forming a line
fr.write(l);
fr.write(" ");// to move to next line in output file
i++;
}
}
fr.close();
reader.close();
}
}

//Please enter Input and output file path. In my case i created files in my D drive

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote