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

in java language In this project you need to develop an application that will ch

ID: 3776768 • Letter: I

Question

in java language

In this project you need to develop an application that will check the similarity between a document (Pattern) and other documents. Your input will be a set of text files, at least 4 files, and a potentially plagiarized document. Your output must be the similarity percentage between the pattern and each text file (individually) and between the overall percentage between the pattern and all text files. Use the string matching algorithm with finite state machine to implement your detector. Your application should at least contain these functionalities: Load the pattern file (you may tokenize the file by sentence or by line). Build the state machine for each pattern. a. Show the built table (Transfer Function). Load the text files. Check similarity between the pattern and each individual text file. Show a percentage for each text file Check the overall similarity. (The percentage = sum of all similarities/number of text files).

Explanation / Answer

// header file
import java.io.*;


public class SimilarityCheck {
public static void main(String args[])
   {       
int percentageSimilarity = 0;
BufferedReader bf = new BufferedReader(new FileReader("test.txt"));
   // sum of all similarities
int linecount = 0;
String lineinFile;
   Pattern p = Pattern.compile("\bthe\b", Pattern.CASE_INSENSITIVE);
   // Number of matches
   int mached = 0;
   while ( lineinFile = bf.readLine()) != null) {
   linecount++;

    Matcher m = p.matcher(line);

  
   while (m.find()) {
   matched++;
   }
   }

bf.close();
   percentageSimilarity = matched / linecount ;
   System.out.println("Percentage Similarity in file is " + percentageSimilarity );
}
}