在解析 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>
这是我的代码,下面,我做错了什么?它不应该匹配正则表达式然后不写它写的东西吗?
正则表达式,详细解析一下
正则表达式
正则表达式
求一个非空非中文的正则表达式
相关分类