作用:使用自动机识别论文中的错误的大小写以及空格问题
原理:
代码:
ximport java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
/**
*
*
*
* @Description : 使用自动机 检查论文的格式,包括(首字母大小写、逗号和句号与空格)
* @Project :
* @Program Name : CheckPaperBlank.java
* @Author : 常晓松
* @Creation Date : 2022年11月19日下午8:31:27
* @version : v1.00
*/
public class CheckPaperBlank {
public static void main(String[] args) throws FileNotFoundException {
String fileName = "C:\\Users\\chang\\Desktop\\123.txt";
try (Scanner sc = new Scanner(new FileReader(fileName))) {
while (sc.hasNextLine()) { //按行读取字符串
String line = sc.nextLine();
checkOneSentence(line);
}
}
}
private static void checkOneSentence(String sentence) {
for (int i = 0; i < sentence.length()-2; i++) {
char charCheck1=sentence.toCharArray()[i];
char charCheck2=sentence.toCharArray()[i+1];
char charCheck3=sentence.toCharArray()[i+2];
boolean correct= checkOneChar(charCheck1,charCheck2,charCheck3);
if (!correct) {
System.out.print(charCheck1+""+charCheck2+""+charCheck3);
System.out.println("----->"+sentence);
}
}
}
private static boolean checkOneChar(char charCheck1,char charCheck2,char charCheck3) {
if (charCheck1=='.') {
if (charCheck2==' ') {
if (charCheck3 >= 65 && charCheck3 <= 90) {
return true;
}
return false;
}
return false;
}
if (charCheck1==',') {
if (charCheck2==' ') {
if (charCheck3 >= 97 && charCheck3 <= 122) {
return true;
}
return false;
}
return false;
}
return true;
}
}