-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessQuery.flex
More file actions
executable file
·100 lines (71 loc) · 2.12 KB
/
ProcessQuery.flex
File metadata and controls
executable file
·100 lines (71 loc) · 2.12 KB
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
import java.util.*;
import java.io.*;
import java.sql.Timestamp;
class ProcessQuery{
public static PrintWriter writer = null;
public static int count =0;
public static void main(String[] args) throws IOException{
//int count = 0;
if(args.length != 1){
System.out.println("Please enter two arguments \"Input directory name\" and \"Output directory name\" ");
System.exit(-1);
}
File outputFolder = new File("processed_query");
if(!outputFolder.exists()){
if(outputFolder.mkdir()){System.out.println("Output directory is created.");}
else{System.out.println("Failed to create Output directory. ");}
}
File inputFolder = new File(args[0]);
File[] fileNames = inputFolder.listFiles();
//Arrays.sort(fileNames);
for(File file: fileNames){
if(file.isFile()){
File outputFile = null;
try(BufferedReader br = new BufferedReader(new FileReader(file))){
MyLexer yy = new MyLexer(br);
try{
outputFile = new File("processed_query" +File.separator + file.getName());
count++;
writer = new PrintWriter(outputFile);
while (yy.yylex() !=null){
}
}
catch(IOException e){
System.out.println("Cannot create output file "+file.getName()+".txt");
}catch(Exception e){
/*System.out.println("don't know what happend with file: " + file.getName() );
e.printStackTrace();
System.out.println();*/
}
finally {
if(writer != null){
writer.flush();
writer.close();
}
}
}
}
}
}
public static void downcase(String str){
writer.println(str.toLowerCase());
}
}
%%
LETTER=[A-Za-z]
DIGIT=[0-9]+(-[0-9]+)*|[0-9]+(,[0-9]+)*|[0-9]+"."[0-9]+
EMAIL=[a-zA-Z_][A-Za-z0-9_]*"@"[a-zA-Z]+"."[a-zA-Z]+
URL=http[s]?:\/\/www.[a-zA-Z0-9_\.\/~!@#$%^&*]*
WHITESPACE = [\t\n|\r]
%class MyLexer
%type String
%eofval{
return null;
%eofval}
%%
\<[^\>]*\> {}
{URL} {ProcessQuery.downcase(new String(yytext()));}
{EMAIL} {ProcessQuery.downcase(new String(yytext()));}
[a-zA-Z_][a-zA-Z0-9_]* {ProcessQuery.downcase(new String(yytext()));}
{WHITESPACE} {}
. {}