-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
61 lines (49 loc) · 933 Bytes
/
main.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
//go:build exclude
package main
import (
"fmt"
"os"
"github.com/robherley/guesslang-go/pkg/guesser"
)
/*
This is a simple example of how to use the guesser package.
Expected output:
Best => rs
Reliable => true
Top Five:
- rs (21.66%)
- java (4.87%)
- ts (4.66%)
- js (4.62%)
- html (4.07%)
*/
const snippet = `
fn bubble_sort(arr: &mut [i32]) {
let len = arr.len();
for i in 0..len {
for j in 0..len - i - 1 {
if arr[j] > arr[j + 1] {
arr.swap(j, j + 1);
}
}
}
}
`
func main() {
gsr, err := guesser.New()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
answer, err := gsr.Guess(snippet)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Best =>", answer.Predictions[0].Language)
fmt.Println("Reliable =>", answer.Reliable)
fmt.Println("Top Five:")
for _, lang := range answer.Predictions[:5] {
fmt.Printf("- %s (%.2f%%)\n", lang.Language, lang.Confidence*100)
}
}