Add a bunch of useless comments to make linter happy

pull/15/head
Simon Let 6 years ago
parent 79d7f1c45e
commit 882e2f34a3
  1. 6
      pkg/strat/directory-sensitive.go
  2. 5
      pkg/strat/dummy.go
  3. 6
      pkg/strat/dynamic-record-distance.go
  4. 10
      pkg/strat/frequent.go
  5. 6
      pkg/strat/markov-chain-cmd.go
  6. 6
      pkg/strat/markov-chain.go
  7. 6
      pkg/strat/random.go
  8. 6
      pkg/strat/recent-bash.go
  9. 5
      pkg/strat/recent.go
  10. 6
      pkg/strat/record-distance.go
  11. 2
      pkg/strat/strat.go

@ -2,23 +2,28 @@ package strat
import "github.com/curusarn/resh/pkg/records" import "github.com/curusarn/resh/pkg/records"
// DirectorySensitive prediction/recommendation strategy
type DirectorySensitive struct { type DirectorySensitive struct {
history map[string][]string history map[string][]string
lastPwd string lastPwd string
} }
// Init see name
func (s *DirectorySensitive) Init() { func (s *DirectorySensitive) Init() {
s.history = map[string][]string{} s.history = map[string][]string{}
} }
// GetTitleAndDescription see name
func (s *DirectorySensitive) GetTitleAndDescription() (string, string) { func (s *DirectorySensitive) GetTitleAndDescription() (string, string) {
return "directory sensitive (recent)", "Use recent commands executed is the same directory" return "directory sensitive (recent)", "Use recent commands executed is the same directory"
} }
// GetCandidates see name
func (s *DirectorySensitive) GetCandidates() []string { func (s *DirectorySensitive) GetCandidates() []string {
return s.history[s.lastPwd] return s.history[s.lastPwd]
} }
// AddHistoryRecord see name
func (s *DirectorySensitive) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *DirectorySensitive) AddHistoryRecord(record *records.EnrichedRecord) error {
// work on history for PWD // work on history for PWD
pwd := record.Pwd pwd := record.Pwd
@ -34,6 +39,7 @@ func (s *DirectorySensitive) AddHistoryRecord(record *records.EnrichedRecord) er
return nil return nil
} }
// ResetHistory see name
func (s *DirectorySensitive) ResetHistory() error { func (s *DirectorySensitive) ResetHistory() error {
s.Init() s.Init()
s.history = map[string][]string{} s.history = map[string][]string{}

@ -2,23 +2,28 @@ package strat
import "github.com/curusarn/resh/pkg/records" import "github.com/curusarn/resh/pkg/records"
// Dummy prediction/recommendation strategy
type Dummy struct { type Dummy struct {
history []string history []string
} }
// GetTitleAndDescription see name
func (s *Dummy) GetTitleAndDescription() (string, string) { func (s *Dummy) GetTitleAndDescription() (string, string) {
return "dummy", "Return empty candidate list" return "dummy", "Return empty candidate list"
} }
// GetCandidates see name
func (s *Dummy) GetCandidates() []string { func (s *Dummy) GetCandidates() []string {
return nil return nil
} }
// AddHistoryRecord see name
func (s *Dummy) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *Dummy) AddHistoryRecord(record *records.EnrichedRecord) error {
s.history = append(s.history, record.CmdLine) s.history = append(s.history, record.CmdLine)
return nil return nil
} }
// ResetHistory see name
func (s *Dummy) ResetHistory() error { func (s *Dummy) ResetHistory() error {
return nil return nil
} }

@ -8,6 +8,7 @@ import (
"github.com/curusarn/resh/pkg/records" "github.com/curusarn/resh/pkg/records"
) )
// DynamicRecordDistance prediction/recommendation strategy
type DynamicRecordDistance struct { type DynamicRecordDistance struct {
history []records.EnrichedRecord history []records.EnrichedRecord
DistParams records.DistParams DistParams records.DistParams
@ -23,6 +24,7 @@ type strDynDistEntry struct {
distance float64 distance float64
} }
// Init see name
func (s *DynamicRecordDistance) Init() { func (s *DynamicRecordDistance) Init() {
s.history = nil s.history = nil
s.pwdHistogram = map[string]int{} s.pwdHistogram = map[string]int{}
@ -30,6 +32,7 @@ func (s *DynamicRecordDistance) Init() {
s.gitOriginHistogram = map[string]int{} s.gitOriginHistogram = map[string]int{}
} }
// GetTitleAndDescription see name
func (s *DynamicRecordDistance) GetTitleAndDescription() (string, string) { func (s *DynamicRecordDistance) GetTitleAndDescription() (string, string) {
return "dynamic record distance (depth:" + strconv.Itoa(s.MaxDepth) + ";" + s.Label + ")", "Use TF-IDF record distance to recommend commands" return "dynamic record distance (depth:" + strconv.Itoa(s.MaxDepth) + ";" + s.Label + ")", "Use TF-IDF record distance to recommend commands"
} }
@ -38,6 +41,7 @@ func (s *DynamicRecordDistance) idf(count int) float64 {
return math.Log(float64(len(s.history)) / float64(count)) return math.Log(float64(len(s.history)) / float64(count))
} }
// GetCandidates see name
func (s *DynamicRecordDistance) GetCandidates(strippedRecord records.EnrichedRecord) []string { func (s *DynamicRecordDistance) GetCandidates(strippedRecord records.EnrichedRecord) []string {
if len(s.history) == 0 { if len(s.history) == 0 {
return nil return nil
@ -70,6 +74,7 @@ func (s *DynamicRecordDistance) GetCandidates(strippedRecord records.EnrichedRec
return hist return hist
} }
// AddHistoryRecord see name
func (s *DynamicRecordDistance) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *DynamicRecordDistance) AddHistoryRecord(record *records.EnrichedRecord) error {
// append record to front // append record to front
s.history = append([]records.EnrichedRecord{*record}, s.history...) s.history = append([]records.EnrichedRecord{*record}, s.history...)
@ -79,6 +84,7 @@ func (s *DynamicRecordDistance) AddHistoryRecord(record *records.EnrichedRecord)
return nil return nil
} }
// ResetHistory see name
func (s *DynamicRecordDistance) ResetHistory() error { func (s *DynamicRecordDistance) ResetHistory() error {
s.Init() s.Init()
return nil return nil

@ -6,6 +6,7 @@ import (
"github.com/curusarn/resh/pkg/records" "github.com/curusarn/resh/pkg/records"
) )
// Frequent prediction/recommendation strategy
type Frequent struct { type Frequent struct {
history map[string]int history map[string]int
} }
@ -15,14 +16,17 @@ type strFrqEntry struct {
count int count int
} }
func (s *Frequent) init() { // Init see name
func (s *Frequent) Init() {
s.history = map[string]int{} s.history = map[string]int{}
} }
// GetTitleAndDescription see name
func (s *Frequent) GetTitleAndDescription() (string, string) { func (s *Frequent) GetTitleAndDescription() (string, string) {
return "frequent", "Use frequent commands" return "frequent", "Use frequent commands"
} }
// GetCandidates see name
func (s *Frequent) GetCandidates() []string { func (s *Frequent) GetCandidates() []string {
var mapItems []strFrqEntry var mapItems []strFrqEntry
for cmdLine, count := range s.history { for cmdLine, count := range s.history {
@ -36,12 +40,14 @@ func (s *Frequent) GetCandidates() []string {
return hist return hist
} }
// AddHistoryRecord see name
func (s *Frequent) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *Frequent) AddHistoryRecord(record *records.EnrichedRecord) error {
s.history[record.CmdLine]++ s.history[record.CmdLine]++
return nil return nil
} }
// ResetHistory see name
func (s *Frequent) ResetHistory() error { func (s *Frequent) ResetHistory() error {
s.init() s.Init()
return nil return nil
} }

@ -8,6 +8,7 @@ import (
"github.com/mb-14/gomarkov" "github.com/mb-14/gomarkov"
) )
// MarkovChainCmd prediction/recommendation strategy
type MarkovChainCmd struct { type MarkovChainCmd struct {
Order int Order int
history []strMarkCmdHistoryEntry history []strMarkCmdHistoryEntry
@ -24,15 +25,18 @@ type strMarkCmdEntry struct {
transProb float64 transProb float64
} }
// Init see name
func (s *MarkovChainCmd) Init() { func (s *MarkovChainCmd) Init() {
s.history = nil s.history = nil
s.historyCmds = nil s.historyCmds = nil
} }
// GetTitleAndDescription see name
func (s *MarkovChainCmd) GetTitleAndDescription() (string, string) { func (s *MarkovChainCmd) GetTitleAndDescription() (string, string) {
return "command-based markov chain (order " + strconv.Itoa(s.Order) + ")", "Use command-based markov chain to recommend commands" return "command-based markov chain (order " + strconv.Itoa(s.Order) + ")", "Use command-based markov chain to recommend commands"
} }
// GetCandidates see name
func (s *MarkovChainCmd) GetCandidates() []string { func (s *MarkovChainCmd) GetCandidates() []string {
if len(s.history) < s.Order { if len(s.history) < s.Order {
var hist []string var hist []string
@ -78,6 +82,7 @@ func (s *MarkovChainCmd) GetCandidates() []string {
return hist return hist
} }
// AddHistoryRecord see name
func (s *MarkovChainCmd) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *MarkovChainCmd) AddHistoryRecord(record *records.EnrichedRecord) error {
s.history = append(s.history, strMarkCmdHistoryEntry{cmdLine: record.CmdLine, cmd: record.Command}) s.history = append(s.history, strMarkCmdHistoryEntry{cmdLine: record.CmdLine, cmd: record.Command})
s.historyCmds = append(s.historyCmds, record.Command) s.historyCmds = append(s.historyCmds, record.Command)
@ -85,6 +90,7 @@ func (s *MarkovChainCmd) AddHistoryRecord(record *records.EnrichedRecord) error
return nil return nil
} }
// ResetHistory see name
func (s *MarkovChainCmd) ResetHistory() error { func (s *MarkovChainCmd) ResetHistory() error {
s.Init() s.Init()
return nil return nil

@ -8,6 +8,7 @@ import (
"github.com/mb-14/gomarkov" "github.com/mb-14/gomarkov"
) )
// MarkovChain prediction/recommendation strategy
type MarkovChain struct { type MarkovChain struct {
Order int Order int
history []string history []string
@ -18,14 +19,17 @@ type strMarkEntry struct {
transProb float64 transProb float64
} }
// Init see name
func (s *MarkovChain) Init() { func (s *MarkovChain) Init() {
s.history = nil s.history = nil
} }
// GetTitleAndDescription see name
func (s *MarkovChain) GetTitleAndDescription() (string, string) { func (s *MarkovChain) GetTitleAndDescription() (string, string) {
return "markov chain (order " + strconv.Itoa(s.Order) + ")", "Use markov chain to recommend commands" return "markov chain (order " + strconv.Itoa(s.Order) + ")", "Use markov chain to recommend commands"
} }
// GetCandidates see name
func (s *MarkovChain) GetCandidates() []string { func (s *MarkovChain) GetCandidates() []string {
if len(s.history) < s.Order { if len(s.history) < s.Order {
return s.history return s.history
@ -58,12 +62,14 @@ func (s *MarkovChain) GetCandidates() []string {
return hist return hist
} }
// AddHistoryRecord see name
func (s *MarkovChain) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *MarkovChain) AddHistoryRecord(record *records.EnrichedRecord) error {
s.history = append(s.history, record.CmdLine) s.history = append(s.history, record.CmdLine)
// s.historySet[record.CmdLine] = true // s.historySet[record.CmdLine] = true
return nil return nil
} }
// ResetHistory see name
func (s *MarkovChain) ResetHistory() error { func (s *MarkovChain) ResetHistory() error {
s.Init() s.Init()
return nil return nil

@ -7,21 +7,25 @@ import (
"github.com/curusarn/resh/pkg/records" "github.com/curusarn/resh/pkg/records"
) )
// Random prediction/recommendation strategy
type Random struct { type Random struct {
CandidatesSize int CandidatesSize int
history []string history []string
historySet map[string]bool historySet map[string]bool
} }
// Init see name
func (s *Random) Init() { func (s *Random) Init() {
s.history = nil s.history = nil
s.historySet = map[string]bool{} s.historySet = map[string]bool{}
} }
// GetTitleAndDescription see name
func (s *Random) GetTitleAndDescription() (string, string) { func (s *Random) GetTitleAndDescription() (string, string) {
return "random", "Use random commands" return "random", "Use random commands"
} }
// GetCandidates see name
func (s *Random) GetCandidates() []string { func (s *Random) GetCandidates() []string {
seed := time.Now().UnixNano() seed := time.Now().UnixNano()
rand.Seed(seed) rand.Seed(seed)
@ -39,12 +43,14 @@ func (s *Random) GetCandidates() []string {
return candidates return candidates
} }
// AddHistoryRecord see name
func (s *Random) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *Random) AddHistoryRecord(record *records.EnrichedRecord) error {
s.history = append([]string{record.CmdLine}, s.history...) s.history = append([]string{record.CmdLine}, s.history...)
s.historySet[record.CmdLine] = true s.historySet[record.CmdLine] = true
return nil return nil
} }
// ResetHistory see name
func (s *Random) ResetHistory() error { func (s *Random) ResetHistory() error {
s.Init() s.Init()
return nil return nil

@ -2,21 +2,25 @@ package strat
import "github.com/curusarn/resh/pkg/records" import "github.com/curusarn/resh/pkg/records"
// RecentBash prediction/recommendation strategy
type RecentBash struct { type RecentBash struct {
histfile []string histfile []string
histfileSnapshot map[string][]string histfileSnapshot map[string][]string
history map[string][]string history map[string][]string
} }
// Init see name
func (s *RecentBash) Init() { func (s *RecentBash) Init() {
s.histfileSnapshot = map[string][]string{} s.histfileSnapshot = map[string][]string{}
s.history = map[string][]string{} s.history = map[string][]string{}
} }
// GetTitleAndDescription see name
func (s *RecentBash) GetTitleAndDescription() (string, string) { func (s *RecentBash) GetTitleAndDescription() (string, string) {
return "recent (bash-like)", "Behave like bash" return "recent (bash-like)", "Behave like bash"
} }
// GetCandidates see name
func (s *RecentBash) GetCandidates(strippedRecord records.EnrichedRecord) []string { func (s *RecentBash) GetCandidates(strippedRecord records.EnrichedRecord) []string {
// populate the local history from histfile // populate the local history from histfile
if s.histfileSnapshot[strippedRecord.SessionID] == nil { if s.histfileSnapshot[strippedRecord.SessionID] == nil {
@ -25,6 +29,7 @@ func (s *RecentBash) GetCandidates(strippedRecord records.EnrichedRecord) []stri
return append(s.history[strippedRecord.SessionID], s.histfileSnapshot[strippedRecord.SessionID]...) return append(s.history[strippedRecord.SessionID], s.histfileSnapshot[strippedRecord.SessionID]...)
} }
// AddHistoryRecord see name
func (s *RecentBash) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *RecentBash) AddHistoryRecord(record *records.EnrichedRecord) error {
// remove previous occurance of record // remove previous occurance of record
for i, cmd := range s.history[record.SessionID] { for i, cmd := range s.history[record.SessionID] {
@ -44,6 +49,7 @@ func (s *RecentBash) AddHistoryRecord(record *records.EnrichedRecord) error {
return nil return nil
} }
// ResetHistory see name
func (s *RecentBash) ResetHistory() error { func (s *RecentBash) ResetHistory() error {
s.Init() s.Init()
return nil return nil

@ -2,18 +2,22 @@ package strat
import "github.com/curusarn/resh/pkg/records" import "github.com/curusarn/resh/pkg/records"
// Recent prediction/recommendation strategy
type Recent struct { type Recent struct {
history []string history []string
} }
// GetTitleAndDescription see name
func (s *Recent) GetTitleAndDescription() (string, string) { func (s *Recent) GetTitleAndDescription() (string, string) {
return "recent", "Use recent commands" return "recent", "Use recent commands"
} }
// GetCandidates see name
func (s *Recent) GetCandidates() []string { func (s *Recent) GetCandidates() []string {
return s.history return s.history
} }
// AddHistoryRecord see name
func (s *Recent) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *Recent) AddHistoryRecord(record *records.EnrichedRecord) error {
// remove previous occurance of record // remove previous occurance of record
for i, cmd := range s.history { for i, cmd := range s.history {
@ -26,6 +30,7 @@ func (s *Recent) AddHistoryRecord(record *records.EnrichedRecord) error {
return nil return nil
} }
// ResetHistory see name
func (s *Recent) ResetHistory() error { func (s *Recent) ResetHistory() error {
s.history = nil s.history = nil
return nil return nil

@ -7,6 +7,7 @@ import (
"github.com/curusarn/resh/pkg/records" "github.com/curusarn/resh/pkg/records"
) )
// RecordDistance prediction/recommendation strategy
type RecordDistance struct { type RecordDistance struct {
history []records.EnrichedRecord history []records.EnrichedRecord
DistParams records.DistParams DistParams records.DistParams
@ -19,14 +20,17 @@ type strDistEntry struct {
distance float64 distance float64
} }
// Init see name
func (s *RecordDistance) Init() { func (s *RecordDistance) Init() {
s.history = nil s.history = nil
} }
// GetTitleAndDescription see name
func (s *RecordDistance) GetTitleAndDescription() (string, string) { func (s *RecordDistance) GetTitleAndDescription() (string, string) {
return "record distance (depth:" + strconv.Itoa(s.MaxDepth) + ";" + s.Label + ")", "Use record distance to recommend commands" return "record distance (depth:" + strconv.Itoa(s.MaxDepth) + ";" + s.Label + ")", "Use record distance to recommend commands"
} }
// GetCandidates see name
func (s *RecordDistance) GetCandidates(strippedRecord records.EnrichedRecord) []string { func (s *RecordDistance) GetCandidates(strippedRecord records.EnrichedRecord) []string {
if len(s.history) == 0 { if len(s.history) == 0 {
return nil return nil
@ -52,12 +56,14 @@ func (s *RecordDistance) GetCandidates(strippedRecord records.EnrichedRecord) []
return hist return hist
} }
// AddHistoryRecord see name
func (s *RecordDistance) AddHistoryRecord(record *records.EnrichedRecord) error { func (s *RecordDistance) AddHistoryRecord(record *records.EnrichedRecord) error {
// append record to front // append record to front
s.history = append([]records.EnrichedRecord{*record}, s.history...) s.history = append([]records.EnrichedRecord{*record}, s.history...)
return nil return nil
} }
// ResetHistory see name
func (s *RecordDistance) ResetHistory() error { func (s *RecordDistance) ResetHistory() error {
s.Init() s.Init()
return nil return nil

@ -4,6 +4,7 @@ import (
"github.com/curusarn/resh/pkg/records" "github.com/curusarn/resh/pkg/records"
) )
// ISimpleStrategy interface
type ISimpleStrategy interface { type ISimpleStrategy interface {
GetTitleAndDescription() (string, string) GetTitleAndDescription() (string, string)
GetCandidates() []string GetCandidates() []string
@ -11,6 +12,7 @@ type ISimpleStrategy interface {
ResetHistory() error ResetHistory() error
} }
// IStrategy interface
type IStrategy interface { type IStrategy interface {
GetTitleAndDescription() (string, string) GetTitleAndDescription() (string, string)
GetCandidates(r records.EnrichedRecord) []string GetCandidates(r records.EnrichedRecord) []string

Loading…
Cancel
Save