为了账号安全,请及时绑定邮箱和手机立即绑定

用 Go 解析 RDF 三元组。一些项目错误地传递了正则表达式

用 Go 解析 RDF 三元组。一些项目错误地传递了正则表达式

Go
慕田峪9158850 2021-08-23 16:32:58
在解析 Freebase RDF 数据转储时,我试图仅根据标题和文本解析某些实体。我正在使用正则表达式来匹配标题和文本,即使它们不匹配,返回 false,内容仍在传递。我决定将什么转换为 XML 的方式是 properties["/type/object/name"] 不为空,或者它是否包含 @en 并且 properties["/common/document/text"] 不为空。什么定义了空?我注意到,通过打印所有名称( properties["/type/object/name"] )和文本( properties["/common/document/text"] ),我注意到其中一些只是“[ ]”。我不要那些。我想要的是那些不是并且在名称中包含 @en 的( properties["/type/object/name"] )。文本( properties["/common/document/text"] )不会有 @en,所以如果它不是“[]”并且其对应的名称有 @en,那么该实体应该转换为 XML。当我运行我的代码时,我正在使用正则表达式来查看它是否匹配和不匹配那些东西,我看到那些被忽略了,那些“空实体”仍在被转换为 XML。这是我从终端抓取的一些输出:<card><title>"[]"</title><image>"https://usercontent.googleapis.com/freebase/v1/image"</image>%!(EXTRA string=/american_football/football_player/footballdb_id)<text>"[]"</text><facts>    <fact property="/type/object/type">/type/property</fact>    <fact property="/type/property/schema">/american_football/football_player</fact>    <fact property="/type/property/unique">true</fact>    <fact property="http://www/w3/org/2000/01/rdf-schema#label">"footballdb ID"@en</fact>    <fact property="/type/property/expected_type">/type/enumeration</fact>    <fact property="http://www/w3/org/1999/02/22-rdf-syntax-ns#type">http://www/w3/org/2002/07/owl#FunctionalProperty</fact>    <fact property="http://www/w3/org/2000/01/rdf-schema#domain">/american_football/football_player</fact>    <fact property="http://www/w3/org/2000/01/rdf-schema#range">/type/enumeration</fact> </facts> </card>这是我的代码,下面,我做错了什么?它不应该匹配正则表达式然后不写它写的东西吗?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 159 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号