我必须从一个巨大的文件(1.5 TB)中读取和过滤行。 巨大文件的内容如下
<http://www.wikidata.org/entity/Q31> <schema#label> "Beligium"@en .
<http://www.wikidata.org/entity/Q31> <schema#label> "Bilkiya"@ay .
<http://www.wikidata.org/entity/Q31> <schema#label> "Belgique"@fr .
<http://www.wikidata.org/entity/Q31> <schema#label> "Beriyum"@na .
<http://www.wikidata.org/entity/Q54> <schema#label> "Japan"@en .
<http://www.wikidata.org/entity/Q112> <schema#label> "asasa"@en .
<http://www.wikidata.org/entity/Q112> <schema#label> "ssdd"@fr .
<https://fr.wikipedia.org/wiki/Label_discographique> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Article> .
<https://fr.wikipedia.org/wiki/Label_discographique> <http://schema.org/about> <http://www.wikidata.org/entity/Q18127> .
我们只想提取与以下模式匹配的行
<http://www.wikidata.org/entity/(ID_LIST)> < schema#label> "(.+)"@(en|fr) .
例如,对于ID_LIST=[Q31,Q54],我们将提取
<http://www.wikidata.org/entity/Q31> <schema#label> "Beligium"@en .
<http://www.wikidata.org/entity/Q31> <schema#label> "Belgique"@fr .
<http://www.wikidata.org/entity/Q54> <schema#label> "Japan"@en .
使用此命令
rg = re.compile('<http://www.wikidata.org/entity/(Q31|Q54)> <schema#label> "(.+)"@(en|fr) .')
rdd = sc.textFile(file_name).filter(lambda x: rg.match(x))
我的问题是,如果ID\u列表来自另一个包含200万个ID的文件呢?我们应该把这两百万放在正则表达式里吗?这有效率吗?你知道吗
当然,简单的解决方案是提取所有与常规模式匹配的行
<http://www.wikidata.org/entity/(.+)> < schema#label> "(.+)"@(en|fr)
然后通过将ID\u列表转换为另一个rdd或数据帧,使用join操作只提取与ID\u列表匹配的行
有没有更好的办法?你知道吗
使用join。你知道吗
(伪代码,可能不起作用)
结果将包含
(id, data)
对相关问题 更多 >
编程相关推荐