-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathguesscategory.go
144 lines (137 loc) · 4.59 KB
/
guesscategory.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"errors"
"strings"
)
// TODO: Use a config file for the mappings
const (
// Decides the order of the keyword/category checks
// (try to order from the more specific/specialized categories to the more general)
tracker = iota
texttools
graphics2d
scanning
utility
settings
hardwaresettings
audio
video
education
math
cs
compression
filetools
model3d
multimedia
graphics
network
email
audiovideo
office
editor
science
vcs
arcadegame
actiongame
adventuregame
logicgame
boardgame
game
programming
system
last
)
var (
keywordmap = map[int][]string{
tracker: {"sequencer"},
model3d: {"rendering", "modeling", "modelling", "modeler", "render", "raytracing", "CAD"},
multimedia: {"non-linear", "audio", "sound", "graphics", "demo", "music"},
graphics: {"draw", "pixelart", "animated"},
network: {"network", "p2p", "browser", "remote"},
email: {"gmail", "email", "e-mail", "mail"},
audiovideo: {"synth", "synthesizer", "ffmpeg", "guitar"},
office: {"ebook", "e-book", "spreadsheet", "calculator", "processor", "documents"},
editor: {"editor"},
science: {"gps", "inspecting", "molecular", "mathematics"},
vcs: {"git"},
arcadegame: {"combat", "arcade", "racing", "fighting", "fight", "shooter"},
actiongame: {"shooter", "fps"},
adventuregame: {"roguelike", "rpg"},
logicgame: {"puzzle"},
boardgame: {"board", "chess", "goban", "chessboard", "checkers", "reversi", "go"},
// "emulator" and "player" aren't always for games, but those cases will be
// picked up by one of the other categories first, as orderd by the constants above
game: {"game", "rts", "mmorpg", "emulator", "player"},
programming: {"code", "ide", "programming", "develop", "compile", "interpret", "valgrind"},
system: {"sensor", "bus", "calibration", "usb", "file"},
}
categorymap = map[int]string{
tracker: "Application;Multimedia;Audio;Sequencer;Music",
model3d: "Application;Graphics;3DGraphics",
multimedia: "Application;Multimedia",
graphics: "Application;Graphics",
network: "Application;Network",
email: "Application;Network;Email",
audiovideo: "Application;AudioVideo",
office: "Application;Office",
editor: "Application;Development;TextEditor",
science: "Application;Science",
vcs: "Application;Development;RevisionControl",
arcadegame: "Application;Game;ArcadeGame",
actiongame: "Application;Game;ActionGame",
adventuregame: "Application;Game;AdventureGame",
logicgame: "Application;Game",
boardgame: "Application;Game;BoardGame",
game: "Application;Game",
programming: "Application;Development",
system: "Application;System",
texttools: "Application;TextTools",
graphics2d: "Application;Graphics;2DGraphics",
scanning: "Application;Grahpics;Scanning",
utility: "Application;Utility",
settings: "Application;Settings",
hardwaresettings: "Application;HardwareSettings;Settings",
audio: "Application;AudioVideo;Audio",
video: "Application;AudioVideo;Video",
education: "Application;Science",
math: "Application;Science;Math",
cs: "Application;Science;ComputerScience",
compression: "Application;Utility;Archiving",
filetools: "Application;System;FileTools",
}
)
// ValidCategoryWords validates each word in 'categoryWords' against a list of accepted categories derived from 'categorymap'.
// It ensures all provided words represent valid application categories, returning an error for any unrecognized category.
func ValidCategoryWords(categoryWords []string) error {
var validWords []string
for _, v := range categorymap {
fields := strings.Split(v, ";")
for _, field := range fields {
if strings.TrimSpace(field) == "" {
continue
}
if !hasS(validWords, field) {
validWords = append(validWords, field)
}
}
}
for _, word := range categoryWords {
if !hasS(validWords, word) {
return errors.New(word + " is an unrecognized category")
}
}
return nil
}
// GuessCategory will try to guess which category an application belongs to,
// given a short package description.
// If no guess is made, it will return "Application".
func GuessCategory(pkgdesc string) string {
var keywordList []string
for key := 0; key < last; key++ {
keywordList = keywordmap[key]
if keywordsInDescription(pkgdesc, keywordList) {
return categorymap[key]
}
}
return "Application"
}