|
@@ -14,8 +14,9 @@ from bs4 import BeautifulSoup
|
|
|
import copy
|
|
|
|
|
|
end_pattern = "商务要求|评分标准|商务条件|商务条件"
|
|
|
-_param_pattern = "(产品|技术|清单|配置|参数|具体|明细|项目|招标|货物|服务|规格|工作|具体)[及和与]?(指标|配置|条件|要求|参数|需求|规格|名称及要求)|配置清单|(质量|技术).{,10}要求|验收标准|^(参数|功能)$"
|
|
|
-meter_pattern = "\d+([毫μ千]?[升L]|摄氏度|kg|mm|um|cm|mol|Mpa|Hz|℃|W|min)|角度|容积|色彩|帧率|磁场|强度|允差|噪音|材质|频率|阻抗|浓度|范围|误差|精确|温度|可调|设定值|功能|检测|高度|宽度|模式|尺寸|重量|峰值|容量|寿命|稳定性|高温|电源|电压|功率|压力|压强"
|
|
|
+_param_pattern = "(产品|技术|清单|配置|参数|具体|明细|项目|招标|货物|服务|规格|工作|具体)[及和与]?(指标|配置|条件|要求|参数|需求|规格|条款|名称及要求)|配置清单|(质量|技术).{,10}要求|验收标准|^(参数|功能)$"
|
|
|
+meter_pattern = "[><≤≥±]\d+|\d+(?:[μucmkK微毫千]?[米升LlgGmMΩ]|摄氏度|英寸|度|天|VA|dB|bpm|rpm|kPa|mol|cmH20|%|°|Mpa|Hz|K?HZ|℃|W|min|[*×xX])|[*×xX]\d+|/min|\ds[^a-zA-Z]|GB.{,20}标准|PVC|PP|角度|容积|色彩|自动|流量|外径|轴位|折射率|帧率|柱镜|振幅|磁场|镜片|防漏|强度|允差|心率|倍数|瞳距|底座|色泽|噪音|间距|材质|材料|表面|频率|阻抗|浓度|兼容|防尘|防水|内径|实时|一次性|误差|性能|距离|精确|温度|超温|范围|跟踪|对比度|亮度|[横纵]向|均压|负压|正压|可调|设定值|功能|检测|高度|厚度|宽度|深度|[单双多]通道|效果|指数|模式|尺寸|重量|峰值|谷值|容量|寿命|稳定性|高温|信号|电源|电流|转换率|效率|释放量|转速|离心力|向心力|弯曲|电压|功率|气量|国标|标准协议|灵敏度|最大值|最小值|耐磨|波形|高压|性强|工艺|光源|低压|压力|压强|速度|湿度|重量|毛重|[MLX大中小]+码|净重|颜色|[红橙黄绿青蓝紫]色|不锈钢|输入|输出|噪声|认证|配置"
|
|
|
+not_meter_pattern = "投标报价|中标金额|商务部分|公章|分值构成|业绩|详见|联系人|联系电话|合同价|金额|采购预算|资金来源|费用|质疑|评审因素|评审标准|商务资信|商务评分|专家论证意见|评标方法|代理服务费|售后服务|评分类型|评分项目|预算金额|得\d+分|项目金额|详见招标文件|乙方"
|
|
|
|
|
|
|
|
|
def getTrs(tbody):
|
|
@@ -696,7 +697,6 @@ def extract_products(list_data,_product,_param_pattern = "产品名称|设备材
|
|
|
if re.search("^\d+$",cell_text) is not None:
|
|
|
has_number = True
|
|
|
|
|
|
-
|
|
|
if cell_i>=len(line):
|
|
|
continue
|
|
|
cell = line[cell_i]
|
|
@@ -707,7 +707,7 @@ def extract_products(list_data,_product,_param_pattern = "产品名称|设备材
|
|
|
|
|
|
if len(table_products)>0:
|
|
|
logger.debug("table products %s"%(str(table_products)))
|
|
|
- if min([len(x) for x in table_products])>0 and max([len(x) for x in table_products])<=20:
|
|
|
+ if min([len(x) for x in table_products])>0 and max([len(x) for x in table_products])<=30:
|
|
|
if re.search("招标人|代理人|预算|数量|交货期|品牌|产地","".join(table_products)) is None:
|
|
|
list_table_products.append(table_products)
|
|
|
_find = False
|
|
@@ -715,12 +715,13 @@ def extract_products(list_data,_product,_param_pattern = "产品名称|设备材
|
|
|
for _p in table_products:
|
|
|
if is_similar(_product,_p,90):
|
|
|
_find = True
|
|
|
- list_result = list(set([a for a in table_products if len(a)>1 and len(a)<20 and re.search("费用|预算|合计|金额|万元|运费",a) is None]))
|
|
|
+ logger.debug("similar table_products %s"%(str(table_products)))
|
|
|
+ list_result = list(set([a for a in table_products if len(a)>1 and len(a)<20 and re.search("费用|预算|合计|金额|万元|运费|^其他$",a) is None]))
|
|
|
break
|
|
|
if not _find:
|
|
|
for table_products in list_table_products:
|
|
|
list_result.extend(table_products)
|
|
|
- list_result = list(set([a for a in list_result if len(a)>1 and len(a)<20 and re.search("费用|预算|合计|金额|万元|运费",a) is None]))
|
|
|
+ list_result = list(set([a for a in list_result if len(a)>1 and len(a)<30 and re.search("费用|预算|合计|金额|万元|运费",a) is None]))
|
|
|
return list_result
|
|
|
|
|
|
|
|
@@ -767,12 +768,20 @@ def get_correct_product(product,products):
|
|
|
def get_childs_text(childs,_product,products,is_begin=False,is_end=False):
|
|
|
_text = ""
|
|
|
|
|
|
+ end_next = False
|
|
|
for _child in childs:
|
|
|
|
|
|
child_text = _child.get("text")
|
|
|
|
|
|
+
|
|
|
if child_text.find(_product)>=0:
|
|
|
- is_begin = True
|
|
|
+ if not is_begin:
|
|
|
+ is_begin = True
|
|
|
+ if not end_next:
|
|
|
+ if _child["sentence_title"] is not None and isinstance(_child["title_next"],dict) and _child["title_next"]["sentence_title"] is not None:
|
|
|
+ end_next = True
|
|
|
+ end_title = _child["title_next"]
|
|
|
+ logger.debug("end_title %s "%end_title["text"])
|
|
|
|
|
|
logger.debug("%s-%s-%s"%("get_childs_text",child_text[:10],str(is_begin)))
|
|
|
|
|
@@ -797,31 +806,43 @@ def get_childs_text(childs,_product,products,is_begin=False,is_end=False):
|
|
|
_text += _child.get("text")+"\r\n"
|
|
|
childs2 = _child.get("child_title",[])
|
|
|
|
|
|
+
|
|
|
if len(childs2)>0:
|
|
|
for _child2 in childs2:
|
|
|
child_text,is_begin,is_end = get_childs_text([_child2],_product,products,is_begin)
|
|
|
- if is_begin and is_end:
|
|
|
- break
|
|
|
- else:
|
|
|
- if is_begin:
|
|
|
- _text += child_text
|
|
|
+ if is_begin:
|
|
|
+ _text += child_text
|
|
|
+ if is_end:
|
|
|
+ break
|
|
|
+
|
|
|
+ if end_next:
|
|
|
+ is_end = True
|
|
|
+
|
|
|
+ # logger.debug("%s-%s-%s"%("get_childs_text1",_text,str(is_begin)))
|
|
|
+ # logger.debug("%s-%s-%s"%("get_childs_text2",_text,str(is_begin)))
|
|
|
return _text,is_begin,is_end
|
|
|
|
|
|
def extract_parameters_by_tree(_product,products,list_data,_data_i,parent_title,list_result,):
|
|
|
_data = list_data[_data_i]
|
|
|
childs = _data.get("child_title",[])
|
|
|
if len(childs)>0:
|
|
|
- child_text,_,_ = get_childs_text([parent_title],_product,products)
|
|
|
- logger.info("extract_parameters_by_tree child_text:%s"%child_text)
|
|
|
+ child_text,_,_ = get_childs_text([_data],_product,products)
|
|
|
if len(child_text)>0:
|
|
|
+ logger.info("extract_type by_tree child_text:%s"%child_text)
|
|
|
list_result.append(child_text)
|
|
|
if parent_title is not None:
|
|
|
+ child_text,_,_ = get_childs_text([parent_title],_product,products)
|
|
|
+ if len(child_text)>0:
|
|
|
+ logger.info("extract_type by_tree child_text:%s"%child_text)
|
|
|
+ list_result.append(child_text)
|
|
|
+
|
|
|
childs = parent_title.get("child_title",[])
|
|
|
if len(childs)>0:
|
|
|
|
|
|
range_data = get_range_data_by_childs(list_data[_data_i:],childs)
|
|
|
p_text = ""
|
|
|
_find = False
|
|
|
+ end_id = id(_data["title_next"]) if isinstance(_data["sentence_title"],dict) and _data["title_next"] is not None and _data["title_next"]["sentence_title"] is not None else None
|
|
|
for pdata in range_data:
|
|
|
ptext = pdata["text"]
|
|
|
for p in products:
|
|
@@ -832,8 +853,11 @@ def extract_parameters_by_tree(_product,products,list_data,_data_i,parent_title,
|
|
|
_find = True
|
|
|
if _find:
|
|
|
break
|
|
|
+ if id(pdata)==end_id:
|
|
|
+ break
|
|
|
p_text += ptext+"\r\n"
|
|
|
if len(p_text)>0:
|
|
|
+ logger.debug("extract_type by parent range_text:%s"%p_text)
|
|
|
list_result.append(p_text)
|
|
|
return True
|
|
|
return False
|
|
@@ -861,8 +885,8 @@ def get_table_pieces(_text,_product,products,list_result,_find):
|
|
|
if _find:
|
|
|
list_trs.append(tr)
|
|
|
if len(list_trs)>0:
|
|
|
- logger.debug("extract_type table slices")
|
|
|
table_html = "<table>%s</table>"%("\r\n".join([str(a) for a in list_trs]))
|
|
|
+ logger.debug("extract_type table slices %s"%(table_html))
|
|
|
list_result.append(table_html)
|
|
|
|
|
|
def extract_parameters_by_table(_product,products,_param_pattern,list_data,_data_i,list_result):
|
|
@@ -887,8 +911,8 @@ def extract_parameters_by_table(_product,products,_param_pattern,list_data,_data
|
|
|
if re.search(_param_pattern,text_line_first) is not None and text_line_first.find(_product)>=0:
|
|
|
_flag = True
|
|
|
if _flag:
|
|
|
- logger.debug("extract_type add all table %s"%_text)
|
|
|
if len(products)==0:
|
|
|
+ logger.debug("extract_type whole table by param and product %s"%(_text))
|
|
|
list_result.append(_text)
|
|
|
else:
|
|
|
for p in products:
|
|
@@ -911,15 +935,26 @@ def extract_parameters_by_table(_product,products,_param_pattern,list_data,_data
|
|
|
for line in list_table:
|
|
|
for cell in line:
|
|
|
cell_text = cell[0]
|
|
|
- if len(cell_text)>50 and len(re.findall("\d+",cell_text))>10 and cell_text.find(_product)>=0:
|
|
|
- list_result.append(cell_text)
|
|
|
+ if len(cell_text)>50 and len(re.findall(meter_pattern,cell_text))>5 and cell_text.find(_product)>=0:
|
|
|
+ _f = True
|
|
|
+ for cell in line:
|
|
|
+ if not _f:
|
|
|
+ break
|
|
|
+ cell_text = cell[0]
|
|
|
+ for p in products:
|
|
|
+ if cell_text.find(p)>=0 and p!=_product:
|
|
|
+ _f = False
|
|
|
+ break
|
|
|
+ if _f:
|
|
|
+ logger.debug("extract_type param column %s"%(cell_text))
|
|
|
+ list_result.append(cell_text)
|
|
|
if len(cell_text)<len(_product)*10 and str(cell_text).find(_product)>=0:
|
|
|
for _index in list_head_index:
|
|
|
if _index>=len(line):
|
|
|
continue
|
|
|
_cell = line[_index]
|
|
|
if len(cell[0])>0:
|
|
|
- logger.info("%s-%s"%("extract_type add on table",_cell[0]))
|
|
|
+ logger.info("%s-%s"%("extract_type add on table text:",_cell[0]))
|
|
|
list_result.append(_cell[0])
|
|
|
if not _flag and (re.search(_param_pattern,_text) is not None or (parent_title is not None and re.search(_param_pattern,parent_title["text"]) is not None)) and _text.find(_product)>=0:
|
|
|
get_table_pieces(_text,_product,products,list_result,False)
|
|
@@ -984,14 +1019,14 @@ def extract_parameters_by_sentence(list_data,_data,_data_i,_product,products,lis
|
|
|
if re.search(_param_pattern,_text) is not None and len(_text)<50:
|
|
|
childs = _data["child_title"]
|
|
|
if len(childs)>0:
|
|
|
- logger.debug("extract_type sentence %s"%("re.search(_param_pattern,_text) is not None and len(_text)<50:"))
|
|
|
extract_text,_,_ = get_childs_text([_data],_product,products)
|
|
|
if len(extract_text)>0:
|
|
|
+ logger.debug("extract_type param-product %s"%(extract_text))
|
|
|
list_result.append(extract_text)
|
|
|
elif is_project:
|
|
|
- logger.debug("extract_type sentence is_project")
|
|
|
extract_text,_,_ = get_childs_text([_data],_product,products,is_begin=True)
|
|
|
if len(extract_text)>0 and re.search(meter_pattern,extract_text) is not None:
|
|
|
+ logger.debug("extract_type sentence is_project param-product is product %s"%(extract_text))
|
|
|
list_result.append(extract_text)
|
|
|
|
|
|
def getBestProductText(list_result,_product,products):
|
|
@@ -1006,7 +1041,7 @@ def getBestProductText(list_result,_product,products):
|
|
|
_result = list_result[i]
|
|
|
_check = True
|
|
|
_result_text = BeautifulSoup(_result,"html5lib").get_text()
|
|
|
- _search = re.search("项目编号[::]|项目名称[::]|联合体投标",_result)
|
|
|
+ _search = re.search("项目编号[::]|项目名称[::]|联合体投标|开户银行",_result)
|
|
|
if _search is not None:
|
|
|
logger.debug("result%d error illegal text %s"%(i,str(_search)))
|
|
|
_check = False
|
|
@@ -1015,7 +1050,7 @@ def getBestProductText(list_result,_product,products):
|
|
|
if _result_text.find(p)>0 and not (is_similar(_product,p,80) or p.find(_product)>=0 or _product.find(p)>=0):
|
|
|
logger.debug("result%d error product scoss %s"%(i,p))
|
|
|
_check = False
|
|
|
- if len(_result_text)<50:
|
|
|
+ if len(_result_text)<100:
|
|
|
if re.search(meter_pattern,_result_text) is None:
|
|
|
logger.debug("result%d error text min count"%(i))
|
|
|
_check = False
|
|
@@ -1027,6 +1062,19 @@ def getBestProductText(list_result,_product,products):
|
|
|
logger.debug("result%d error text max count less meter"%(i))
|
|
|
_check = False
|
|
|
|
|
|
+ list_find = list(set(re.findall(meter_pattern,_result_text)))
|
|
|
+
|
|
|
+ not_list_find = list(set(re.findall(not_meter_pattern,_result_text)))
|
|
|
+ _count = len(list_find)-len(not_list_find)
|
|
|
+ has_num = False
|
|
|
+ for _find in list_find:
|
|
|
+ if re.search('[0-9a-zA-Z]',_find) is not None:
|
|
|
+ has_num = True
|
|
|
+ break
|
|
|
+ if not(_count>=2 and has_num or _count>=5):
|
|
|
+ logger.debug("result%d error match not enough"%(i))
|
|
|
+ _check = False
|
|
|
+
|
|
|
if _check:
|
|
|
return _result
|
|
|
|
|
@@ -1052,7 +1100,7 @@ def extract_product_parameters(list_data,_product):
|
|
|
if _type=="sentence":
|
|
|
if _text.find(_product)>=0:
|
|
|
_find_count += 1
|
|
|
- if re.search("项目名称|采购项目",_text) is not None:
|
|
|
+ if re.search("项目名称|采购项目",_text) is not None and re.search("等",_text) is not None:
|
|
|
is_project = True
|
|
|
extract_parameters_by_sentence(list_data,_data,_data_i,_product,products,list_result,is_project)
|
|
|
|
|
@@ -1061,13 +1109,14 @@ def extract_product_parameters(list_data,_product):
|
|
|
_find_count += 1
|
|
|
extract_parameters_by_table(_product,products,_param_pattern,list_data,_data_i,list_result)
|
|
|
|
|
|
- return getBestProductText(list_result,_product,products),_find_count
|
|
|
+ _text = getBestProductText(list_result,_product,products)
|
|
|
+ return _text,_find_count
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
- filepath = "download/fa85b009fad13bd5e48ae1a51d2e3175.html"
|
|
|
- _product = "自动体外除颤器(AED)等"
|
|
|
+ filepath = "download/4597dcc128bfabc7584d10590ae50656.html"
|
|
|
+ _product = "彩色多普勒超声诊断仪"
|
|
|
|
|
|
_html = open(filepath, "r", encoding="utf8").read()
|
|
|
|
|
@@ -1079,5 +1128,6 @@ if __name__ == '__main__':
|
|
|
|
|
|
_text,_count = extract_product_parameters(list_data,_product)
|
|
|
logger.info("find count:%d"%(_count))
|
|
|
- logger.info("extract_text %s"%_text)
|
|
|
+ logger.info("extract_parameter_text::%s"%(_text))
|
|
|
+
|
|
|
|