Closed TheoPortmann closed 6 years ago
Thanks for trying wptools, @TheoPortmann!
I see what's going on here. That value also contains the wikitext template: {{,}}
. Currently, if an infobox value contains a template, we return the wikitext for it, which is why you get "'cépages' = '{{,}}'
".
Like #91, this French Infobox wikitext is unusually complex. French Wikipedia desperately needs Infobox parity in Wikidata. I wonder how much time people spend trying to parse wikitext like this? And, I guess wikitext like this is a major obstacle to getting the data it represents into Wikidata.
Anyway, I think we can give a better result.
I'm adding a new approach to extracting values from the parsetree called "iter" in the comparison below. I think it is an improvement over the previous approach called "find" here. This new approach (iter) has the benefit of picking up TAIL text, as well as getting MORE templates and links mixed with <ext>
tags (references, etc.).
The difference between the approaches is that wptools.utils.template_to_dict_iter()
uses etree.iter()
to iterate over elements, accumulating tail text in order, while wptools.utils.template_to_dict_find()
uses etree.xpath()
to "lookup" or find specific elements.
The drawback to "iter" is that it does not preserve <ext>
tags. I think excluding them is better because it focuses the result on the data.
You can still get the deprecated "find" result by calling template_to_dict(tree, find=True)
. That may help people wanting to use this tool to update Wikidata with references. We can expose it later as an option to wptools.page.parse()
if someone wants it.
nom =
find: Orléans-cléry
iter: Orléans-cléry
charte =
find: rouge
iter: rouge
image =
find: AOC Orléans-cléry vignoble.JPG
iter: AOC Orléans-cléry vignoble.JPG
légende =
find: Vignoble de l'AOC orléans-cléry à [[Mareau-aux-Prés]].
iter: Vignoble de l'AOC orléans-cléry à [[Mareau-aux-Prés]].
appellations =
find: orléans-cléry<ext><name>ref</name><attr> group="Notes" name="AO"</attr></ext>
iter: orléans-cléry
typeappellation =
find: [[appellation d'origine contrôlée|AOC]]-[[appellation d'origine protégée|AOP]]<ext><name>ref</name><attr> name="inao"</attr><inner>{{Lien web|url=http://www.inao.gouv.fr/public/produits/detailProduit.php?ID_PRODUIT=5301 |titre=Orléans-Cléry |site=[http://www.inao.gouv.fr www.inao.gouv.fr] |année=10 mars 2011 |éditeur=[[Ministère de l'agriculture (France)|Ministère de l'agriculture]]. [[Institut national de l'origine et de la qualité]] |consulté le=17 mars 2011 }}</inner><close></ref></close></ext>
iter: [[appellation d'origine contrôlée|AOC]]-[[appellation d'origine protégée|AOP]]
année =
find: [[2006]]<ext><name>ref</name><attr> name="Légifrance1"</attr><inner>{{Légifrance | base=JORF | numéro=AGRP0602138D | texte=Décret du 23 novembre 2006 }} relatif à l'appellation d'origine contrôlée "Orléans-Cléry". {{Lien web|url=http://www.legifrance.gouv.fr |titre=www.legifrance.gouv.fr |année=2006 |éditeur=Secrétariat général du gouvernement français |consulté le=17 mars 2011 }}</inner><close></ref></close></ext>
iter: [[2006]]
pays =
find: {{France}}
iter: {{France}}
région-mère =
find: [[Vignoble de la vallée de la Loire|vallée de la Loire]]
iter: [[Vignoble de la vallée de la Loire|vallée de la Loire]]
similaire =
find:
iter:
sous-régions =
find: [[Orléanais]]
iter: [[Orléanais]]
localisation =
find: [[Loiret (département)|Loiret]]
iter: [[Loiret (département)|Loiret]]
saison =
find:
iter:
climat =
find: [[Climat tempéré|tempéré]] [[Climat océanique|océanique]] dégradé
iter: [[Climat tempéré|tempéré]] [[Climat océanique|océanique]] dégradé
jourssoleil =
find: {{unité|1804|heures}}
iter: {{unité|1804|heures}} /an
sol =
find: [[argile|argilo]]-[[silice|siliceux]] et [[Grave (terrain)|gravelo]]-[[silice|siliceux]]
iter: [[argile|argilo]]-[[silice|siliceux]] et [[Grave (terrain)|gravelo]]-[[silice|siliceux]]
superficietotale =
find:
iter:
superficieplantée =
find: 28 [[hectare]]s<ext><name>ref</name><attr> name="Guide Hachette"</attr><inner>{{ouvrage|langue=fr|prénom1=|nom1=Collectif|lien auteur1=|titre=Le guide Hachette des vins 2011 |sous-titre=des vins pour tous les goût, à tous les prix|numéro d'édition=|éditeur=Hachette livre|lien éditeur=|lieu=Paris|mois=août|année=2010|pages totales=1402|passage=1050|isbn=978-2-01-237681-6|consulté le=17 mars 2011}}</inner><close></ref></close></ext>
iter: 28 [[hectare]]s
exploitations =
find: 23 viticulteurs et 6 vinificateurs<ext><name>ref</name><attr> name="inao"</attr></ext>
iter: 23 viticulteurs et 6 vinificateurs
cépages =
find: {{,}}
iter: [[cabernet franc]] N {{,}}
vins =
find: [[Vin rouge|rouges]]
iter: [[Vin rouge|rouges]]
volproduction =
find: {{unité|848|hectolitres}}
iter: {{unité|848|hectolitres}} en [[2009]]
densité =
find: {{unité|5000|pieds}}
iter: minimum de {{unité|5000|pieds}} par hectare
rendement =
find: {{unité|65|hectolitres}}
iter: maximum 50 à {{unité|65|hectolitres}} par hectare
That's super nice, you really did a great job.
Thank you. I hope it helps! Adding test cases, then build and release.
This is now available in release v0.4.9 on pypi.
Thanks so much for helping us make this improvement @TheoPortmann!
With some pages, french one, some fields of the infobox don't have the data shown in wikipedia but instead the {{,}}
In infobox part of page.data :
In parsetree :
I don't get the value [[cabernet franc]]