未验证 提交 43ce7b5a 编写于 作者: P Phodal Huang

feat: update concept output

上级 42001fb1
......@@ -196,25 +196,21 @@ coca concept
Results Examples:
```
product 874
time 541
member 405
like 404
example 371
order 328
primary 288
criterion 222
price 214
selective 212
promotion 198
list 196
category 184
icon 160
note 159
pic 147
point 143
brand 131
receiver 121
+------------------+--------+
| WORDS | COUNTS |
+------------------+--------+
| context | 590 |
| resolve | 531 |
| path | 501 |
| content | 423 |
| code | 416 |
| resource | 373 |
| property | 372 |
| session | 364 |
| attribute | 349 |
| properties | 343 |
| headers | 330 |
+------------------+--------+
```
### Count Refs
......
package cmd
import (
"encoding/json"
"github.com/olekukonko/tablewriter"
"github.com/phodal/coca/config"
"github.com/phodal/coca/core/domain/concept"
"github.com/phodal/coca/core/models"
. "github.com/phodal/coca/core/support"
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"log"
"os"
"strconv"
)
var parsedDeps []models.JClassNode
......@@ -27,14 +29,20 @@ var conceptCmd = &cobra.Command{
log.Fatal("lost file:" + dependence)
}
_ = json.Unmarshal(file, &parsedDeps)
_ = json.Unmarshal(file, &parsedDeps)
wordCounts := analyser.Analysis(&parsedDeps)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Words", "Counts"})
for _, word := range wordCounts {
if word.Value > 0 {
fmt.Println(word.Key, word.Value)
table.Append([]string{word.Key, strconv.Itoa(word.Value)})
}
}
table.Render()
}
},
}
......
......@@ -46,6 +46,7 @@ var itStopWords = []string{
"update",
"delete",
"save",
"post",
"add",
"remove",
......@@ -105,8 +106,17 @@ var itStopWords = []string{
"message",
"factory",
"error",
"error",
"errors",
"exception",
"null",
"string",
"init",
"data",
"hash",
"convert",
"size",
"build",
"return",
}
func removeNormalWords(words map[string]int) map[string]int {
......
......@@ -2,6 +2,7 @@ package concept
import (
"github.com/iancoleman/strcase"
"regexp"
"strings"
)
......@@ -25,6 +26,9 @@ func SegmentConceptCamelcase(methodsName []string) map[string]int {
delimited := strcase.ToDelimited(name, '.')
split := strings.Split(delimited, ".")
for _, word := range split {
if FilterString(word) == "" {
continue
}
if strMap[word] == 0 {
strMap[word] = 1
} else {
......@@ -36,3 +40,13 @@ func SegmentConceptCamelcase(methodsName []string) map[string]int {
return strMap
}
func FilterString(str string) string {
var digitCheck = regexp.MustCompile(`^[0-9]+$`)
if digitCheck.MatchString(str) {
return ""
}
return strings.TrimSpace(str)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册