From 8cf21b5e6268a5e63eaac31b000ce14c3ce4220a Mon Sep 17 00:00:00 2001 From: lnd212 Date: Mon, 2 May 2022 02:48:35 +0400 Subject: [PATCH] read file and get soma basic info --- go.mod | 3 ++ main.go | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 go.mod create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1a7f706 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module morozovad.ddns.net/lnd212/go-xdfx2csv + +go 1.15 diff --git a/main.go b/main.go new file mode 100644 index 0000000..608b3c3 --- /dev/null +++ b/main.go @@ -0,0 +1,97 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strings" + "sync" + "time" +) + +var ( + full_name string + lang_from string + lang_to string +) + +const ( + FIRST_LINES = 5 +) + +func main() { + f, err := os.OpenFile("dict.xdxf", os.O_RDONLY, os.ModePerm) + if err != nil { + log.Fatalf("open file error: %v", err) + return + } + defer f.Close() + + fullFile(f) +} + +func fullFile(file *os.File) { + sc := bufio.NewScanner(file) + /*for sc.Scan() { + fmt.Println(sc.Text()) + }*/ + if err := sc.Err(); err != nil { + log.Fatalf("scan file error: %v", err) + return + } + + //skip first lines with some unnessesary data and save full name + first:="" + for sc.Scan() { + line := sc.Text() + if strings.Contains(line, "") { + line = strings.ReplaceAll(line, "full_name>", "") + line = strings.ReplaceAll(line, "") { + first= line + break + } + } + + fmt.Printf("Dict name: %s.\n", full_name) + fmt.Printf("From %s to %s. \n", lang_from, lang_to) + fmt.Println(first) + // read file line by line + var ( + word string + translation string + transcription string + ) + + for sc.Scan() { + line := sc.Text() + if strings.Contains(line, "") { + word = "" + translation = "" + transcription = "" + fmt.Println(word, translation, transcription) + } + if strings.Contains(line, "") { + _, word, _ = strings.Cut(line, "") + } + fmt.Println(sc.Text()) + } +} + +func processChunk(chunk []byte, linesPool *sync.Pool, stringPool *sync.Pool, start time.Time, end time.Time) { + +} + +//readFile opens file in chunks and process to other func. https://medium.com/swlh/processing-16gb-file-in-seconds-go-lang-3982c235dfa2 +func readFile() { + +}