我想找到或设计一个可以找到维基百科XML转储的解析器,但我无法找到任何解析器,也不知道如何做到这一点。
我尝试过使用wikiextractor,但不幸的是它不会根据用户定义的类别提取文章,而是提取包含关键字的文章。
例如,在我下载的xml文件中,维基百科文章“无政府主义”。这篇文章可以在以下类别中找到:
[[Category:Anarchism| ]]
[[Category:Political culture]]
[[Category:Political ideologies]]
[[Category:Social theories]]
[[Category:Anti-fascism]]
[[Category:Anti-capitalism]]
[[Category:Far-left politics]]
例如,无政府主义的xml的一部分:
<page>
<title>Anarchism</title>
<ns>0</ns>
<id>12</id>
<revision>
<id>716551092</id>
<parentid>714146352</parentid>
<timestamp>2016-04-22T10:19:33Z</timestamp>
<contributor>
<ip>85.193.216.88</ip>
</contributor>
<comment>a better word; use [[plain English]] -> [[WP:MOS]]</comment>
<model>wikitext</model>
<format>text/x-wiki</format>
<text xml:space="preserve">{{Redirect2|Anarchist|Anarchists|the fictional character|Anarchist (comics)|other uses|Anarchists (disambiguation)}}
{{pp-move-indef}}
{{Use British English|date=January 2014}}
{{Anarchism sidebar}}
'''Anarchism''' is a [[political philosophy]] that advocates [[self-governance|self-governed]] societies based on voluntary institutions. These are often described as [[stateless society|stateless societies]],<ref>"ANARCHISM, a social philosophy that rejects authoritarian government and maintains that voluntary institutions are best suited to express man's natural social tendencies." George Woodcock. "Anarchism" at The Encyclopedia of Philosophy</ref><ref>"In a society developed on these lines, the voluntary associations which already now begin to cover all the fields of human activity would take a still greater extension so as to substitute themselves for the state in all its functions." [http://www.theanarchistlibrary.org/HTML/Petr_Kropotkin___Anarchism__from_the_Encyclopaedia_Britannica.html Peter Kropotkin. "Anarchism" from the Encyclopædia Britannica]</ref><ref>"Anarchism." The Shorter Routledge Encyclopedia of Philosophy. 2005. p. 14 "Anarchism is the view that a society without the state, or government, is both possible and desirable."</ref><ref>Sheehan, Sean. Anarchism, London: Reaktion Books Ltd., 2004. p. 85</ref> although several authors have defined them more specifically as institutions based on non-[[Hierarchy|hierarchical]] [[Free association (communism and anarchism)|free associations]].<ref>"as many anarchists have stressed, it is not government as such that they find objectionable, but the hierarchical forms of government associated with the nation state." Judith Suissa. ''Anarchism and Education: a Philosophical Perspective''. Routledge. New York. 2006. p. 7</ref><ref name="iaf-ifa.org"/><ref>"That is why Anarchy, when it works to destroy authority in all its aspects, when it demands the abrogation of laws and the abolition of the mechanism that serves to impose them, when it refuses all hierarchical organisation and preaches free agreement — at the same time strives to maintain and enlarge the precious kernel of social customs without which no human or animal society can exist." [[Peter Kropotkin]]. [http://www.theanarchistlibrary.org/HTML/Petr_Kropotkin__Anarchism__its_philosophy_and_ideal.html Anarchism: its philosophy and ideal]</ref><ref>"anarchists are opposed to irrational (e.g., illegitimate) authority, in other words, hierarchy — hierarchy being the institutionalisation of authority within a society." [http://www.theanarchistlibrary.org/HTML/The_Anarchist_FAQ_Editorial_Collective__An_Anarchist_FAQ__03_17_.html#toc2 "B.1 Why are anarchists against authority and hierarchy?"] in [[An Anarchist FAQ]]</ref> Anarchism considers the [[state (polity)|state]] to be undesirable, unnecessary, and harmful.<ref name="definition">
我想在Wikipedia XML转储中搜索特定类别中包含的所有文章,例如[[Category:Anti-fascism]]
,并生成XML文件。然后我将清理XML文件,以便我可以使用gensim word2vec模型进行训练。
请告诉我如何做,我只有基本的编程经验,我需要在Python中这样做。
谢谢