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

split words columns and use Chinese

上级 a12c1541
“秋天的天气”+(形容词-天气-秋季-好)、(形容词-天气-秋季-好),(形容词-外貌-女性)+(名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),“因为”+(名词-称呼=F)+(动词-及物_名词-意愿)+“带她去”+(名词-地点-名山)+(动词-及物_名词-动作-眼部-中性)+(形容词-颜色-植物-树木)+(名词-植物-树木)+(连词-并列关系)+(形容词-颜色-植物-花卉)+(名词-植物-花卉)。 难忘的秋游
(S:形容词-外貌-女性)+(S:名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),(副词-形容词做副词-情绪-快乐)+(动词-及物_名词-动作-手臂-亲切)+(形容词-性格-积极)+(S:名词-称呼=F)。 段落一:“秋天的天气”+(形容词-天气-秋季-好)、(形容词-天气-秋季-好),(形容词-外貌-女性)+(名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),“因为”+(名词-称呼=F)+(动词-及物_名词-意愿)+“带她去”+(名词-地点-名山)+(动词-及物_名词-动作-眼部-中性)+(形容词-颜色-植物-树木)+(名词-植物-树木)+(连词-并列关系)+(形容词-颜色-植物-花卉)+(名词-植物-花卉)。(S:形容词-外貌-女性)+(S:名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),(副词-形容词做副词-情绪-快乐)+(动词-及物_名词-动作-手臂-亲切)+(形容词-性格-积极)+(S:名词-称呼=F)。
\ No newline at end of file \ No newline at end of file
...@@ -29,7 +29,7 @@ func GenerateFieldValuesFromExcel(filePath, sheet string, field *model.DefField) ...@@ -29,7 +29,7 @@ func GenerateFieldValuesFromExcel(filePath, sheet string, field *model.DefField)
sheet = firstSheet sheet = firstSheet
} }
} else { // dir } else { // dir
ConvertExcelsToSQLiteIfNeeded(dbName, filePath) ConvertWordExcelsToSQLiteIfNeeded(dbName, filePath)
} }
list, selectCol := ReadDataFromSQLite(*field, dbName, sheet) list, selectCol := ReadDataFromSQLite(*field, dbName, sheet)
...@@ -166,7 +166,7 @@ func ConvertSingleExcelToSQLiteIfNeeded(dbName string, path string) (firstSheet ...@@ -166,7 +166,7 @@ func ConvertSingleExcelToSQLiteIfNeeded(dbName string, path string) (firstSheet
return return
} }
func ConvertExcelsToSQLiteIfNeeded(tableName string, dir string) { func ConvertWordExcelsToSQLiteIfNeeded(tableName string, dir string) {
if !isExcelChanged(dir) { if !isExcelChanged(dir) {
return return
} }
...@@ -175,8 +175,9 @@ func ConvertExcelsToSQLiteIfNeeded(tableName string, dir string) { ...@@ -175,8 +175,9 @@ func ConvertExcelsToSQLiteIfNeeded(tableName string, dir string) {
fileUtils.GetFilesByExtInDir(dir, ".xlsx", &files) fileUtils.GetFilesByExtInDir(dir, ".xlsx", &files)
seq := 1 seq := 1
ddlFields := make([]string, 0)
insertSqls := make([]string, 0) insertSqls := make([]string, 0)
ddlFields := make([]string, 0)
ddlFields = append(ddlFields, " `词语` VARCHAR DEFAULT ''")
colMap := map[string]bool{} colMap := map[string]bool{}
for _, file := range files { for _, file := range files {
...@@ -230,12 +231,18 @@ func ReadDataFromSQLite(field model.DefField, dbName string, tableName string) ( ...@@ -230,12 +231,18 @@ func ReadDataFromSQLite(field model.DefField, dbName string, tableName string) (
} }
selectCol := field.Select selectCol := field.Select
if vari.Def.Type == constant.ConfigTypeArticle {
selectCol = stringUtils.GetPinyin(selectCol)
}
from := dbName from := dbName
if tableName != "" { if tableName != "" {
from += "_" + tableName from += "_" + tableName
} }
where := field.Where where := field.Where
if vari.Def.Type == constant.ConfigTypeArticle {
where = stringUtils.GetPinyin(where)
}
if where == "" { if where == "" {
where = "1=1" where = "1=1"
} }
...@@ -431,7 +438,9 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[] ...@@ -431,7 +438,9 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
fileName := fileUtils.GetFileName(filePath) fileName := fileUtils.GetFileName(filePath)
fileName = strings.TrimSuffix(fileName, "词库") fileName = strings.TrimSuffix(fileName, "词库")
colPrefix := stringUtils.GetPinyin(fileName)
colPrefix := fileName // stringUtils.GetPinyin(fileName)
*ddlFields = append(*ddlFields, " `" + colPrefix + "` VARCHAR DEFAULT ''")
for rowIndex, sheet := range excel.GetSheetList() { for rowIndex, sheet := range excel.GetSheetList() {
rows, _ := excel.GetRows(sheet) rows, _ := excel.GetRows(sheet)
...@@ -441,6 +450,7 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[] ...@@ -441,6 +450,7 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
colDefine := "" colDefine := ""
colList := make([]string, 0) colList := make([]string, 0)
colList = append(colList, "`" + colPrefix + "`")
colCount := 0 colCount := 0
index := 0 index := 0
...@@ -451,19 +461,17 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[] ...@@ -451,19 +461,17 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
} }
colCount++ colCount++
colName := stringUtils.GetPinyin(val) colName := val // stringUtils.GetPinyin(val)
if colIndex == 0 && colName != "ci" {
colName = "ci"
}
if colName != "ci" {
colName = colPrefix + "_" + colName
}
if (*colMap)[colName] == false { if (*colMap)[colName] == false {
colType := "VARCHAR" colType := "VARCHAR"
colDefine = " " + "`" + colName + "` " + colType + " DEFAULT ''" colDefine = " " + "`" + colName + "` " + colType + " DEFAULT ''"
if colIndex == 0 {
colName = "词语"
} else { // first already added
*ddlFields = append(*ddlFields, colDefine) *ddlFields = append(*ddlFields, colDefine)
}
(*colMap)[colName] = true (*colMap)[colName] = true
} }
...@@ -480,6 +488,7 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[] ...@@ -480,6 +488,7 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
valListItem := make([]string, 0) valListItem := make([]string, 0)
valListItem = append(valListItem, strconv.Itoa(*seq)) valListItem = append(valListItem, strconv.Itoa(*seq))
valListItem = append(valListItem, "'y'")
*seq += 1 *seq += 1
for i := 0; i < colCount; i++ { for i := 0; i < colCount; i++ {
......
...@@ -36,12 +36,12 @@ func ConvertArticle(src, dist string) { ...@@ -36,12 +36,12 @@ func ConvertArticle(src, dist string) {
files = append(files, pth) files = append(files, pth)
if dist == "" { if dist == "" {
dist = path.Dir(pth) dist = fileUtils.AddSepIfNeeded(path.Dir(pth))
} }
} else { } else {
fileUtils.GetFilesInDir(src, ".txt", &files) fileUtils.GetFilesInDir(src, ".txt", &files)
if dist == "" { if dist == "" {
dist = src dist = fileUtils.AddSepIfNeeded(src)
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册