Browse Source

Update to index

ailton 8 years ago
parent
commit
9325f0ca31

+ 0 - 16
src/graph/extractor/ExtractorGraph.java

@@ -60,19 +60,3 @@ public class ExtractorGraph {
60 60
 	}
61 61
 
62 62
 }
63
-//File file = new File("/home/ailton/Monografia/file.txt");
64
-//try{
65
-//
66
-//	
67
-//FileWriter fw = new FileWriter(file);
68
-//for( DOProcess process : this.allProcess )
69
-//{
70
-//	fw.write(process.toString());
71
-//}
72
-//}catch
73
-//(Exception e)
74
-//{
75
-//	e.printStackTrace();
76
-//}
77
-
78
-//

+ 19 - 22
src/graph/extractor/graph/builder/BuilderFactory.java

@@ -1,12 +1,17 @@
1 1
 package graph.extractor.graph.builder;
2 2
 
3 3
 import java.io.File;
4
+import java.io.IOException;
4 5
 import java.nio.file.Files;
5 6
 import java.util.ArrayList;
6 7
 import java.util.List;
7 8
 import java.util.Random;
8 9
 
9
-import entity.DOProcess;
10
+import org.apache.lucene.index.IndexWriter;
11
+
12
+import dao.connection.LuceneConnector;
13
+import dao.entity.DOProcess;
14
+import dao.lucene.tables.DAOJudge;
10 15
 import graph.input.file.InputFactory;
11 16
 import graph.output.OutPutFactory;
12 17
 
@@ -52,10 +57,12 @@ public abstract class BuilderFactory {
52 57
 						process.setProcessDate(oneDayOfDO.getName());
53 58
 						this.processes.add(process);
54 59
 					}
60
+					
61
+					
55 62
 				}
56 63
 				output.buildOutput(this.processes);
57 64
 				
58
-				this.moveDoneFiles(oneDayOfDO);
65
+				//this.moveDoneFiles(oneDayOfDO);
59 66
 				this.processes.clear();
60 67
 				allProcess.clear();
61 68
 				allDateFiles.remove(oneDayOfDO);
@@ -70,26 +77,16 @@ public abstract class BuilderFactory {
70 77
 			
71 78
 
72 79
 		}
73
-
74
-	/*	for(File oneDayOfDO : allDateFiles )
75
-		{
76
-			List<String> allProcess  = input.getAllProcess(oneDayOfDO);
77
-
78
-			for(String oneProcess: allProcess)
79
-			{
80
-				DOProcess process = this.extractProcess(oneProcess);
81
-				if(process != null)
82
-				{
83
-					process.setProcessDate(oneDayOfDO.getName());
84
-					this.processes.add(process);	
85
-				}
86
-			}
87
-
88
-			output.buildOutput(this.processes);
89
-			this.processes.clear();
90
-			allProcess.clear();
91
-		}*/
92
-
80
+		DAOJudge daoJudge = DAOJudge.getInstance();
81
+		daoJudge.store();
82
+		try {
83
+			LuceneConnector.getIndexDisk().commit();
84
+		} catch (IOException e) {
85
+			// TODO Auto-generated catch block
86
+			e.printStackTrace();
87
+		}
88
+		
89
+		
93 90
 
94 91
 
95 92
 	}

+ 266 - 41
src/graph/extractor/graph/builder/STJBuilder.java

@@ -1,45 +1,213 @@
1 1
 package graph.extractor.graph.builder;
2 2
 
3
-import entity.DOProcess;
4
-import entity.Entity;
5
-import entity.Judge;
6
-import entity.Lawyer;
7
-import entity.ProcessTypes;
8
-import entity.TYPES;
3
+
4
+
5
+import dao.entity.DOProcess;
6
+import dao.entity.Entity;
7
+import dao.entity.Judge;
8
+import dao.entity.Lawyer;
9
+import dao.entity.ProcessTypes;
10
+import dao.entity.TYPES;
9 11
 
10 12
 public class STJBuilder extends BuilderFactory{
11 13
 
14
+	private static boolean nextLawyer =false;
15
+	
16
+	private String normalizeJudgeName(String judgeName)
17
+	{
18
+		
19
+		if(judgeName.contains("(") && !judgeName.startsWith("(") )
20
+		{
12 21
 
22
+			try{
13 23
 
14
-	private Entity getEntity(String canditate)
24
+				judgeName = judgeName.split("\\(")[0].trim();
25
+			}catch(Exception e)
26
+			{
27
+				e.printStackTrace();
28
+			}
29
+		}
30
+		if(judgeName.contains("PRESIDENTE DA"))
31
+		{
32
+			
33
+			judgeName = TYPES.NAMEDEFAULT;
34
+		}
35
+		if(judgeName.equals("PROCESSO NÃO DISTRIBUÍDO"))
36
+		{
37
+			judgeName = TYPES.NAMEDEFAULT;
38
+		}
39
+		
40
+		
41
+		return judgeName;
42
+	}
43
+	
44
+	
45
+	private String normalizeEntityName(String entityName)
15 46
 	{
16
-		Entity entity = new Entity();
47
+		String originalEntityName = entityName.trim();
48
+		
49
+		if(entityName.contains("(PRESO)"))
50
+		{
51
+			entityName = entityName.split("(PRESO)")[0].trim();
52
+		}
53
+		if(entityName.contains("E OUTRO"))
54
+		{
55
+			entityName = entityName.split("E OUTRO")[0].trim();
56
+		}
57
+		if(entityName.endsWith(" E"))
58
+		{
59
+			entityName = entityName.split(" E")[0].trim();
60
+		}
61
+		if(entityName.endsWith("\\("))
62
+		{
63
+			entityName = entityName.split("\\(")[0].trim();
64
+		}
65
+		
66
+		
67
+		if(entityName.length() > 0)
68
+			return entityName;
69
+		else
70
+			return TYPES.NAMEDEFAULT;
71
+		
72
+	}
73
+	
74
+	
75
+	private Lawyer normalizeLawyerName(Lawyer lawyer)
76
+	{
77
+		
78
+		//String originalEntityName = entityName.trim();
79
+		String nameNormalized = lawyer.getName().replaceAll("\\r|\\n", " ").trim();
80
+
17 81
 
18 82
 		try{
83
+			
84
+			
19 85
 
86
+			if(nameNormalized.contains("-"))
87
+			{
20 88
 
89
+				if(nameNormalized.charAt(nameNormalized.length()-1) != '-')
90
+				{
91
+					lawyer.setOABNumber(nameNormalized.split("-")[1].trim());
92
+				}
93
+				nameNormalized = nameNormalized.split("-")[0].trim();
94
+			}
95
+			
96
+			if(nameNormalized.contains("E OUTRO"))
97
+			{
98
+				nameNormalized = nameNormalized.split("E OUTRO")[0].trim();
99
+			}
100
+			
101
+			if(nameNormalized.contains("DEFENSORIA") ||nameNormalized.contains("PROCURADORIA"))
102
+			{
103
+				nameNormalized = TYPES.NAMEDEFAULT;
104
+			}
105
+			
106
+			
107
+		}
108
+		catch(Exception e)
109
+		{
110
+			
111
+			System.out.println("lawyer error:  " + lawyer);
112
+		}
113
+
114
+
115
+
116
+		
117
+		
118
+		
119
+		if(nameNormalized.contains("EM CAUSA")  )
120
+		{
121
+			nameNormalized = nameNormalized.split("EM CAUSA")[0].trim();
122
+			nameNormalized = nameNormalized.substring(0, nameNormalized.length() -1).trim();
123
+			
124
+		}
125
+			
126
+		if(nameNormalized.equals("E OUTRO(S)"))
127
+		{
128
+			nameNormalized = TYPES.NAMEDEFAULT;
129
+		}
130
+			
131
+		
132
+		if(nameNormalized.endsWith(" E"))
133
+		{
134
+			nameNormalized = nameNormalized.split(" E")[0].trim();
135
+		}
136
+		
137
+		if(nameNormalized.equals(""))
138
+		{
139
+			lawyer.setName(lawyer.getName());
140
+		}
141
+		else
142
+		{
143
+			lawyer.setName(nameNormalized);
144
+		}
145
+		
146
+		return lawyer;
147
+		
148
+		
149
+				
150
+
151
+		
152
+	}
153
+	
154
+
155
+	private Entity getEntity(String canditate)
156
+	{
157
+
158
+
159
+
160
+		Entity entity = new Entity();
161
+
162
+		try{
163
+			
164
+			
21 165
 			if(canditate.contains(":") && !canditate.contains("Distribuição automática"))
22 166
 			{
23 167
 				String type = canditate.split(":")[0].trim();
24 168
 				entity.setType(type);
169
+				entity.setName(this.normalizeEntityName(canditate.split(":")[1].trim()));
25 170
 
26 171
 
27 172
 				if(type.equals("RELATORA") || type.equals("RELATOR"))		
28 173
 				{
29 174
 					entity.setType(TYPES.JUDGE);
175
+					entity.setName(this.normalizeJudgeName(canditate.split(":")[1].trim()));
176
+					
177
+					
30 178
 				}
31
-				if(type.contains("ADVOGAD") )
179
+				if(type.contains("ADVOGAD") || type.contains("PROCURADOR") )
32 180
 				{
181
+				
182
+					
183
+					entity = this.normalizeLawyerName(new Lawyer(canditate.split(":")[1].trim()) );
33 184
 					entity.setType(TYPES.LAWYER);
185
+					if(type.contains("ADVOGADOS") )
186
+						nextLawyer = true;
187
+
34 188
 				}
35 189
 
36
-				entity.setName(canditate.split(":")[1].trim());
190
+				
37 191
 
38 192
 			}
39 193
 			else
40 194
 			{
41
-				entity.setName(canditate);
42
-				entity.setType(TYPES.OTHERINFO);
195
+				if(nextLawyer)
196
+				{
197
+					nextLawyer = false;
198
+					entity.setType(TYPES.LAWYER);
199
+					entity.setName(canditate);
200
+
201
+				}
202
+				else{
203
+
204
+
205
+					entity.setName(canditate);
206
+					entity.setType(TYPES.OTHERINFO);
207
+				}
208
+
209
+
210
+
43 211
 
44 212
 
45 213
 			}
@@ -57,11 +225,25 @@ public class STJBuilder extends BuilderFactory{
57 225
 	@Override
58 226
 	protected DOProcess extractProcess(String process) {
59 227
 
60
-		
228
+
61 229
 		DOProcess proc = new DOProcess();
62
-		
230
+
231
+//		try{
232
+//			File file = new File("/home/ailton/Monografia/log");
233
+//			FileWriter fileWriter = new FileWriter(file, true);
234
+//			PrintWriter out = new PrintWriter(fileWriter);
235
+//			out.println(process);
236
+//			out.println();
237
+//			out.close();
238
+//
239
+//		}catch(Exception e)
240
+//		{
241
+//			e.printStackTrace();
242
+//		}
243
+
244
+
63 245
 		proc.setOrign("DJ_STJ");
64
-		
246
+
65 247
 		String vecProcesses[] = process.split("\n");
66 248
 		int index = 0;
67 249
 		String firstLine = vecProcesses[index];
@@ -78,24 +260,24 @@ public class STJBuilder extends BuilderFactory{
78 260
 			{
79 261
 				index++;
80 262
 				firstLine = firstLine +vecProcesses[index];
81
-				
263
+
82 264
 			}
83
-			
265
+
84 266
 			if(!firstLine.contains("class='np'"))
85 267
 			{
86 268
 				return null;
87
-				
269
+
88 270
 			}
89
-			
90
-			
271
+
272
+
91 273
 
92 274
 			String processType = firstLine.toLowerCase().split("nº")[0].toLowerCase();
93 275
 			firstLine = firstLine.substring(processType.length());
94 276
 			ProcessTypes procType = new ProcessTypes(processType);
95 277
 			proc.setProcessType(procType);
96
-			
97
-			
98
-			
278
+
279
+
280
+
99 281
 			String processIndex = firstLine.split("<NP1><B class='np'>")[0].trim();
100 282
 			firstLine = firstLine.split("<NP1><B class='np'>")[1].trim();
101 283
 			proc.setProcessIndex(processIndex);
@@ -147,33 +329,38 @@ public class STJBuilder extends BuilderFactory{
147 329
 		}
148 330
 
149 331
 
150
-		
332
+
151 333
 		/***next lines*/
152 334
 		try{
153 335
 			index++;
154
-			
336
+
155 337
 			String line = vecProcesses[index];
156 338
 
157 339
 			while( index < vecProcesses.length-1 && !this.isVerdict(line)  )
158 340
 			{
159 341
 
160 342
 				Entity entity= this.getEntity(line);
161
-				switch (entity.getType()) {
162
-				case TYPES.JUDGE:
163
-					proc.setJudge(new Judge(entity.getName()));
164
-					break;
165
-				case TYPES.OTHERINFO:
166
-					proc.addOtherInfo(entity.getName());
167
-					break;
168
-				case TYPES.LAWYER:
169
-					proc.addLawyer(new Lawyer(entity.getName()));
170
-					break;
171
-
172
-
173
-				default:
174
-					proc.addEntity(entity);
175
-					break;
343
+				
344
+				if(entity.getName() != null)
345
+				{
346
+					switch (entity.getType()) {
347
+					case TYPES.JUDGE:
348
+						proc.setJudge(new Judge(entity.getName()));
349
+						break;
350
+					case TYPES.OTHERINFO:
351
+						proc.addOtherInfo(entity.getName());
352
+						break;
353
+					case TYPES.LAWYER:
354
+						proc.addLawyer(new Lawyer(entity.getName()));
355
+						break;
356
+
357
+
358
+					default:
359
+						proc.addEntity(entity);
360
+						break;
361
+					}
176 362
 				}
363
+				
177 364
 
178 365
 				index++;
179 366
 				line = vecProcesses[index];
@@ -204,7 +391,39 @@ public class STJBuilder extends BuilderFactory{
204 391
 
205 392
 
206 393
 
394
+	private double getLowerCasePCT(String line)
395
+	{
396
+		int lowerCaseLetters = 0;
397
+		for (int i = 0; i < line.length(); i++) 
398
+		{
399
+			char ch = line.charAt(i);
400
+
401
+			//If ch is in lowercase, then incrementing lowerCaseLetters
402
+
403
+			if(Character.isLowerCase(ch))
404
+			{
405
+
406
+				lowerCaseLetters++;
407
+			}
408
+		}
409
+		if( line.length() > 0)
410
+			return 100*lowerCaseLetters/line.length();
411
+		
412
+		return lowerCaseLetters;
413
+		
414
+
415
+	}
416
+
417
+
418
+
207 419
 	private boolean isVerdict(String line) {
420
+
421
+
422
+		//System.out.println(line + " "+ this.getLowerCasePCT(line));
423
+
424
+		if(this.getLowerCasePCT(line) > 65)
425
+			return true;
426
+		
208 427
 		line = line.trim().toLowerCase();
209 428
 
210 429
 		if(line.equals("despacho"))
@@ -217,7 +436,13 @@ public class STJBuilder extends BuilderFactory{
217 436
 
218 437
 			return true;
219 438
 		}
220
-		
439
+		if(line.equals("ementa"))
440
+		{
441
+
442
+			return true;
443
+		}
444
+
445
+
221 446
 		if(line.contains("A Turma, por unanimidade"))
222 447
 		{
223 448
 			return true;

+ 1 - 1
src/graph/output/OutPutFactory.java

@@ -2,7 +2,7 @@ package graph.output;
2 2
 
3 3
 import java.util.List;
4 4
 
5
-import entity.DOProcess;
5
+import dao.entity.DOProcess;
6 6
 
7 7
 
8 8
 public abstract class OutPutFactory {

+ 25 - 8
src/graph/output/database/DatabaseOutput.java

@@ -1,16 +1,21 @@
1 1
 package graph.output.database;
2 2
 
3
+import java.io.IOException;
3 4
 import java.util.List;
4 5
 import java.util.Random;
5 6
 
6
-import dao.lucene.relation.DAOGeneralProcess;
7
-import entity.DOProcess;
7
+import dao.connection.LuceneConnector;
8
+import dao.entity.DOProcess;
9
+import dao.lucene.relations.DAOGeneralProcess;
10
+import dao.lucene.tables.DAOEntity;
11
+import dao.lucene.tables.DAOJudge;
12
+import dao.lucene.tables.DAOLawyer;
8 13
 import graph.output.OutPutFactory;
9 14
 
10 15
 public class DatabaseOutput extends OutPutFactory {
11 16
 
12 17
 	
13
-	DAOGeneralProcess dao = new DAOGeneralProcess();
18
+	DAOGeneralProcess dao =  DAOGeneralProcess.getInstance();
14 19
 	public int runned;
15 20
 	
16 21
 	public DatabaseOutput() {
@@ -38,7 +43,9 @@ public class DatabaseOutput extends OutPutFactory {
38 43
 		
39 44
 		int counter  = 0;
40 45
 		this.runned = 0;
41
-		
46
+		DAOJudge daoJudge = DAOJudge.getInstance();
47
+		DAOEntity daoEntity = DAOEntity.getInstance();
48
+		DAOLawyer daoLawyer = DAOLawyer.getInstance();
42 49
 		
43 50
 		while(allProcess.size() > 0)
44 51
 		{
@@ -46,18 +53,26 @@ public class DatabaseOutput extends OutPutFactory {
46 53
 				Random rand = new Random();
47 54
 				int randNumber = Math.abs(rand.nextInt(allProcess.size()));
48 55
 				DOProcess process= allProcess.get(randNumber);
56
+				
49 57
 				this.insertToOutPut(process);
50 58
 				counter++;
51 59
 				try{
52
-					if(counter% (processSize/100) ==0 || counter >= processSize -10)
60
+					if(counter% (processSize/50) ==0 || counter >= processSize -10)
61
+					{
62
+						
53 63
 						System.out.println("Concluido "+ counter+ " de "+ processSize);
64
+					}
65
+						
66
+					
67
+//					if((runned) % (processSize/50) ==1) 
68
+//						System.out.println("Atualizou " + runned );
69
+					
70
+					
54 71
 					
55
-					if((runned) % (processSize/100) ==1) 
56
-						System.out.println("Atualizou " + runned );
57 72
 					
58 73
 				}catch(Exception e)
59 74
 				{
60
-					
75
+					e.printStackTrace();
61 76
 				}
62 77
 				
63 78
 				allProcess.remove(process);
@@ -71,6 +86,8 @@ public class DatabaseOutput extends OutPutFactory {
71 86
 			
72 87
 
73 88
 		}
89
+		
90
+		
74 91
 		System.out.println("Foram atualizados " +runned+". Skip: " + (processSize-runned));
75 92
 
76 93
 		System.gc();

+ 2 - 2
src/graph/output/graph/JGraphOutput.java

@@ -14,8 +14,8 @@ import org.jgrapht.ext.*;
14 14
 
15 15
 import org.jgrapht.graph.*;
16 16
 
17
-import entity.DOProcess;
18
-import entity.Entity;
17
+import dao.entity.DOProcess;
18
+import dao.entity.Entity;
19 19
 
20 20
 /**
21 21
  * A demo applet that shows how to use JGraph to visualize JGraphT graphs.

+ 4 - 4
src/graph/output/screen/ScreenOutput.java

@@ -7,10 +7,10 @@ import org.graphstream.graph.Graph;
7 7
 import org.graphstream.graph.Node;
8 8
 import org.graphstream.graph.implementations.SingleGraph;
9 9
 
10
-import entity.DOProcess;
11
-import entity.Judge;
12
-import entity.Lawyer;
13
-import entity.TYPES;
10
+import dao.entity.DOProcess;
11
+import dao.entity.Judge;
12
+import dao.entity.Lawyer;
13
+import dao.entity.TYPES;
14 14
 import graph.output.OutPutFactory;
15 15
 
16 16
 public class ScreenOutput extends OutPutFactory{