提交 27d74ce0 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

split by full stop and new line

上级 5dbb81ea
难忘的秋游
段落一:“秋天的天气”+(形容词-天气-秋季-好)、(形容词-天气-秋季-好),(形容词-外貌-女性)+(名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),“因为”+(名词-称呼=F)+(动词-及物_名词-意愿)+“带她去”+(名词-地点-名山)+(动词-及物_名词-动作-眼部-中性)+(形容词-颜色-植物-树木)+(名词-植物-树木)+(连词-并列关系)+(形容词-颜色-植物-花卉)+(名词-植物-花卉)。(S:形容词-外貌-女性)+(S:名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),(副词-形容词做副词-情绪-快乐)+(动词-及物_名词-动作-手臂-亲切)+(形容词-性格-积极)+(S:名词-称呼=F)+ “结尾。”
\ No newline at end of file
段落一:(S:名词-称呼=F)+ “结尾。”
段落二:“第二段内容”
\ No newline at end of file
......@@ -167,7 +167,7 @@ func ConvertSingleExcelToSQLiteIfNeeded(dbName string, path string) (firstSheet
func ConvertWordExcelsToSQLiteIfNeeded(tableName string, dir string) {
if !isExcelChanged(dir) {
//return
return
}
files := make([]string, 0)
......
......@@ -32,6 +32,11 @@ func CreateListFieldValues(field *model.DefField, fieldValue *model.FieldWithVal
func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWithValues) {
rang := field.Range
if rang == "" {
fieldValue.Values = append(fieldValue.Values, "")
return
}
rangeSections := ParseRangeProperty(rang) // 1
index := 0
......
......@@ -53,6 +53,12 @@ func ParseRangeProperty(rang string) []string {
func ParseDesc(desc string) (items []string) {
desc = strings.TrimSpace(desc)
desc = strings.Trim(desc, ",")
if desc == "" {
items = append(items, desc)
return
}
runeArr := []rune(desc)
if runeArr[0] == constant.Backtick && runeArr[len(runeArr) - 1] == constant.Backtick { // `xxx`
......@@ -78,6 +84,12 @@ func ParseDesc(desc string) (items []string) {
*/
func ParseRangeSection(item string) (entry string, step string, repeat int) {
item = strings.TrimSpace(item)
if item == "" {
repeat = 1
return
}
runeArr := []rune(item)
if (runeArr[0] == constant.Backtick && runeArr[len(runeArr) - 1] == constant.Backtick) || // `xxx`
(string(item[0]) == string(constant.LeftBrackets) && // (xxx)
......@@ -115,6 +127,11 @@ func ParseRangeSection(item string) (entry string, step string, repeat int) {
func ParseRangeSectionDesc(str string) (typ string, desc string) {
desc = strings.TrimSpace(str)
if desc == "" {
typ = "literal"
return
}
if stringUtils.EndWith(desc, ".yaml") { // refer to another yaml file
typ = "yaml"
return
......
......@@ -123,5 +123,4 @@ type DefFieldExport struct {
Where string `yaml:"where"`
Rand bool `yaml:"rand"`
Limit int `yaml:"limit"`
Range string `yaml:"range"`
}
\ No newline at end of file
......@@ -51,7 +51,7 @@ func ConvertArticle(src, dist string) {
}
func convertToYaml(article, filePath string) (content string) {
sections := parseSections(article)
sections, _ := parseSections(article)
conf := createDef(constant.ConfigTypeArticle, table, filePath)
......@@ -59,6 +59,8 @@ func convertToYaml(article, filePath string) (content string) {
for index, section := range sections {
tye := section["type"]
val := section["val"]
parag := section["parag"]
sent := section["sent"]
if tye == "exp" {
fields := createFields(index, prefix, val)
......@@ -68,11 +70,18 @@ func convertToYaml(article, filePath string) (content string) {
} else {
prefix += val
if prefix != "" && index == len(sections) - 1 {
field := model.DefFieldExport{}
field.Range = prefix
if parag == "true" {
field := model.DefFieldExport{Field: strconv.Itoa(index), Prefix: prefix}
conf.XFields = append(conf.XFields, field)
prefix = ""
} else if sent == "true" {
field := model.DefFieldExport{Field: strconv.Itoa(index), Prefix: prefix}
conf.XFields = append(conf.XFields, field)
prefix = ""
} else if prefix != "" && index == len(sections) - 1 { // last section
field := model.DefFieldExport{Field: strconv.Itoa(index), Prefix: prefix}
conf.XFields = append(conf.XFields, field)
prefix = ""
}
}
}
......@@ -142,13 +151,16 @@ func createFields(index int, prefix, exp string) (fields []model.DefFieldExport)
return
}
func parseSections(content string) (sections []map[string]string) {
func parseSections(content string) (sections []map[string]string, division [][]int) {
strStart := false
expStart := false
content = strings.TrimSpace(content)
runeArr := []rune(content)
//parag := 0
//sent := 0
section := ""
for i := 0; i < len(runeArr); i++ {
item := runeArr[i]
......@@ -158,6 +170,11 @@ func parseSections(content string) (sections []map[string]string) {
if isCouple {
section += duplicateStr
i += 1
if i == len(runeArr) - 1 {
addSection(section, "str", &sections)
}
} else if strStart && str == strRight { // str close
addSection(section, "str", &sections)
......@@ -184,11 +201,37 @@ func parseSections(content string) (sections []map[string]string) {
section = ""
} else {
section += str
}
//if i == len(runeArr) - 1 && len(section) > 0 {
// addSection(section, "str", &sections)
//}
if str == "。" {
if i < len(runeArr) && string(runeArr[i+1]) == strRight {
i += 1
}
addSection(section, "str", &sections)
strStart = false
expStart = false
section = ""
} else if str == "\n" {
// get all \n
for j := i+1; j < len(runeArr); j++ {
if string(runeArr[j]) == "\n" {
section += str
i = j
} else {
break
}
}
addSection(section, "str", &sections)
strStart = false
expStart = false
section = ""
} else if i == len(runeArr) - 1 {
addSection(section, "str", &sections)
}
}
}
return
......@@ -199,6 +242,14 @@ func addSection(str, typ string, arr *[]map[string]string) {
mp["type"] = typ
mp["val"] = str
runeArr := []rune(str)
end := runeArr[len(runeArr) - 1]
if string(end) == "\n" {
mp["parag"] = "true"
} else if string(end) == "。" {
mp["sent"] = "true"
}
*arr = append(*arr, mp)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册