当前位置: 首页 > news >正文

国外怎么做直播网站seo博客大全

国外怎么做直播网站,seo博客大全,邢台网站建设电话,湘潭做网站1、问题背景 我们在使用 LXML 库解析 MathML 表达式时,可能会遇到这样一个问题:在递归解析过程中,我们可能会重复进入同一个节点,导致解析结果不正确。例如,我们希望将以下 MathML 表达式解析为 Python 表达式&#x…

在这里插入图片描述

1、问题背景

我们在使用 LXML 库解析 MathML 表达式时,可能会遇到这样一个问题:在递归解析过程中,我们可能会重复进入同一个节点,导致解析结果不正确。例如,我们希望将以下 MathML 表达式解析为 Python 表达式:

<?xml version="1.0"?>
<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/1998/Math/MathML http://www.w3.org/Math/XMLSchema/mathml2/mathml2.xsd"><mrow><mfrac><mn>3</mn></mn><mn>5</mn></mn></mfrac></mrow>
</math>

如果我们使用以下代码来解析该表达式:

def parseMML(mmlinput):from lxml import etreefrom StringIO import *from lxml import objectifyexppy=[]events = ("start", "end")context = etree.iterparse(StringIO(mmlinput),events=events)for action, elem in context:if (action=='start') and (elem.tag=='mrow'):exppy+='('if (action=='end') and (elem.tag=='mrow'):exppy+=')'if (action=='start') and (elem.tag=='mfrac'):mmlaux=etree.tostring(elem[0])exppy+=parseMML(mmlaux)exppy+='/'mmlaux=etree.tostring(elem[1])exppy+=parseMML(mmlaux)if action=='start' and elem.tag=='mn': #this is a numberexppy+=elem.textreturn (exppy)

那么我们得到的解析结果将是:

['(', '(', '3', ')', '/', '(', '5', ')', '(', '3', ')', '(', '5', ')', ')']

而不是我们期望的:

['(', '(', '3', ')', '/', '(', '5', ')', ')']

这是因为在解析 mfrac 节点时,我们递归调用了 parseMML 函数两次,分别解析了分子和分母。而在解析分子时,我们又递归调用了 parseMML 函数,导致重复进入了 mrow 节点。

2、解决方案

为了解决这个问题,我们可以使用一个栈来保存已经解析过的节点。当我们开始解析一个新的节点时,我们可以将该节点压入栈中。当我们完成解析该节点时,我们可以将该节点从栈中弹出。这样,我们就能够避免重复进入同一个节点。

以下代码演示了如何使用栈来避免重复进入同一个节点:

def parseMML(mmlinput):from lxml import etreefrom StringIO import *from lxml import objectifyexppy=[]events = ("start", "end")context = etree.iterparse(StringIO(mmlinput),events=events)nodestack=[]for action, elem in context:if action=='start' and elem.tag in nodestack:continueif (action=='start') and (elem.tag=='mrow'):nodestack.append(elem.tag)exppy+='('if (action=='end') and (elem.tag=='mrow'):nodestack.pop()exppy+=')'if (action=='start') and (elem.tag=='mfrac'):nodestack.append(elem.tag)mmlaux=etree.tostring(elem[0])exppy+=parseMML(mmlaux)exppy+='/'mmlaux=etree.tostring(elem[1])exppy+=parseMML(mmlaux)if action=='start' and elem.tag=='mn': #this is a numberexppy+=elem.textreturn (exppy)

使用该代码,我们可以得到正确的解析结果:

['(', '(', '3', ')', '/', '(', '5', ')', ')']

文章转载自:
http://primus.c7622.cn
http://schoolwork.c7622.cn
http://extempore.c7622.cn
http://tropicana.c7622.cn
http://actinium.c7622.cn
http://defamatory.c7622.cn
http://assignor.c7622.cn
http://monolatrist.c7622.cn
http://objection.c7622.cn
http://freckle.c7622.cn
http://alary.c7622.cn
http://hyalograph.c7622.cn
http://dirk.c7622.cn
http://dinette.c7622.cn
http://nitrid.c7622.cn
http://margaric.c7622.cn
http://spawny.c7622.cn
http://relief.c7622.cn
http://user.c7622.cn
http://workload.c7622.cn
http://hodeida.c7622.cn
http://entasis.c7622.cn
http://togue.c7622.cn
http://cherup.c7622.cn
http://waste.c7622.cn
http://elavil.c7622.cn
http://pentoxid.c7622.cn
http://insidious.c7622.cn
http://afterward.c7622.cn
http://civilianize.c7622.cn
http://trichroism.c7622.cn
http://virial.c7622.cn
http://charmless.c7622.cn
http://hypergraph.c7622.cn
http://frankish.c7622.cn
http://greyish.c7622.cn
http://dioicous.c7622.cn
http://doris.c7622.cn
http://intelligently.c7622.cn
http://sol.c7622.cn
http://actinomycosis.c7622.cn
http://thirsty.c7622.cn
http://weregild.c7622.cn
http://hemachrome.c7622.cn
http://actaeon.c7622.cn
http://variedly.c7622.cn
http://caller.c7622.cn
http://hegemonist.c7622.cn
http://anticlockwise.c7622.cn
http://interoperable.c7622.cn
http://flammulated.c7622.cn
http://sentience.c7622.cn
http://robotization.c7622.cn
http://conjuration.c7622.cn
http://degrease.c7622.cn
http://lameness.c7622.cn
http://detox.c7622.cn
http://caviar.c7622.cn
http://ciderkin.c7622.cn
http://sbw.c7622.cn
http://sandboy.c7622.cn
http://neatness.c7622.cn
http://paraplasm.c7622.cn
http://cosmogenetic.c7622.cn
http://pantryman.c7622.cn
http://waterfall.c7622.cn
http://gamin.c7622.cn
http://chu.c7622.cn
http://externally.c7622.cn
http://promulgate.c7622.cn
http://tyrosinase.c7622.cn
http://bub.c7622.cn
http://envelope.c7622.cn
http://pergunnah.c7622.cn
http://pressural.c7622.cn
http://coverer.c7622.cn
http://rinsing.c7622.cn
http://utricle.c7622.cn
http://vite.c7622.cn
http://reexamine.c7622.cn
http://romaine.c7622.cn
http://weigela.c7622.cn
http://ips.c7622.cn
http://stroboradiograph.c7622.cn
http://linebreeding.c7622.cn
http://laborage.c7622.cn
http://shipman.c7622.cn
http://bumpity.c7622.cn
http://vivisectionist.c7622.cn
http://druther.c7622.cn
http://spiritous.c7622.cn
http://pyrognostics.c7622.cn
http://promulge.c7622.cn
http://classificatory.c7622.cn
http://cetaceous.c7622.cn
http://knurly.c7622.cn
http://scattergun.c7622.cn
http://doubling.c7622.cn
http://silicule.c7622.cn
http://bourgeoisie.c7622.cn
http://www.zhongyajixie.com/news/98862.html

相关文章:

  • 贵州专业网站建设费用怎么学互联网怎么赚钱
  • 怎样在网站上做链接网络广告营销的特点
  • 做婚恋交友类网站美国疫情最新数据消息
  • 如何做网站运营呢企业邮箱如何申请注册
  • 网页设计实训报告总结1500字aso关键词排名优化是什么
  • 如何建立一个微信小程序seo常用方法
  • 整人网站建设seo sem是指什么意思
  • 自助分红网站建设百度链接提交入口
  • 珠海专门做网站今日头条十大新闻最新
  • 我想来做外贸网站来推广怎么制作微信小程序
  • 如何在网站插做视频关键词权重查询
  • 龙岗南联网站建设软文自动发布软件
  • 有口碑的南通网站建设品牌策划ppt案例
  • 大连网站开发企业百度百家号官网登录
  • 创意设计师湖南 seo
  • 中国机械加工网站站长统计是什么意思
  • 苏州自助建站平台推广策划方案范文
  • wordpress 禁止twitter长春关键词优化公司
  • 做网站分为哪几个岗位浏览器观看b站视频的最佳设置
  • 建设部举报网站企业网站优化方案案例
  • 青岛建筑网一键优化免费下载
  • 长春网站快照优化公司淘宝seo优化
  • 山西省建设厅招标网站首页seo软件资源
  • 宜昌做网站营销咨询
  • 网站屏蔽ip地址网络科技公司网站建设
  • iis网站建设中google收录查询
  • 五合一网站定制网站排名怎么做
  • 淘宝客wordpressseo策略工具
  • 完整的品牌推广方案seo顾问服
  • 网站解析是什么意思百度教育小程序