Skip to content

Commit 4a68d9f

Browse files
author
fillol
committed
Improvement on the CSV reading and writing function
1 parent 246b857 commit 4a68d9f

3 files changed

Lines changed: 72 additions & 11 deletions

File tree

CSV/createCSV.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package CSV
2+
3+
import (
4+
"github.com/Darklabel91/Summary_Classifier"
5+
"github.com/Darklabel91/Summary_Classifier/Struct"
6+
)
7+
8+
func CreateCSVs(raw []Struct.Raw_decision, nameResultFolder string) {
9+
var totalInfered []Struct.Infered_decision
10+
var exOfficioReview []Struct.Infered_decision
11+
var diligence []Struct.Infered_decision
12+
var affected []Struct.Infered_decision
13+
var partial []Struct.Infered_decision
14+
var groundless []Struct.Infered_decision
15+
var hasGround []Struct.Infered_decision
16+
var noInfo []Struct.Infered_decision
17+
var notMap []Struct.Infered_decision
18+
19+
for i := 0; i < len(raw); i++ {
20+
emp := Summary_Classifier.SummaryClassifier(raw[i].Summary, raw[i].Identifier, raw[i].Court)
21+
totalInfered = append(totalInfered, emp)
22+
if emp.Class == "Reexame Necessário" {
23+
exOfficioReview = append(exOfficioReview, emp)
24+
} else if emp.Class == "Convertido em Diligência" {
25+
diligence = append(diligence, emp)
26+
} else if emp.Class == "Prejudicado" {
27+
affected = append(affected, emp)
28+
} else if emp.Class == "Parcial Provimento" {
29+
partial = append(partial, emp)
30+
} else if emp.Class == "Improvimento" {
31+
groundless = append(groundless, emp)
32+
} else if emp.Class == "Provimento" {
33+
hasGround = append(hasGround, emp)
34+
} else if emp.Class == "Sem Informação" {
35+
noInfo = append(noInfo, emp)
36+
} else if emp.Class == "Não Mapeado" {
37+
notMap = append(notMap, emp)
38+
}
39+
40+
}
41+
42+
exportCSV("totalInfered", nameResultFolder, totalInfered)
43+
44+
if len(exOfficioReview) != 0 {
45+
exportCSV("exOfficioReview", nameResultFolder, exOfficioReview)
46+
}
47+
if len(diligence) != 0 {
48+
exportCSV("diligence", nameResultFolder, diligence)
49+
}
50+
if len(affected) != 0 {
51+
exportCSV("affected", nameResultFolder, affected)
52+
}
53+
if len(partial) != 0 {
54+
exportCSV("partial", nameResultFolder, partial)
55+
}
56+
if len(groundless) != 0 {
57+
exportCSV("groundless", nameResultFolder, groundless)
58+
}
59+
if len(hasGround) != 0 {
60+
exportCSV("hasGround", nameResultFolder, hasGround)
61+
}
62+
if len(noInfo) != 0 {
63+
exportCSV("noInfo", nameResultFolder, noInfo)
64+
}
65+
if len(notMap) != 0 {
66+
exportCSV("notMap", nameResultFolder, notMap)
67+
}
68+
}

CSV/write.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package CSV
22

33
import (
44
"encoding/csv"
5-
"fmt"
65
"github.com/Darklabel91/Summary_Classifier/Error"
76
"github.com/Darklabel91/Summary_Classifier/Struct"
87
"os"
@@ -13,11 +12,10 @@ func create(p string) (*os.File, error) {
1312
if err := os.MkdirAll(filepath.Dir(p), 0770); err != nil {
1413
return nil, err
1514
}
16-
fmt.Println("Criou .csv")
1715
return os.Create(p)
1816
}
1917

20-
func ExportCSV(nameFile string, nameFolder string, result []Struct.Infered_decision) {
18+
func exportCSV(nameFile string, nameFolder string, result []Struct.Infered_decision) {
2119
empData := [][]string{}
2220

2321
for i := 0; i < len(result); i++ {

Summary_Classifier.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package Summary_Classifier
22

33
import (
4+
"fmt"
45
"github.com/Darklabel91/Summary_Classifier/CSV"
56
"github.com/Darklabel91/Summary_Classifier/Classifier"
67
"github.com/Darklabel91/Summary_Classifier/Struct"
@@ -24,13 +25,7 @@ func SummaryClassifier(summary string, identifier string, court string) Struct.I
2425

2526
}
2627
func SummaryClassifierCSV(rawDecisionPath string, separator rune, nameResultFolder string) {
27-
var infered []Struct.Infered_decision
28-
2928
raw := CSV.ReadCsvFile(rawDecisionPath, separator)
30-
31-
for i := 0; i < len(raw); i++ {
32-
infered = append(infered, SummaryClassifier(raw[i].Summary, raw[i].Identifier, raw[i].Court))
33-
}
34-
35-
CSV.ExportCSV("Infered Decision", nameResultFolder, infered)
29+
CSV.CreateCSVs(raw, nameResultFolder)
30+
fmt.Println("Files created")
3631
}

0 commit comments

Comments
 (0)