Skip to content

Commit ad7ebec

Browse files
committed
use regex to create cypher friendly variables from filenames
1 parent c2858dc commit ad7ebec

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

code2cypher.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"strconv"
1111
"os/exec"
12+
"regexp"
1213
)
1314

1415
type node struct {
@@ -42,6 +43,8 @@ func main() {
4243
verbose := flag.Bool("verbose", false, "log iteration through file tree")
4344
flag.Parse()
4445

46+
reStr := regexp.MustCompile(`\W`)
47+
4548
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
4649
if err != nil {
4750
return err
@@ -79,7 +82,7 @@ func main() {
7982
pre := "a_"
8083
id := strings.Replace(element, ".", "_", -1)
8184
id = pre + id
82-
id = strings.Replace(id, "-", "_", -1)
85+
id = reStr.ReplaceAllString(id, "$1")
8386
id += strconv.Itoa(i)
8487
if (info.IsDir() == false) {
8588
groups := strings.Split(element, ".")
@@ -92,7 +95,7 @@ func main() {
9295

9396
ParentId := strings.Replace(pathSegments[parentIndex], ".", "_", -1)
9497
ParentId = pre + ParentId
95-
ParentId = strings.Replace(ParentId, "-", "_", -1)
98+
ParentId = reStr.ReplaceAllString(ParentId, "$1")
9699
ParentId += strconv.Itoa(parentIndex)
97100

98101
if (ext != "DS_Store") {
@@ -150,6 +153,7 @@ func main() {
150153
for _, c := range currentFile.Contributers {
151154
if (len(c) > 3) {
152155
contributerId := "c_" + strings.Replace(c, " ", "", -1)
156+
contributerId = reStr.ReplaceAllString(contributerId, "$1")
153157
if (!Contains(processedContributers, c)) {
154158
fmt.Println("CREATE (" + contributerId + ":" + "person" + " { name: '" + c + "' })")
155159
processedContributers = append(processedContributers, c)

0 commit comments

Comments
 (0)