generated from VLADIMIR/template
clear
This commit is contained in:
parent
09b04de9c3
commit
ee76743097
39
internal/services/story_service/cleaners.go
Normal file
39
internal/services/story_service/cleaners.go
Normal file
@ -0,0 +1,39 @@
|
||||
package story_service
|
||||
|
||||
import "strings"
|
||||
|
||||
var (
|
||||
replaceMap = map[string]string{
|
||||
"a": "а",
|
||||
"e": "е",
|
||||
"o": "о",
|
||||
"c": "с",
|
||||
"p": "р",
|
||||
"x": "х",
|
||||
"y": "у",
|
||||
"k": "к",
|
||||
"m": "м",
|
||||
"t": "т",
|
||||
"h": "н",
|
||||
"b": "в",
|
||||
"u": "и",
|
||||
}
|
||||
)
|
||||
|
||||
func clearMatch(s string) string {
|
||||
s = strings.TrimPrefix(s, "(")
|
||||
s = strings.TrimPrefix(s, "[")
|
||||
s = strings.TrimSuffix(s, ")")
|
||||
s = strings.TrimSuffix(s, "]")
|
||||
return clearCode(s)
|
||||
}
|
||||
|
||||
func clearCode(code string) string {
|
||||
code = strings.ToLower(code)
|
||||
code = strings.TrimSpace(code)
|
||||
code = strings.ReplaceAll(code, "-", "")
|
||||
for latin, cyrillic := range replaceMap {
|
||||
code = strings.ReplaceAll(code, latin, cyrillic)
|
||||
}
|
||||
return code
|
||||
}
|
||||
16
internal/services/story_service/data_models.go
Normal file
16
internal/services/story_service/data_models.go
Normal file
@ -0,0 +1,16 @@
|
||||
package story_service
|
||||
|
||||
type Story struct {
|
||||
Places []*Place `json:"places"`
|
||||
}
|
||||
|
||||
type Place struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Text string `json:"text"`
|
||||
Applications []*Application `json:"applications"`
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
23
internal/services/story_service/dto_models.go
Normal file
23
internal/services/story_service/dto_models.go
Normal file
@ -0,0 +1,23 @@
|
||||
package story_service
|
||||
|
||||
type Graph struct {
|
||||
Nodes []*GraphNode
|
||||
Edges []*GraphEdge
|
||||
}
|
||||
|
||||
type GraphNode struct {
|
||||
ID int32
|
||||
Label string
|
||||
Name string
|
||||
Text string
|
||||
Applications []*GraphApplication
|
||||
}
|
||||
|
||||
type GraphEdge struct {
|
||||
From int32
|
||||
To int32
|
||||
}
|
||||
|
||||
type GraphApplication struct {
|
||||
Name string
|
||||
}
|
||||
@ -10,61 +10,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
replaceMap = map[string]string{
|
||||
"a": "а",
|
||||
"e": "е",
|
||||
"o": "о",
|
||||
"c": "с",
|
||||
"p": "р",
|
||||
"x": "х",
|
||||
"y": "у",
|
||||
"k": "к",
|
||||
"m": "м",
|
||||
"t": "т",
|
||||
"h": "н",
|
||||
"b": "в",
|
||||
"u": "и",
|
||||
}
|
||||
)
|
||||
|
||||
type Story struct {
|
||||
Places []*Place `json:"places"`
|
||||
}
|
||||
|
||||
type Place struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Text string `json:"text"`
|
||||
Applications []*Application `json:"applications"`
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Graph struct {
|
||||
Nodes []*GraphNode
|
||||
Edges []*GraphEdge
|
||||
}
|
||||
|
||||
type GraphNode struct {
|
||||
ID int32
|
||||
Label string
|
||||
Name string
|
||||
Text string
|
||||
Applications []*GraphApplication
|
||||
}
|
||||
|
||||
type GraphEdge struct {
|
||||
From int32
|
||||
To int32
|
||||
}
|
||||
|
||||
type GraphApplication struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type StoryService struct {
|
||||
story *Story
|
||||
}
|
||||
@ -141,10 +86,13 @@ func (s *StoryService) GetGraph(ctx context.Context) *Graph {
|
||||
matches := re.FindAllString(place.Text, -1)
|
||||
|
||||
for _, match := range matches {
|
||||
edges = append(edges, &GraphEdge{
|
||||
From: m[clearCode(place.Code)],
|
||||
To: m[clearMatch(match)],
|
||||
})
|
||||
edges = append(
|
||||
edges,
|
||||
&GraphEdge{
|
||||
From: m[clearCode(place.Code)],
|
||||
To: m[clearMatch(match)],
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,21 +101,3 @@ func (s *StoryService) GetGraph(ctx context.Context) *Graph {
|
||||
Edges: edges,
|
||||
}
|
||||
}
|
||||
|
||||
func clearMatch(s string) string {
|
||||
s = strings.TrimPrefix(s, "(")
|
||||
s = strings.TrimPrefix(s, "[")
|
||||
s = strings.TrimSuffix(s, ")")
|
||||
s = strings.TrimSuffix(s, "]")
|
||||
return clearCode(s)
|
||||
}
|
||||
|
||||
func clearCode(code string) string {
|
||||
code = strings.ToLower(code)
|
||||
code = strings.TrimSpace(code)
|
||||
code = strings.ReplaceAll(code, "-", "")
|
||||
for latin, cyrillic := range replaceMap {
|
||||
code = strings.ReplaceAll(code, latin, cyrillic)
|
||||
}
|
||||
return code
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user