Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
5dbb81ea
Z
zendata
项目概览
易企天创
/
zendata
8 个月 前同步成功
通知
17
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5dbb81ea
编写于
9月 16, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
generate yaml and article
上级
a7e6f725
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
109 addition
and
94 deletion
+109
-94
data/words/v1/形容词词库.xlsx
data/words/v1/形容词词库.xlsx
+0
-0
demo/article/article.txt
demo/article/article.txt
+1
-1
src/gen/definition.go
src/gen/definition.go
+1
-5
src/gen/excel.go
src/gen/excel.go
+88
-58
src/gen/res.go
src/gen/res.go
+2
-8
src/model/definition.go
src/model/definition.go
+1
-2
src/service/article.go
src/service/article.go
+16
-20
tmp/cache/.data.db
tmp/cache/.data.db
+0
-0
未找到文件。
data/words/v1/形容词词库.xlsx
浏览文件 @
5dbb81ea
无法预览此类型文件
demo/article/article.txt
浏览文件 @
5dbb81ea
难忘的秋游
段落一:“秋天的天气”+(形容词-天气-秋季-好)、(形容词-天气-秋季-好),(形容词-外貌-女性)+(名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),“因为”+(名词-称呼=F)+(动词-及物_名词-意愿)+“带她去”+(名词-地点-名山)+(动词-及物_名词-动作-眼部-中性)+(形容词-颜色-植物-树木)+(名词-植物-树木)+(连词-并列关系)+(形容词-颜色-植物-花卉)+(名词-植物-花卉)。(S:形容词-外貌-女性)+(S:名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),(副词-形容词做副词-情绪-快乐)+(动词-及物_名词-动作-手臂-亲切)+(形容词-性格-积极)+(S:名词-称呼=F)。
\ No newline at end of file
段落一:“秋天的天气”+(形容词-天气-秋季-好)、(形容词-天气-秋季-好),(形容词-外貌-女性)+(名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),“因为”+(名词-称呼=F)+(动词-及物_名词-意愿)+“带她去”+(名词-地点-名山)+(动词-及物_名词-动作-眼部-中性)+(形容词-颜色-植物-树木)+(名词-植物-树木)+(连词-并列关系)+(形容词-颜色-植物-花卉)+(名词-植物-花卉)。(S:形容词-外貌-女性)+(S:名词-姓+名词-名字=F)+(副词-程度副词)+(形容词做谓语-情绪-快乐),(副词-形容词做副词-情绪-快乐)+(动词-及物_名词-动作-手臂-亲切)+(形容词-性格-积极)+(S:名词-称呼=F)+ “结尾。”
\ No newline at end of file
src/gen/definition.go
浏览文件 @
5dbb81ea
...
...
@@ -59,15 +59,11 @@ func LoadConfigDef(defaultFile, configFile string, fieldsToExport *[]string) mod
mergerDefine
(
&
defaultDef
,
&
configDef
,
fieldsToExport
)
orderFields
(
&
defaultDef
,
*
fieldsToExport
)
for
index
,
field
:=
range
defaultDef
.
Fields
{
for
_
,
field
:=
range
defaultDef
.
Fields
{
if
vari
.
Trim
{
field
.
Prefix
=
""
field
.
Postfix
=
""
}
if
defaultDef
.
Type
==
constant
.
ConfigTypeArticle
{
defaultDef
.
Fields
[
index
]
.
Select
=
strings
.
Replace
(
field
.
Select
,
"-"
,
"_"
,
-
1
)
}
}
return
defaultDef
...
...
src/gen/excel.go
浏览文件 @
5dbb81ea
...
...
@@ -9,7 +9,6 @@ import (
fileUtils
"github.com/easysoft/zendata/src/utils/file"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
logUtils
"github.com/easysoft/zendata/src/utils/log"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"github.com/easysoft/zendata/src/utils/vari"
"log"
"os"
...
...
@@ -168,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
)
...
...
@@ -231,26 +230,35 @@ func ReadDataFromSQLite(field model.DefField, dbName string, tableName string) (
}
selectCol
:=
field
.
Select
if
vari
.
Def
.
Type
==
constant
.
ConfigTypeArticle
{
selectCol
=
stringUtils
.
GetPinyin
(
selectCol
)
}
from
:=
dbName
if
tableName
!=
""
{
from
+=
"_"
+
tableName
}
where
:=
field
.
Where
where
:=
strings
.
TrimSpace
(
field
.
Where
)
if
vari
.
Def
.
Type
==
constant
.
ConfigTypeArticle
{
where
=
stringUtils
.
GetPinyin
(
where
)
}
if
where
==
""
{
where
=
"1=1"
}
if
vari
.
Def
.
Type
==
constant
.
ConfigTypeArticle
&&
strings
.
ToLower
(
where
)
==
"true"
{
where
=
selectCol
+
" = 'y'"
}
if
where
==
""
{
where
=
"y"
}
cols
:=
strings
.
Split
(
selectCol
,
"-"
)
wheres
:=
""
for
index
,
col
:=
range
cols
{
if
index
==
0
{
wheres
+=
fmt
.
Sprintf
(
"`%s` = '%s'"
,
col
,
"y"
)
}
else
{
wheres
+=
" AND "
wheres
+=
fmt
.
Sprintf
(
"`%s` = '%s'"
,
col
,
where
)
}
}
where
=
wheres
where
=
strings
.
Replace
(
where
,
"-"
,
"_"
,
-
1
)
}
else
{
if
where
==
""
{
where
=
"1=1"
}
}
if
field
.
Rand
{
where
+=
" ORDER BY RANDOM() "
...
...
@@ -266,7 +274,7 @@ func ReadDataFromSQLite(field model.DefField, dbName string, tableName string) (
colStr
:=
selectCol
if
vari
.
Def
.
Type
==
constant
.
ConfigTypeArticle
{
colStr
=
"
ci AS "
+
selectCol
colStr
=
"
`词语` AS `"
+
selectCol
+
"`"
}
sqlStr
:=
fmt
.
Sprintf
(
"SELECT %s FROM %s WHERE %s"
,
colStr
,
from
,
where
)
...
...
@@ -317,10 +325,6 @@ func ReadDataFromSQLite(field model.DefField, dbName string, tableName string) (
}
}
if
field
.
Select
==
"xingrongci_waimao_nvxing"
{
log
.
Println
(
field
.
Select
)
}
return
list
,
selectCol
}
...
...
@@ -442,7 +446,7 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
colPrefix
:=
fileName
// stringUtils.GetPinyin(fileName)
*
ddlFields
=
append
(
*
ddlFields
,
" `"
+
colPrefix
+
"` VARCHAR DEFAULT ''"
)
for
row
Index
,
sheet
:=
range
excel
.
GetSheetList
()
{
for
sheet
Index
,
sheet
:=
range
excel
.
GetSheetList
()
{
rows
,
_
:=
excel
.
GetRows
(
sheet
)
if
len
(
rows
)
==
0
{
continue
...
...
@@ -450,69 +454,95 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
colDefine
:=
""
colList
:=
make
([]
string
,
0
)
colList
=
append
(
colList
,
"`"
+
colPrefix
+
"`"
)
colCount
:=
0
index
:=
0
// gen col list for ddl and insert cols
for
colIndex
,
col
:=
range
rows
[
0
]
{
val
:=
strings
.
TrimSpace
(
col
)
if
rowIndex
==
0
&&
val
==
""
{
if
sheetIndex
==
0
&&
val
==
""
{
break
}
colCount
++
col
Name
:=
val
// stringUtils.GetPinyin(
val)
col
List
=
append
(
colList
,
val
)
if
(
*
colMap
)[
colName
]
==
false
{
colType
:=
"VARCHAR"
colDefine
=
" "
+
"`"
+
colName
+
"` "
+
colType
+
" DEFAULT ''"
colNames
:=
val
colNameArr
:=
strings
.
Split
(
colNames
,
"-"
)
for
_
,
colName
:=
range
colNameArr
{
if
(
*
colMap
)[
colName
]
==
false
{
colType
:=
"VARCHAR"
colDefine
=
" "
+
"`"
+
colName
+
"` "
+
colType
+
" DEFAULT ''"
if
colIndex
==
0
{
colName
=
"词语"
}
else
{
// first already added
*
ddlFields
=
append
(
*
ddlFields
,
colDefine
)
}
if
colIndex
==
0
{
colName
=
"词语"
}
else
{
// first already added
*
ddlFields
=
append
(
*
ddlFields
,
colDefine
)
}
(
*
colMap
)[
colName
]
=
true
(
*
colMap
)[
colName
]
=
true
}
}
colList
=
append
(
colList
,
"`"
+
colName
+
"`"
)
index
++
}
valList
:=
make
([]
string
,
0
)
insertTemplate
:=
"INSERT INTO `"
+
tableName
+
"` (%s) VALUES (%s);"
// gen values for insert
for
rowIndex
,
row
:=
range
rows
{
if
rowIndex
==
0
{
if
rowIndex
==
0
{
// ignore title line
continue
}
valListItem
:=
make
([]
string
,
0
)
valListItem
=
append
(
valListItem
,
strconv
.
Itoa
(
*
seq
))
valListItem
=
append
(
valListItem
,
"'y'"
)
record
:=
map
[
string
]
interface
{}{}
record
[
colPrefix
]
=
"y"
record
[
"seq"
]
=
*
seq
*
seq
+=
1
for
i
:=
0
;
i
<
colCount
;
i
++
{
val
:=
""
if
i
==
0
{
// word
val
=
strings
.
TrimSpace
(
row
[
i
])
}
else
if
i
<=
len
(
row
)
-
1
{
// excel value
val
=
strings
.
ToLower
(
strings
.
TrimSpace
(
row
[
i
]))
if
val
!=
"y"
&&
val
!=
"b"
&&
val
!=
"f"
&&
val
!=
"m"
{
val
=
""
}
for
colIndex
,
col
:=
range
row
{
if
colIndex
>=
len
(
colList
)
{
break
}
colNames
:=
colList
[
colIndex
]
val
:=
strings
.
ToLower
(
strings
.
TrimSpace
(
col
))
if
val
==
""
{
continue
}
if
colIndex
==
0
{
// word
record
[
"词语"
]
=
val
}
else
{
val
=
""
if
val
!=
"y"
&&
val
!=
"b"
&&
val
!=
"f"
&&
val
!=
"m"
{
val
=
""
}
colNameArr
:=
strings
.
Split
(
colNames
,
"-"
)
for
_
,
colName
:=
range
colNameArr
{
record
[
colName
]
=
val
}
}
valListItem
=
append
(
valListItem
,
"'"
+
val
+
"'"
)
}
valList
=
append
(
valList
,
"("
+
strings
.
Join
(
valListItem
,
", "
)
+
")"
)
}
insertTemplate
:=
"INSERT INTO `"
+
tableName
+
"` (`seq`, %s) VALUES %s;"
insertSql
:=
fmt
.
Sprintf
(
insertTemplate
,
strings
.
Join
(
colList
,
", "
),
strings
.
Join
(
valList
,
", "
),
)
*
insertSqls
=
append
(
*
insertSqls
,
insertSql
)
cols
:=
make
([]
string
,
0
)
vals
:=
make
([]
string
,
0
)
for
key
,
val
:=
range
record
{
cols
=
append
(
cols
,
"`"
+
key
+
"`"
)
valStr
:=
""
switch
val
.
(
type
)
{
case
int
:
valStr
=
strconv
.
Itoa
(
val
.
(
int
))
default
:
valStr
=
"'"
+
val
.
(
string
)
+
"'"
}
vals
=
append
(
vals
,
valStr
)
}
insertSql
:=
fmt
.
Sprintf
(
insertTemplate
,
strings
.
Join
(
cols
,
","
),
strings
.
Join
(
vals
,
","
))
*
insertSqls
=
append
(
*
insertSqls
,
insertSql
)
}
}
}
\ No newline at end of file
src/gen/res.go
浏览文件 @
5dbb81ea
...
...
@@ -48,14 +48,8 @@ func loadResField(field *model.DefField, res *map[string]map[string][]string) {
}
}
else
if
field
.
From
!=
""
{
// refer to res
var
valueMap
map
[
string
][]
string
if
vari
.
Def
.
Type
==
constant
.
ConfigTypeArticle
&&
field
.
UseLastSameValue
{
// use last
valueMap
=
getLastDuplicateVal
((
*
res
)[
field
.
From
],
field
.
Select
)
}
if
valueMap
==
nil
{
resFile
,
resType
,
sheet
:=
fileUtils
.
GetResProp
(
field
.
From
)
valueMap
,
_
=
getResValue
(
resFile
,
resType
,
sheet
,
field
)
}
resFile
,
resType
,
sheet
:=
fileUtils
.
GetResProp
(
field
.
From
)
valueMap
,
_
=
getResValue
(
resFile
,
resType
,
sheet
,
field
)
if
(
*
res
)[
field
.
From
]
==
nil
{
(
*
res
)[
field
.
From
]
=
map
[
string
][]
string
{}
...
...
src/model/definition.go
浏览文件 @
5dbb81ea
...
...
@@ -85,7 +85,6 @@ type FieldSimple struct {
LoopIndex
int
`yaml:"-"`
IsRand
bool
`yaml:"-"`
IsReferYaml
bool
`yaml:"-"`
UseLastSameValue
bool
`yaml:"useLastSameValue"`
}
type
FieldWithValues
struct
{
...
...
@@ -124,5 +123,5 @@ type DefFieldExport struct {
Where
string
`yaml:"where"`
Rand
bool
`yaml:"rand"`
Limit
int
`yaml:"limit"`
UseLastSameValue
bool
`yaml:"useLastSameValu
e"`
Range
string
`yaml:"rang
e"`
}
\ No newline at end of file
src/service/article.go
浏览文件 @
5dbb81ea
package
service
import
(
"fmt"
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
_
"github.com/mattn/go-sqlite3"
"gopkg.in/yaml.v3"
"path"
...
...
@@ -22,8 +20,6 @@ const (
expRight
=
")"
table
=
"words.v1"
//src = "data/words"
//dist = "demo"
)
var
(
compares
=
[]
string
{
"="
,
"!="
,
">"
,
"<"
}
...
...
@@ -71,6 +67,13 @@ func convertToYaml(article, filePath string) (content string) {
prefix
=
""
}
else
{
prefix
+=
val
if
prefix
!=
""
&&
index
==
len
(
sections
)
-
1
{
field
:=
model
.
DefFieldExport
{}
field
.
Range
=
prefix
conf
.
XFields
=
append
(
conf
.
XFields
,
field
)
}
}
}
...
...
@@ -111,37 +114,26 @@ func createFields(index int, prefix, exp string) (fields []model.DefFieldExport)
if
string
(
expArr
[
0
])
==
"s"
&&
(
string
(
expArr
[
1
])
==
":"
||
string
(
expArr
[
1
])
==
":"
)
{
exp
=
string
(
expArr
[
2
:
])
expArr
=
expArr
[
2
:
]
field
.
UseLastSameValue
=
true
}
if
strings
.
Index
(
exp
,
"="
)
==
len
(
exp
)
-
2
{
exp
=
string
(
expArr
[
:
len
(
expArr
)
-
2
])
field
.
Select
=
stringUtils
.
GetPinyin
(
exp
)
field
.
Where
=
fmt
.
Sprintf
(
"%s = '%s'"
,
field
.
Select
,
string
(
expArr
[
len
(
expArr
)
-
1
])
)
field
.
Select
=
exp
field
.
Where
=
string
(
expArr
[
len
(
expArr
)
-
1
]
)
}
else
{
field
.
Select
=
stringUtils
.
GetPinyin
(
exp
)
field
.
Where
=
"true"
//field.Where = getPinyin(exp) + " = 'y'"
field
.
Select
=
exp
field
.
Where
=
""
}
if
strings
.
Index
(
field
.
Select
,
"+"
)
<
0
{
fields
=
append
(
fields
,
field
)
}
else
if
strings
.
Index
(
field
.
Select
,
"+"
)
>
0
{
// include more than one field, split to two
arr
:=
strings
.
Split
(
field
.
Where
,
"="
)
right
:=
""
if
len
(
arr
)
>
1
{
right
=
arr
[
1
]
}
items
:=
strings
.
Split
(
field
.
Select
,
"+"
)
for
_
,
item
:=
range
items
{
var
objClone
interface
{}
=
field
fieldClone
:=
objClone
.
(
model
.
DefFieldExport
)
fieldClone
.
Select
=
item
if
len
(
arr
)
>
1
{
// has conditions
fieldClone
.
Where
=
item
+
" = "
+
right
}
fieldClone
.
Where
=
field
.
Where
fields
=
append
(
fields
,
fieldClone
)
}
...
...
@@ -193,6 +185,10 @@ func parseSections(content string) (sections []map[string]string) {
}
else
{
section
+=
str
}
//if i == len(runeArr) - 1 && len(section) > 0 {
// addSection(section, "str", §ions)
//}
}
return
...
...
tmp/cache/.data.db
浏览文件 @
5dbb81ea
无法预览此类型文件
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录