コンテンツにスキップ

英文维基 | 中文维基 | 日文维基 | 草榴社区

利用者:赤の旋律/interwiki.py

Interwiki.pyは、言語間リンクを作るために、pythonで書かれたプログラムです。Pywikipediabotフレームワークの一つとして動作します。

このスクリプトは、与えられたページを読み込み、言語間リンクがあればそのリンク先のページを同様にチェックし、そこから言語間リンクを持ってきます。

  • 言語間リンクを持っていないか、それが一致したときは、botは停止します。
  • 新しい言語間リンクをみつけた、もしくは言語間リンクが変更された時には、botはこれを実行します。
  • 言語間リンクが削除されていた時は、botはあなたに実行するかの許可を求めます。
  • 1つのページにいくつもの言語リンクがあった場合、botは対話モードに入ります。そのページにリンクしているページが見つけられ、リンクされるべき言語を尋ね、それぞれの言語ごとにリンクされるべきかを尋ねます。

これらはオプションで変更できることを覚えておいてください。

interwiki.py pagenameとすることで、動作させるページを直接指定できますが、他の手段もあります。下を見てください。

1つ以上のページで動作させる

[編集]

XML Exportを使用すると、pywikipediabotは1つ以上、一回ごとに60のページを取得できます。この方法を使えば、botをページ群上で使用できます。これを行う最も一般的な形式は、-start引数を使用しアルファベット順にSpecial:Allpagesから取得するやり方です。

-start

[編集]

-start引数を使用すると、botは指定された文字からアルファベット順にページを調査します。もし、'B'から開始したいのであれば、interwiki.py -start:Bのようにしてください。特にすべてのwikiで動作させたい場合、interwiki.py -start:!としてください。

リスタートする: -continue, -restore

[編集]

巨大なwikiを調査した場合、長い時間がかかります。動作が終了する前にプログラムが強制終了させる場合があるでしょう。この場合、次回使用時にinterwiki.py -continueとしてください。botはクラッシュしたり停止させられた時、動作していたページを指定したファイルを作成します。continueオプションを使えば、それらのページからアルファベット順に続行することができます。アルファベット順にリスタートしたくない時は、代わりにinterwiki.py -restoreを使ってください。そうすれば、動作していたページちょうどからリスタートできるでしょう。

最後の動作のみが保存されることに注意してください。botは情報をinterwikiダンプファイルに保存しますが、次の動作停止したとき、それが1ページのみの動作だったとしても、ファイルは上書きされてしまいます。

自立的な動作

[編集]

多数のページで動作させているとき、問題をいちいち尋ねずに続行したいと思うかもしれません。これは"-autonomous"オプションを指定することで可能です。このオプションが使用されたとき、botはすべての問題と除去をスキップし、それらのログをautonomous_problems.datに保存します。除去も同様に行いたければ、"-force"オプションをともに指定してください。その場合、あとでしっかり確認をしてください。

sax_parse_bug.dat

[編集]

interwiki.pyが動作しているあいだ、スクリーンにsax_parse_bug.datに触れるエラーメッセージが表示され、まとめてではなく、ページを一つ一つ取得することがあります。これは不正な文字がページのひとつから取得されたことが原因です。

xmltest.pyがこの問題を追跡するために使用できます。引数としてファイル名を与えて動作させてください。:

python xmltest.py sax_parse_bug.dat

Running on years AD

[編集]

There is a special option -years that makes sure not to follow links to centuries and decennia that are common on some wikipedias (like ja:). Even then, this option should be used in combination with an exceptions file (see below) because the la: and ia: number pages are about the numbers and not about the years.

python interwiki.py -autonomous -years

This will take a while to start up while it is preparing hints for all pages named [[1]] through [[2050]]

If you stop the robot during a -years run and want to restart it later, you can tell the robot at which page to restart by using -years:XYZ where XYZ is the year where the robot stopped last time. You can also make the robot start B.C. by making XYZ a negative number.

python interwiki.py -autonomous -years:-500

Running on a simple list of pages

[編集]

Sometimes you have a list of pages available. Just a file of subjects, each subject on a separate line, formatted as [[xx:yyy]] comments. The -file option can be used to run the interwiki bot over such a list of subjects. An example of such a file could be an autonomous_problem.dat file that you want to treat manually:

python interwiki.py -file:autonomous_problem.dat

Using hints

[編集]

Upto now, we have only worked on adding interwikis on pages that already have some. But the bot can also be used to add them on pages that have none yet. This is done by using hints. If for example you want to add interwikis to the page [[en:House]], and think there might be a page at [[fr:Maison]] that would be about the same subject, you can type (if your bot is set to run on English by default) "interwiki.py House -hint:fr:Maison".

If the link is to the same title, you can remove the title, and even the second :. Also, if you want to link to the same word in several languages, you can combine them with commas. So instead of "interwiki.py Albert Einstein -hint:de:Albert_Einstein -hint:fr:Albert_Einstein -hint:id:Albert_Einstein" (those underscores are necessary, otherwise the bot will regard the 'Einstein' part of the pagename), you can write "interwiki.py Albert Einstein -hint:de,fr,id",

Special hints

[編集]

Some special hints have been defined to do a number of languages at once. You can use them instead of the language part of a hint. Currently the following special hints exist for Wikipedia:

  • 10: Ten of the largest Wikipedias
  • 20,30,50: Idem, for twenty, thirty and fifty languages
  • all: All Wikipedias with at least ~100 articles
  • cyril: All languages in Cyrillic script

The same are defined for Wiktionary, but at the moment of writing, 30, 50 and all are the same for Wiktionary. It is intended to add more options.

Asking for hints

[編集]

When working on multiple pages such hints in the command line are rarely useful. In that case (or if you want to decide on the hints later), you can use the options "-askhints", "-untranslated" and "-untranslatedonly". If you choose the -askhints option, for each page you will be asked for one or more hints. They can be like the hints after -hint: on the command line, but the ':' may not be omitted, and spaces are allowed. Thus, valid hints would for example be "en:John Smith", "de,nds,af:" or "50:". "-untranslated" asks for hints only if there are no interwiki links yet; "-untranslatedonly" is like -untranslated, but other pages are not worked on at all.

Instead of giving a hint, you can give an empty line. This specifies that all hints for this page have been given (or that you have no hints for it). Note that if you have given a hint, the bot will keep asking for more hints until you press enter. Another option is to input a question mark and nothing else; in that case you get shown the beginning of the text to the page. If after that you input the question mark again, it will give a larger part of the text, etcetera.

It might in these cases be useful to have the "-confirm" option added, so the bot gets interactive before making a change. This can be used to check whether the links are correct and/or as an impetus to create a backlink.

Wiktionary

[編集]

For Wiktionary there is the special "-wiktionary" option. It works like "-hint:all", but has some extras because on Wiktionary some languages use capitalisation and others don't, and links to another word are never correct.

On non-capitalising wiktionaries, links to capitalising wiktionaries are only added for capitalised words. Also, any link found to a word that differs more than just in capitalisation, is ignored completely.

Automatic translation

[編集]

For years (both AD and BC) and days of the year, the bot can automatically translate it in a large number of languages. If you do not want this automatic translation (for example because it takes long to go over such a large number of languages), it can be switched off with the "-noauto" option.

With the option "-years:" followed by a number (positive or negative), the bot goes through the years from the given year to 2050. If "-years" without any addition is given, the beginning year is taken to be the year 1.

With the option "-days" the bot goes through the days of the year; however, this bot only works correctly on nl:.

[編集]

If you want to run the bot, but know that for a given page, it will get to links that it should not get, you can use the -noredirect or -neverlink or -select or -ignore options.

-noredirect means that if a redirect page is found, the redirect is not followed, as is the normal behaviour, but the page is skipped.

-neverlink:xx with xx: a language code means that any links to the language xx: are ignored.

-select lets you select or deselect every single links that is being found individually, before any page is changed.

-ignore:zxx:pagetitle excludes the page named "pagetitle" in language "zxx" and its interwiki links from inclusion, even if there are interwiki links pointing to it.

Working with the logfile

[編集]

Each run of the interwiki.py program will write not only to the screen, but also to a file called logs/interwiki.log. You may have seen that once a subject is completed, a list of other Wikipedias interwiki links is printed preceded by 'WARNING:'. To use these lines, the interwiki.log file is more convenient than the screen.

All Interwikis to en: missing

First an explanation why this is important. Assume you have a page [[My Subject]] that links to [[fr:Mon Sujet]] and [[nl:Mijn Onderwerp]]. Assume also that neither the nl: nor the fr: page list your en: page: they only know each other. A run of interwiki.py on either fr: or nl: will not find your en: page. This can be referred to as the backlink problem: there can be an unknown language that link to the others, but as long as none of the others link back, there is no way of discovering the existance. Do we really need to add these backlinks manually? No, that is where the warnings come in. In the interwiki.log:

WARNING: fr:[[Mon Sujet]] does not link to [[en:My Subject]]
WARNING: nl:[[Mijn Onderwerp]] does not link to [[en:My Subject]]

If the person running interwiki.py either on fr: or on nl: would have this information, that would be sufficient to get the network of links completed.

For this reason there is another option for the interwiki.py program:

python interwiki.py -warnfile:english_treelang.log

In this mode the program will read the warnfile, and start to process all of the pages that are mentioned for its home language using the "does not link to" lines as hints.

This process can still take a long time. If you trust the operator that sent you the log, and the log is recent, you can also do:

python warnfile.py english_treelang.log

This will not verify any of the suggestions in the warnfile, but blindly implement them at full speed, saving the Wikipedia server a lot of efforts.

Now, instead of sending the whole interwiki.log file to everyone, there is a special program to split it up:

python splitwarning.py

This will read your interwiki.log and create files called warning_XX.log (one for each language) that are more convenient to use. If you zip these files up and make them available somewhere on the internet, you can announce this at Interwiki bot/Warnfiles.

Overview of the options

[編集]

Here is a list of the options, with an explanation of those that have not yet been discussed.

  • -array: (usage: "-array:nn" with nn a number) When working on several pages, make sure to have at least this number of pages the bot is working on, if possible. The default value is 100; when using -untranslatedonly or a similar option, you might want to set it lower.
  • -always: Always save the page, even if only one byte has changed (default: save the page only if at least one link has actually changed)
  • -askhints: Ask hints (see above)
  • -async: Puts the page on a queue to be saved to wiki asynchronously. This enables loading pages during saving throtteling and gives a better performance.
  • -autonomous Work in autonomous mode (see above)
  • -cleanup: When an interwiki link is to be removed, just do it, don't ask for permission. This works like -force except keeping disambiguation mismatch and namespace mismatch unchanged.
  • -confirm Always ask permission before changing a page.
  • -select Ask for each link whether it should be include before changing any page.
  • -days: Work on the days
  • -file: (usage: "-file:filename") Specifies a file containing a list of pages to process. (Page names are specified as [[project:lang:pagename]], [[lang:pagename]], or [[pagename]].
  • -force: When an interwiki link is to be removed, just do it, don't ask for permission
  • -hint: Give a hint (see above)
  • -name: Old option; equivalent to "-hint:all", but capitalizes the last word when trying on eo:. Might get deprecated.
  • -namespace: Number or name of namespace to process. Can be used multiple times. Do not use with the -start parameter (use something like -start:Category:! instead)
  • -neverlink: Do not link to a specific language (see above)
  • -noauto: Do not use automatic translation (see above)
  • -nobacklink: Do not give a list of missing links on pages linked to
  • -nobell: Give no audio sign when asking for input.
  • -noredirect: If the bot finds a page linked to is a redirect, it is skipped (normal behaviour: It follows the redirect)
  • -noshownew: Do not show new links found
  • -number: (usage"-number:nn" with nn a number) In combination with -start, checks only the first nn pages rather than the whole wiki.
  • -same: Old option; equivalent to "-hint:all"; might get deprecated
  • -showpage: When using -askhints or some such option, always show the page text, even if not prompted.
  • -skipfile: (usage "-skipfile:filename") On a run using -start, do not do the pages in the file start
  • -untranslated: Ask hints for untranslated pages (see above)
  • -untranslatedonly: Ask hints for untranslated pages (see above)
  • -warnfile: Use the logfile for pages and hints (see above)
  • -wiktionary: Special wiktionary options (see above)
  • -years: Work on the years

Help:Pywikipedia/Global Options

See also

[編集]

-->