article.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package util
  2. import (
  3. "regexp"
  4. )
  5. //
  6. type Job struct {
  7. SourceMid string //数据源的MongoId
  8. Category string //类别
  9. CategorySecond string //二级分类
  10. Content string //正文
  11. Title string //标题
  12. SpiderCode string //爬虫代码
  13. Domain string //网站域名
  14. Href string //原文链接
  15. City string //城市
  16. Province string //省份
  17. Data *map[string]interface{} //数据库源数据
  18. Block []*Block //分块
  19. Result map[string][]*ExtField //结果
  20. BuyerAddr string //采购单位地址
  21. BlockPackage map[string]*BlockPackage //块中的分包
  22. Winnerorder []map[string]interface{} //中标候选人排序
  23. PackageInfo map[string]map[string]interface{} //分包信息
  24. RuleBlock *RuleBlock //分块规则
  25. BrandData [][]map[string]string //
  26. HasTable int //有table
  27. HasKey int //是否匹配到table中的标题
  28. HasBrand int //有品牌
  29. HasGoods int //有商品
  30. IsFile bool //有附件
  31. }
  32. type ExtField struct {
  33. Field string //属性
  34. Code string //匹配标签(字符串、正则)、正则或lua代码
  35. RuleText string //内容
  36. Type string //kv(细类:colon1,colon2,space,table)、正则(regexp)
  37. MatchType string //匹配类型:1:标签库类型(tag_string,tag_regexp),2:全文正则regcontent
  38. ExtFrom string //抽取来源(title,detail)
  39. Value interface{} //抽取结果
  40. Score int //得分
  41. }
  42. //分块规则
  43. type RuleBlock struct {
  44. BlockRegs []*regexp.Regexp
  45. TitleRegs []*regexp.Regexp
  46. }
  47. //块
  48. type Block struct {
  49. Tags []Tags //对块做的标签,可以作为数据抽取的依据
  50. Title string //块标题
  51. Index int //块索引
  52. Text string //块内容
  53. Start int //开始索引
  54. End int //结束索引
  55. ColonKV *JobKv //冒号kv (分出的对应的KV值)
  56. TableKV *JobKv //table kv (分出的对应的KV值)
  57. SpaceKV *JobKv //空格 kv (分出的对应的KV值)
  58. BPackage *BlockPackage //分包信息
  59. Tag map[string]bool //块标签
  60. Block []*Block //子块
  61. }
  62. //段落
  63. type Segment struct {
  64. Index int //段落索引
  65. Text string //段落内容
  66. }
  67. //包
  68. type BlockPackage struct {
  69. Index string //序号 (转换后编号,只有数字或字母)
  70. Origin string //包的原始值
  71. Type string //类型 (匹配后面的标段、包之类的词)
  72. Text string //包文 (包对应的正文)
  73. ColonKV *JobKv //冒号kv (分出的对应的KV值)
  74. TableKV *JobKv //table kv (分出的对应的KV值)
  75. SpaceKV *JobKv //空格 kv (分出的对应的KV值)
  76. BidStatus string //成交状态
  77. WinnerOrder []map[string]interface{} //中标人排序
  78. Accuracy bool //包里面抽取字段的准确性,如果能打上块标签的话,就不用中标候选人中的值覆盖包里面的值
  79. }
  80. //联系人
  81. type ContactFormat struct {
  82. Direction int
  83. IndexMap map[int]string
  84. MatchMap map[string]map[string]bool
  85. WeightMap map[string]map[string]interface{}
  86. }
  87. //kv
  88. type Kv struct {
  89. Key string
  90. Value string
  91. Line string
  92. PrevLine string
  93. NextLine string
  94. Title string
  95. }
  96. //最终放到job上的kv
  97. type JobKv struct {
  98. Kvs []*Kv //有序的冒号kv
  99. Kvs_2 []*Kv //有序的冒号kv
  100. Kv map[string]string //table kv (分出的对应的KV值)
  101. KvIndex map[string]int //kv_index(流程)
  102. KvTag map[string]*Tag //带权重的kv
  103. }
  104. func NewJobKv() *JobKv {
  105. return &JobKv{
  106. Kvs: []*Kv{},
  107. Kvs_2: []*Kv{},
  108. Kv: map[string]string{},
  109. KvTag: map[string]*Tag{},
  110. }
  111. }