Information from Wikipedia's "Infobox"

178 views
Skip to first unread message

zliu

unread,
Feb 20, 2012, 8:50:51 AM2/20/12
to jwpl-users
Hello,

Does anyone knows how to get the information from Wikipedia's
"Infobox" by using JWPL API? I want to get the type of article, for
example, people, location, etc.

Any idea?
Thanks in advance.

Best regards,

Zhan

Elham Fekri

unread,
Feb 20, 2012, 11:56:46 PM2/20/12
to jw...@googlegroups.com
hello
Infoboxes have a format and I parsed the text field of page table to
get infobox title and it's attributes.

good luck

zliu

unread,
Feb 22, 2012, 4:10:39 AM2/22/12
to jwpl-users
Thanks Elham.

I get the whole text of one page by using page.getText(). However, I
can't find any information about "infobox".
Could you please give me a concrete example (some lines of code) about
this problem?

Thanks in advance!
Best regards,

Zhan

On Feb 21, 5:56 am, Elham Fekri <elham.fe...@gmail.com> wrote:
> hello
> Infoboxes have a format and I parsed the text field of page table to
> get infobox title and it's attributes.
>
> good luck
>

Andre Blessing

unread,
Feb 22, 2012, 4:33:50 AM2/22/12
to jw...@googlegroups.com
Hello Zhan,

the following code shows simple infobox processing.

ParsedPare pp = page.getParsedPage(); // parse the page
for (Template t: pp.getTemplates()) // iterate over all templates
{
if (t.getName().toLowerCase().startsWith("infobox")) // consider infoboxes
{
for (String s: t.getParameters()) // iterate over all
attribute-value pairs
{
System.out.println(t.getName + " " + s)
}
}
}


Best regards,

Andre

Elham Fekri

unread,
Feb 22, 2012, 6:58:34 AM2/22/12
to jw...@googlegroups.com
hello
I am working on Persian wikipedia and in this language I saw "{{جعبه"
in every page that has infobox and the title of infobox comes after
it. Then attributes start and they are after a "|" character(and
almost in a new line) and their value come after "=" character.
In English pages the pattern is similar and it is {{Infobox and ...

examples for page Tehran:
{{Infobox settlement
|official_name = Tehran
|native_name = تهران
|nickname = TEH
|settlement_type =
|image_skyline = Tehranwnight34w.jpg
|image_seal = Tehran Logo.png
|image_caption = Tehran Skyline, 2006
|image_map =
|mapsize =
|map_caption =
|pushpin_map = Iran <!-- the name of a location map as
per http://en.wikipedia.org/wiki/Template:Location_map -->
|pushpin_label_position = <!-- the position of the pushpin label:
left, right, top, bottom, none -->
|pushpin_map_caption =
|pushpin_mapsize =
|coordinates_region = IR
|subdivision_type = [[List of countries|Country]]
|subdivision_name = {{flag|Iran}}
|subdivision_type1 =[[Provinces of Iran|Province]]
|subdivision_name1 =[[Tehran Province|Tehran]]
|subdivision_type2 =[[Counties of Iran|County]]
|subdivision_name2 =[[Tehran County|Tehran]]
|subdivision_type3 =[[Bakhsh]]
|subdivision_name3 =[[Central District (Tehran County)|Central]]
|subdivision_type4 =
|subdivision_name4 =
|leader_title = Mayor
|leader_name = [[Mohammad Bagher Ghalibaf]]
|established_title =
|established_date = 1906
|leader_title1 = City Council
|leader_name1 = Chairman: [[Mehdi Chamran]]
|area_magnitude =
|area_metro_km2 = 1274
|area_metro_sq_mi =
|area_land_km2 =
|area_land_sq_mi =
|area_water_km2 =
|area_water_sq_mi =
|area_water_percent =
|area_urban_km2 = 730
|area_urban_sq_mi =
|population_as_of = 2010
|population_note = Population Data from 2006 Census and
Tehran Municipality.<ref>[http://www.sci.org.ir/content/userfiles/_sci_en/sci_en/sel/year85/f2/CS_02_8.HTM
Statistical Center of Iran – 2006 Census]{{dead link|date=November
2010}}</ref><ref>{{cite
web|url=http://www.inro.ca/en/pres_pap/international/ieug07/Day1_2.pdf
|title=Microsoft PowerPoint – Day1_2_Network, Transit & Travel Demand
Modelling in Iran Using EMME2 |format=PDF |date=
|accessdate=2010-11-12}}</ref> Metro area figure refers to [[Tehran
Province]].
|population_metro = 13,413,348
|population_urban = 9,110,347
|population_density_sq_mi = 26748.3
|population_blank1_title = Population Rank in Iran
|population_blank1 = [[List of Iran cities by population|1st]]
|timezone = [[Iran Standard Time|IRST]]
|utc_offset = +3:30
|timezone_DST = [[Iran Standard Time|IRDT]]
|utc_offset_DST = +4:30
|coordinates_display = %
|latd = 35 | latm = 41 | lats = 46 | latNS = N
|longd = 51 | longm = 25 | longs = 23 | longEW = E
|elevation_m = 1200
|elevation_ft = 3900
|area_code = 021
|website = [http://www.tehran.ir/ www.tehran.ir]
|footnotes =
}}


**************************************

and in Pershian:
{{جعبه شهر ایران
|نام‌رسمی=تهران
|روی‌نقشه=آری
|عرض‌جغرافیایی=35.67
|طول‌جغرافیایی=51.42
|تصویر= TEHRAN-5VIEWS.JPG
|اندازه‌تصویر=275
|برچسب‌تصویر=توضیح نگاره‌ها:{{بر}}سمت چپ: [[برج میلاد]]{{بر}}بالا وسط:
[[برج بین‌المللی تهران]]{{بر}} بالا راست: [[برج آزادی]]{{بر}}پایین
وسط: [[کوشک احمدشاهی]] {{بر}} پایین راست: [[سردر باغ ملی]]
|استان=تهران
|شهرستان=تهران
|بخش=[[بخش مرکزی شهرستان تهران|مرکزی]]
|دهستان=
|نام‌محلی=
|نام‌های‌دیگر=
|نام‌های‌قدیمی=طهران
|سال‌شهرشدن=
|جمعیت=شهر: ۸،۴۲۹،۸۰۷<ref name="xxx"/>{{سخ}}[[استان تهران]]: ۱۳،۲۸۱،۸۵۸
|رشدجمعیت=
|تراکم‌جمعیت=۱۰٬۵۵۵<ref name="Hashiye">{{یادکرد وب
|نشانی=http://www.hamshahrionline.ir/hamnews/1384/840825/news/shari.htm
|عنوان=مساحت حاشیه‌های پایتخت سه برابر مساحت شهر تهران است.
|تاریخ بازدید=۱ اکتبر ۲۰۰۸
|ناشر=وبگاه همشهری آن‌لاین
}}</ref>
|زبان=[[زبان فارسی|فارسی]]{{سخ}}دیگرزبان‌ها:{{سخ}}<small> [[کردی]]،
[[ترکی]] ، [[لهجه قدیم تهرانی|تاتی]]<ref>{{یادکرد وب
|نشانی=http://www.ichto.ir/Default.aspx?tabid=198 |عنوان=آداب و رسوم
تهران-زبان |تاریخ بازدید= ۱۴ اکتبر ۲۰۱۱ |زبان=فارسی |اثر=سازمان میراث
فرهنگی، صنایه دستی و گردشگری |}}</ref>، [[زبان
عربی|عربی]]<ref>{{یادکرد وب |نشانی=http://anthropology.ir/node/7214
|عنوان=گونه شناسی زبان تعارف در میان عرب زبانان مقیم در تهران |تاریخ
بازدید= 14 اکتبر 2011 |زبان=فارسی |اثر=انسان شناسی و فرهنگ
|}}</ref><ref>{{یادکرد وب
|نشانی=http://www.chn.ir/news/?Section=2&id=48952 |عنوان=کوچه مروي؛
بازارچه اي که به آرامش رسيد |تاریخ بازدید= 14 اکتبر 2011 |زبان=فارسی
|اثر=خبرگذاری میراث فرهنگی |}}</ref>، [[زبان
ارمنی|ارمنی]]<ref>{{یادکرد وب
|نشانی=http://www.armprelacy.com/farsi/t-a.html |عنوان=ارامنه تهران
|تاریخ بازدید= 14 اکتبر 2011 |زبان=فارسی |اثر=خلیفه‌گری ارامنه تهران
|}}</ref> و زبان‌های مهاجر جدید</small><ref
name=autogenerated2>[http://web.archive.org/web/20040323011350/http://www.hamshahri.org/ostans/iraninfo/tehran/farbomi/leftfar.htm
اطلاعات روزنامهٔ همشهری]، بازدید: دسامبر ۲۰۰۸.</ref>
|مذهب=[[شیعه]] و غیره
|مساحت=۷۳۰ کیلومترمربع<ref name="Hashiye"/>
|ارتفاع=متوسط ۱۱۹۰ متر<ref name="about"></ref>
|میانگین‌دما=حداکثر: +۲۲/۷ درجه<ref
name=autogenerated1>http://www.irimo.ir/farsi/drought/synopH/Tehranmehrabad.txt</ref>
حداقل: +۱۱/۹ درجه
|میانگین‌بارش‌سالانه=۲۳۳ میلیمتر<ref name=autogenerated1 />
|شمارروزهای‌یخبندان=۴۷ روز<ref name=autogenerated1 />
|شهردار=[[محمدباقر قالیباف]]
|ره‌آورد=کتاب، کالا
|پیش‌شماره=۰۲۱
|وبگاه=[http://www.tehran.ir/ شهرداری تهران]
|جمله‌خوشامد=به تهران خوش آمدید
|پانویس=

zliu

unread,
Feb 22, 2012, 9:39:10 AM2/22/12
to jwpl-users
Thanks Andre & Elham,

So strange, I tried pp.getTemplates() with different pages, for
example: Tehran, Steve Jobs, etc.

But all templates are empty.There is nothing in the template for my
test. I have never entered in the loop "for". But in the wikipedia all
these pages have the infobox.

Any ideas?

Best,

Zhan




On Feb 22, 10:33 am, Andre Blessing <andre.bless...@ims.uni-

Andre Blessing

unread,
Feb 22, 2012, 10:34:03 AM2/22/12
to jw...@googlegroups.com
Hello Zhan,

try following example. Maybe it is necessary to use a new MediaWikiParser.

public static void main(String[] args) throws Exception {
DatabaseConfiguration dbConfig = new DatabaseConfiguration();
dbConfig.setHost(HOST);
dbConfig.setDatabase(DB);
dbConfig.setUser(USER);
dbConfig.setPassword(PASSWORD);
dbConfig.setLanguage(Language.english);
Wikipedia wiki = new Wikipedia(dbConfig);
Page page = wiki.getPage("Berlin");
String pageText = page.getText();
MediaWikiParserFactory pf = new MediaWikiParserFactory();
MediaWikiParser parser = pf.createParser();
ParsedPage pp = parser.parse(page.getText());
for(Template t : pp.getTemplates()){
if (t.getName().toLowerCase().startsWith("infobox"))
for(String tp : t.getParameters()){
System.out.println(tp);
}
}
}

Best regards,

Andre

zliu

unread,
Feb 22, 2012, 12:29:38 PM2/22/12
to jwpl-users
Thank you very much Andre.

It works!

Best regards,

Zhan

On Feb 22, 4:34 pm, Andre Blessing <andre.bless...@ims.uni-
stuttgart.de> wrote:
> Hello Zhan,
>
Reply all
Reply to author
Forward
0 new messages