Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Scoring partly done. Its now in a state that it can be used. =D
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Button committed Oct 6, 2015
1 parent bcad144 commit e479b1b
Show file tree
Hide file tree
Showing 9 changed files with 561 additions and 186 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zxcvbn
8 changes: 4 additions & 4 deletions adjacency/adjacmartix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import (
nbutton: Really the value is not as important to me than they don't change, which happened during development.
*/
func TestCalculateDegreeQwert(t *testing.T) {
avgDegreeQwert := AdjacencyGph.Qwerty.CalculateAvgDegree()
avgDegreeQwert := buildQwerty().CalculateAvgDegree()

assert.Equal(t, float32(1.531915), avgDegreeQwert, "Avg degree for qwerty should be 1.531915")
}

func TestCalculateDegreeDvorak(t *testing.T) {
avgDegreeQwert := AdjacencyGph.Dvorak.CalculateAvgDegree()
avgDegreeQwert := buildDvorak().CalculateAvgDegree()

assert.Equal(t, float32(1.531915), avgDegreeQwert, "Avg degree for dvorak should be 1.531915")
}

func TestCalculateDegreeKeypad(t *testing.T) {
avgDegreeQwert := AdjacencyGph.Keypad.CalculateAvgDegree()
avgDegreeQwert := buildKeypad().CalculateAvgDegree()

assert.Equal(t, float32(0.62222224), avgDegreeQwert, "Avg degree for keypad should be 0.62222224")
}

func TestCalculateDegreeMacKepad(t *testing.T) {
avgDegreeQwert := AdjacencyGph.MacKeypad.CalculateAvgDegree()
avgDegreeQwert := buildMacKeypad().CalculateAvgDegree()

assert.Equal(t, float32(0.6458333), avgDegreeQwert, "Avg degree for mackeyPad should be 0.6458333")
}
Expand Down
41 changes: 15 additions & 26 deletions adjacency/adjcmartix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,31 @@ import (

type AdjacencyGraph struct {
Graph map[string][6]string
averageDegree float32
averageDegree float64
Name string
}


var AdjacencyGph []AdjacencyGraph;
func init(){
//todo get currentloc so that i don't have to know the whole path
log.SetFlags(log.Lshortfile)
AdjacencyGph = append(AdjacencyGph, buildQwerty())
AdjacencyGph = append(AdjacencyGph, buildDvorak())
AdjacencyGph = append(AdjacencyGph, buildKeypad())
AdjacencyGph = append(AdjacencyGph, buildMacKeypad())



}

func buildQwerty() AdjacencyGraph {
filePath, _ := filepath.Abs("adjacency/Qwerty.json")
return getAdjancencyGraphFromFile(filePath, "qwerty")
filePath, _ := filepath.Abs("Qwerty.json")
return GetAdjancencyGraphFromFile(filePath, "qwerty")
}
func buildDvorak() AdjacencyGraph {
filePath, _ := filepath.Abs("adjacency/Dvorak.json")
return getAdjancencyGraphFromFile(filePath, "dvorak")
filePath, _ := filepath.Abs("Dvorak.json")
return GetAdjancencyGraphFromFile(filePath, "dvorak")
}
func buildKeypad() AdjacencyGraph {
filePath, _ := filepath.Abs("adjacency/Keypad.json")
return getAdjancencyGraphFromFile(filePath, "keypad")
filePath, _ := filepath.Abs("Keypad.json")
return GetAdjancencyGraphFromFile(filePath, "keypad")
}
func buildMacKeypad() AdjacencyGraph {
filePath, _ := filepath.Abs("adjacency/MacKeypad.json")
return getAdjancencyGraphFromFile(filePath, "mac_keypad")
filePath, _ := filepath.Abs("MacKeypad.json")
return GetAdjancencyGraphFromFile(filePath, "mac_keypad")
}

func getAdjancencyGraphFromFile(filePath string, name string) AdjacencyGraph {
func GetAdjancencyGraphFromFile(filePath string, name string) AdjacencyGraph {
data, err := ioutil.ReadFile(filePath)

if err != nil {
Expand All @@ -65,17 +54,17 @@ func getAdjancencyGraphFromFile(filePath string, name string) AdjacencyGraph {
//on qwerty, 'g' has degree 6, being adjacent to 'ftyhbv'. '\' has degree 1.
//this calculates the average over all keys.
//TODO double check that i ported this correctly scoring.coffee ln 5
func (adjGrp AdjacencyGraph) CalculateAvgDegree() (float32) {
if adjGrp.averageDegree != float32(0) {
func (adjGrp AdjacencyGraph) CalculateAvgDegree() (float64) {
if adjGrp.averageDegree != float64(0) {
return adjGrp.averageDegree
}
var avg float32
var count float32
var avg float64
var count float64
for _, value := range adjGrp.Graph {

for _, char := range value {
if char != "" || char != " " {
avg += float32(len(char))
avg += float64(len(char))
count++
}
}
Expand Down
38 changes: 38 additions & 0 deletions match/match.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package match

type Matches []Match
func (s Matches)Len() int {
return len(s)
}
func (s Matches)Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s Matches) Less(i, j int) bool {
if s[i].I < s[j].I {
return true
} else if s[i].I == s[j].I {
return s[i].J < s[j].J
} else {
return false
}
}
type Match struct {
Pattern string
I, J int
Token string
MatchedWord string
Rank float64
DictionaryName string
Turns int
ShiftedCount int
Entropy float64
}

type DateMatch struct {
Pattern string
I, J int
Token string
Separator string
Day, Month, Year int64

}
Loading

0 comments on commit e479b1b

Please sign in to comment.