Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Convert Wikicode to XML #161

Closed
tobiasschweizer opened this issue Aug 22, 2016 · 8 comments
Closed

Convert Wikicode to XML #161

tobiasschweizer opened this issue Aug 22, 2016 · 8 comments

Comments

@tobiasschweizer
Copy link

tobiasschweizer commented Aug 22, 2016

Is there an easy way to convert Wikicode to XML using mwparserfromhell?

In fact, the mw code I am dealing with already looks like XML except for the links.

Can I provide a mapping for these wiki-links so they get turned into XML?

Could I use the builder to do so applying _handle_wikilink (https://mwparserfromhell.readthedocs.io/en/latest/api/mwparserfromhell.parser.html#module-mwparserfromhell.parser.builder)?

@jayvdb
Copy link
Contributor

jayvdb commented Aug 22, 2016

the mw code I am dealing with already looks like XML..

Do you mean the raw wikitext in the wiki source looks like XML?

Or, the mwparserfromhell generated tree looks like XML?

@tobiasschweizer
Copy link
Author

tobiasschweizer commented Aug 22, 2016

Sorry, let me give you a concrete example. This is the source:

[[File:file_icon.gif|link=http://www.ub.unibas.ch/digi/bez/bernoullibriefe/jpg/L_Ia_654/BAU_5_000055682_0001.jpg]] Bale ce 6. 8bre 1708.

Monsieur.<ref>Der Schreiber dieses Briefentwurfs hat zahlreiche Schreibfehler begangen. Sie wurden, falls offenkundig, stillschweigend verbessert.</ref>

J'ay appris avec plaisir par l'honeur de vostre lettre, que Vous etes heureusement arrivé à Geneve. J'aurois souhaité que vous eussiez pris la resolution de rester ici l'hyver prochain, afin de jouir de vôtre presance, pour vous mieux communiquer le peu de lumiere que j'ay dans les Mathematiques, car plus je trouve de disposition dans les Personnes comme Vous pour nos etudes, moins je fais de difficultés de Leur ouvrir mes secrets, bien eloigné de la nature de ceux qui cachent soigneusement ce qu'ils<ref>Im Manuskript steht nur "qui".</ref> sçavent, parce que leur but est de se faire admirer par le public plustot, que de Luy estre utile. Je Vous voi Monsieur dans une si belle carriere, et si bien avancé dans la subtile Geometrie, que je puis augurer sans temerité que vous serez un jour un de nos plus Grands Geometres c'est pourquoi je suis ravy d'entrer comme Vous souhaitez en comerce de lettre avec vous, pour avoir la gloire de contribuer un peu au Titre de Grand Geometre, que le temps Vous donnera: pour en faire donc le commencement, je veux bien Vous faire part de ma maniere de traiter cette equation <math>z^{m}+ay^{n}=bz^{e}y^{r}</math> par substitution, et d'en trouver l'aire; si les indeterminées <math>z</math> et <math>y</math> êtoient separables, il n'y auroit point de difficulté, pour les rendre separables, il faut changer l'equation proposée en une autre où il y ait deux termes contenants un egal nombre de dimensions d'une des indeterminées pour la diviser [[File:file_icon.gif|link=http://www.ub.unibas.ch/digi/bez/bernoullibriefe/jpg/L_Ia_654/BAU_5_000055682_0002.jpg]] en suite par elle, pour cet efet, supposons <math>z=xy^{p}</math>, ce qui ettant substitué dans l'equation proposée, elle se transformera en celle cy <math>x^{m}y^{mp}+ay^{n}=bx^{e}y^{ep+r}</math>, dans la quelle pour faire que <math>y</math> ait en deux termes<ref>Im Manuskript steht "terme".</ref> un<ref>Im Manuskript steht "une"</ref> mesme nombre de dimensions<ref>Im Manuskript steht "dimension". Das Komma fehlt.</ref>, il est arbitraire de mettre<ref>Im Manuskript steht "mestre".</ref> <math>mp=ep+r</math>, ou <math>mp=n</math>, ou <math>n=ep+r</math>, par lesquelles on obtiendra trois differentes formules pour la condition de quadrabilité, mais pour avoir celle de Mr. Craig, je prens la premiere <math>mp=ep+r</math>, ce qui donne <math>p=\frac{r}{m-e}</math>; divisant donc l'equation transformée<ref>Im Manuskript steht "transformé".</ref> par <math>y^{mp}</math>, on aura<ref>In den folgenden Formeln finden sich einige Fehler, die hier korrigiert wurden. </ref> <math>x^{m}+ay^{\frac{mn-en-mr}{m-e}}=bx^{e}</math>, d'où on deduit <math>y=\overline{\frac{b}{a}x^{e}-\frac{1}{a}x^{m}}^{\frac{m-e}{mn-en-mr}}</math>, et par consequent <math>dy=\frac{m-e}{mn-en-mr}dx\times\overline{\frac{eb}{a}x^{e-1}-\frac{m}{a}x^{m-1}}\times\overline{\frac{b}{a}x^{e}-\frac{1}{a}x^{m}}^{\frac{m-e}{mn-en-mr}-1}</math>, multipliant <math>z</math> (<math>xy^{p}=x\times\overline{\frac{b}{a}x^{e}-\frac{1}{a}x^{m}}^{\frac{r}{mn-en-mr}}</math>) par <math>dy</math>, on aura <math>zdy=\frac{m-e}{mn-en-mr}dx\times\overline{\frac{eb}{a}x^{e}-\frac{m}{a}x^{m}}\times\overline{\frac{b}{a}x^{e}-\frac{1}{a}x^{m}}^{\frac{\overline{m-e}\times r}{mn-en-mr}-1}</math>. 

I would like to turn the links ([[File:file_icon.gif|link=http://www.ub.unibas.ch/digi/bez/bernoullibriefe/jpg/L_Ia_654/BAU_5_000055682_0001.jpg]]) into valid XML using mwparserfromhell.

So each of these links should be turned into something like: <file src="http://www.ub.unibas.ch/digi/bez/bernoullibriefe/jpg/L_Ia_654/BAU_5_000055682_0001.jpg"/>

When I pass the source code to the mwparserfromhell.parse method, I can identify the links as Wikilinks using isinstance(node, mwparserfromhell.nodes.Wikilink). So I wonder if I can treat these Wikilinks specially and leave the rest as it is.

Ideally, I would be able to export everything as one string in the end that represents an XML document.

@jayvdb
Copy link
Contributor

jayvdb commented Aug 22, 2016

Would you be happy with it converted to HTML ?

@tobiasschweizer
Copy link
Author

Well, it depends on how this HTML would look like :-)

What would be the easiest way to do the thing I want? Are there other tools I could use?

@jayvdb
Copy link
Contributor

jayvdb commented Aug 22, 2016

I believe that parsoid can be used as a library (without the web service) or command line tool, so that could be enough to give you a HTML version.

@lahwaacz
Copy link
Contributor

mwparserfromhell can't parse the link=... part of file links, see #87.

@Abbe98
Copy link

Abbe98 commented Aug 22, 2016

You can retrieve the articles as HTML using the official API.

@tobiasschweizer
Copy link
Author

I figured out a solution that works for me by iterating over the nodes (recursively) and looking at their type (`isinstance). Depending on the type of the node, I write the desired XML representation to a file. Actually, I just have to generate the doctype, the root elements (opening and closing) and handle internal and external links specially. The rest already looks like XML.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants