-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaccard.go
62 lines (49 loc) · 1.12 KB
/
jaccard.go
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
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
var list1 map[string]int // Vars must be defined
var list2 map[string]int //
var longlist map[string]int //
//
func main() { //
//
list1 = make(map[string]int) // and instanced seperately
list2 = make(map[string]int) //
longlist = make(map[string]int)
for argc,argv := range(os.Args) { // foreach argv
if argc > 0 { // skip argv[0]
if _,x := os.Stat(argv); !os.IsNotExist(x) { // if existing file
dat,_ := ioutil.ReadFile(argv) // read into memory
arr := strings.Split(string(dat), "\n")
for _,line := range(arr) {
if argc == 1 {
v := string(line)
list1[v] = 1
longlist[v] = 1
}
if argc == 2 {
v := string(line)
list2[v] = 1
longlist[v] = 1
}
}
}
}
}
intersection := 0
union := 0
for item := range(longlist) {
_,in_one := list1[item]
_,in_two := list2[item]
if in_one && in_two {
intersection += 1
}
union += 1
}
jack := float32(intersection) / float32(union)
fmt.Println(jack)
}