大佬教程收集整理的这篇文章主要介绍了如何使用 ChemDataExtractor 创建自定义解析器以获取给定文本中的实体?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
谁能分享我如何编写自定义解析器以所需格式获取化学分子名称和成分详细信息
[化学名称+添加:成分]
doc = Paragraph('4-Methylmorpholine N-oxIDe (1.76 mL,8.42 mmol) and potassium osmate dihy@R_404_6618@e (97.3 mg,0.38 mmol) ')
这是我的代码:
class BoilingPoint(BaseModel):
name=StringType()
Quan = StringType()
units =StringType()
Compound.addition = ListType(ModelType(BoilingPoint))
import re
from chemdataextractor.parse import R,I,W,Optional,merge
units = R('^(mg|mL|mmol)$')(u'units').add_action(mergE) # define all units in parser
Quan = R(u'^\d+(\.\d+)?$')(u'value')
bp = (Quan+ units)(u'mL')
from chemdataextractor.parse.base import BaseParser
from chemdataextractor.utils import first
class BpParser(BaseParser):
root=bp
def interpret(self,result,start,end):
compound = Compound(
addition=[BoilingPoint(
#name=first(result.xpath('./name/text()'))
Quan=first(result.xpath('./value/text()')),units=first(result.xpath('./units/text()'))
)
]
)
yIEld compound
Paragraph.parsers = [CompoundParser()]+[BpParser()]
结果: [{'names': ['4-Methylmorpholine N-oxIDe']},{'names': ['potassium osmate dihy@R_404_6618@e']},{'addition': [{'Quan': '1.76','units' : 'mL'}]},{'addition': [{'Quan': '8.42','units': 'mmol'}]},{'addition': [{'Quan': '97.3','单位': 'mg'}]},{'addition': [{'Quan': '0.38','units': 'mmol'}]}]
预期结果:化学名称+添加物:成分
[{'names': ['4-Methylmorpholine N-oxIDe'],'addition': [{'Quan': '1.76','units': 'mL'}]},{'Quan': '8.42','units': 'mmol'}}]
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的如何使用 ChemDataExtractor 创建自定义解析器以获取给定文本中的实体?全部内容,希望文章能够帮你解决如何使用 ChemDataExtractor 创建自定义解析器以获取给定文本中的实体?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。