1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class lo {
public static void main(String[] args) {
String texteFlux = readFile();
texteFlux = regexp1(texteFlux,"<Table(\\s[^<]+)*><TR(\\s[^<]+)*>(<TD(\\s[^<]+)*>[^<]*<\\\\TD>)?<TD(\\s[^<]+)*>IBM\\\\Chartered\\\\GLOBALFOUNDRIES\\\\Infineon\\\\Samsung\\\\ST <\\\\TD>.*?<\\\\Table>","");
texteFlux = regexp1(texteFlux,"<\\\\Table><Table(\\s[^<]+)*>(<[^>]*>)*?(?<!<Caption>)","");
texteFlux = regexp3(texteFlux,"(Table\\s[0-9-]+[\\.\\:\\s]+[^<]+)<\\\\P>[^<]*<Table(\\s[^<]+)*>","<\\\\P>\\n<Table><Caption><P>","<\\P><\\\\Caption>");
texteFlux = regexp3(texteFlux,"(Rule Set\\s[0-9-]+[\\:]+[^<]+)<\\\\P>[^<]*(<Figure>(.*?)<\\\\Figure>)*<Table(\\s[^<]+)*>","<\\\\P>\\n<Table><Caption><P>","<\\\\P><\\\\Caption>");
texteFlux = regexp3(texteFlux, "(?<!<Caption>)<P>(Table\\s[0-9-]+[\\.\\:\\s]+[^<]+)<\\\\P>","\\n<Caption><P>","<\\\\P><\\\\Caption>");
// writeFile(texteFlux);
}
static String readFile (){
FileReader input;
String texte = "";
System.out.println("Entrer le path de votre fichier");
Scanner sc = new Scanner(System.in);
String path = sc.nextLine();
try {
input = new FileReader(path);
BufferedReader br = new BufferedReader(input);
String line=null;
try {
while((line=br.readLine())!=null){
texte+=line;
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return texte;
}
static String regexp1 (String input,String regexp,String replaceBy) {
String resultat = input;
String first = regexp;
Pattern regexpInput = Pattern.compile(first);
Matcher matcherInput = regexpInput.matcher(input);
Vector<String> outPutString = new Vector<String>();
while (matcherInput.find()) {
String tmpString = matcherInput.replaceAll(replaceBy);
if (!outPutString.contains(tmpString)) {
outPutString.add(tmpString);
}
resultat = tmpString;
}
return resultat;
}
static String regexp3 (String input,String regexp,String replaceBy1,String replaceBy2) {
String resultat = input;
String first = regexp;
Pattern regexpInput = Pattern.compile(first);
Matcher matcherInput = regexpInput.matcher(input);
Vector<String> outPutString = new Vector<String>();
while (matcherInput.find()) {
String g1 = matcherInput.group(1);
String tmpString = matcherInput.replaceAll(""+replaceBy1+""+g1+""+replaceBy2+"");
if (!outPutString.contains(tmpString)) {
outPutString.add(tmpString);
}
resultat = tmpString;
}
return resultat;
}
static void writeFile (String texteFlux){
FileWriter writer = null;
String texte = texteFlux;
try{
writer = new FileWriter("/home/gc98/doctest/resultat001.txt", true);
writer.write(texte,0,texte.length());
}catch(IOException ex){
ex.printStackTrace();
}finally{
if(writer != null){
try {
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
} |
Partager