-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathword.go
More file actions
124 lines (117 loc) · 3.66 KB
/
word.go
File metadata and controls
124 lines (117 loc) · 3.66 KB
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
// This file is part of Fwew.
// Fwew is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Fwew is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Fwew. If not, see http://gnu.org/licenses/
// Package main contains all the things. word.go is home to the Word struct.
package main
import "fmt"
// Word is a struct that contains all the data about a given word
type Word struct {
ID string
LangCode string
Navi string
Target string
Attempt string
IPA string
InfixLocations string
PartOfSpeech string
Definition string
Source string
Stressed string
Syllables string
InfixDots string
Affixes map[string][]string
}
func (w Word) String() string {
// this string only doesn't get translated or called from Text() because they're var names
return fmt.Sprintf(""+
"Id: %s\n"+
"LangCode: %s\n"+
"Navi: %s\n"+
"Target: %s\n"+
"Attempt: %s\n"+
"IPA: %s\n"+
"InfixLocations: %s\n"+
"PartOfSpeech: %s\n"+
"Definition: %s\n"+
"Source: %s\n"+
"Stressed: %s\n"+
"Syllables: %s\n"+
"InfixDots: %s\n"+
"Affixes: %v\n",
w.ID,
w.LangCode,
w.Navi,
w.Target,
w.Attempt,
w.IPA,
w.InfixLocations,
w.PartOfSpeech,
w.Definition,
w.Source,
w.Stressed,
w.Syllables,
w.InfixDots,
w.Affixes)
}
// InitWordStruct is basically a constructor for Word struct
func InitWordStruct(w Word, dataFields []string) Word {
//const (
// idField int = 0 // dictionary.txt line Field 0 is Database ID
// lcField int = 1 // dictionary.txt line field 1 is Language Code
// navField int = 2 // dictionary.txt line field 2 is Na'vi word
// ipaField int = 3 // dictionary.txt line field 3 is IPA data
// infField int = 4 // dictionary.txt line field 4 is Infix location data
// posField int = 5 // dictionary.txt line field 5 is Part of Speech data
// defField int = 6 // dictionary.txt line field 6 is Local definition
// srcField int = 7 // dictionary.txt line field 7 is Source data
// stsField int = 8 // dictionary.txt line field 8 is Stressed syllable #
// sylField int = 9 // dictionary.txt line field 9 is syllable breakdown
// ifdField int = 10 // dictionary.txt line field 10 is dot-style infix data
//)
w.ID = dataFields[idField]
w.LangCode = dataFields[lcField]
w.Navi = dataFields[navField]
w.IPA = dataFields[ipaField]
w.InfixLocations = dataFields[infField]
w.PartOfSpeech = dataFields[posField]
w.Definition = dataFields[defField]
w.Source = dataFields[srcField]
w.Stressed = dataFields[stsField]
w.Syllables = dataFields[sylField]
w.InfixDots = dataFields[ifdField]
w.Affixes = map[string][]string{}
return w
}
// CloneWordStruct is basically a copy constructor for Word struct
func CloneWordStruct(w Word) Word {
var nw Word
nw.ID = w.ID
nw.LangCode = w.LangCode
nw.Navi = w.Navi
nw.Target = w.Target
nw.Attempt = w.Attempt
nw.IPA = w.IPA
nw.InfixLocations = w.InfixLocations
nw.PartOfSpeech = w.PartOfSpeech
nw.Definition = w.Definition
nw.Source = w.Source
nw.Stressed = w.Stressed
nw.Syllables = w.Syllables
nw.InfixDots = w.InfixDots
nw.Affixes = make(map[string][]string)
for k := range w.Affixes {
nw.Affixes[k] = make([]string, len(w.Affixes[k]))
copy(nw.Affixes[k], w.Affixes[k])
}
return nw
}