Wikidata:Bota izveide

This page is a translated version of the page Wikidata:Creating a bot and the translation is 34% complete.
Outdated translations are marked like this.

Šī lapa paskaidro kā izveidot botus priekš Wikidata. Lūdzu, apsveriet dalīties ar savu kodu, pievienot jaunus piemērus un jebkādus uzlabojumus.

Prasības

Lai veidotu botus, jums nepieciešams:

  • Nedaudz programmēšanas prasmju (Python, Perl, PHP...)
  • Programmatūras ietvars (viens no zemāk minētajiem) un nedaudz izpildāma koda, lai paveiktu uzdevumu
  • Bota konts (apstiprināts)
  • Izejas koda redaktors (Notepad++, Geany, vi, emacs)

Recommendation

Pywikibot

Nākamajās sadaļās jūs uzzināsiet, kā uzstādīt, konfigurēt un pieslēgties, izmantojot pywikipediabot. Šos pirmos trīs soļus vajadzēs izpildīt tikai vienreiz. Šeit ir arī daži vienkārši piemēri, lai apgūtu botu programmēšanas pamatus.

Uzstādīšana

Plašākai informācijai par pywikibot uzstādīšanu skatīt mw:Manual:Pywikibot/Installation.

Lai uzstādītu pywikipediabot:

Konfigurācija

:Papildu informācijai par pywikibot konfigurēšanu skatiet mw:Manual:Pywikibot/user-config.py.

You must configure user-config.py file with the bot username, family project and language. For Wikidata both family and language parameters are the same, wikidata.

Jūs varat samazināt aizturi starp labojumiem, pievienojot: put_throttle = 1 put_throttle = 1

Pieslēgšanās

Pēc user-config.py faila konfigurēšanas, pieslēgties var ar šo komandu:

$ python login.py

Tiks prasīta bota parole, ievadiet to un spiediet enter. Ja tā bija pareiza, jums būtu jābūt autorizētam.

1. piemērs: Datu iegūšana

1. piemērs: datu iegūšana

Šis piemērs iegūst datus no lapas par Duglasu Adamsu. Saglabājiet šo izejas kodu failā un izpildiet to: python piemers1.py

item.get() pieslēdzas Wikidata un iegūst datus. Rezultāts ir:

{
    'claims': {
        'P646': [<pywikibot.page.Claim instance at 0x7f1880188b48>],
        'P800': [<pywikibot.page.Claim instance at 0x7f1880188488>, <pywikibot.page.Claim instance at 0x7f1880188368>]
        ...
    }
    'labels': {
        'gu': '\u0aa1\u0a97\u0acd\u0ab2\u0abe\u0ab8 \u0a8f\u0aa1\u0aae\u0acd\u0ab8',
        'scn': 'Douglas Adams',
        ...
    }
    'sitelinks': {
        'fiwiki': 'Douglas Adams',
        'fawiki': '\u062f\u0627\u06af\u0644\u0627\u0633 \u0622\u062f\u0627\u0645\u0632',
        'elwikiquote': '\u039d\u03c4\u03ac\u03b3\u03ba\u03bb\u03b1\u03c2 \u0386\u03bd\u03c4\u03b1\u03bc\u03c2',
        ...
    }
    'descriptions': {
        'eo': 'angla a\u016dtoro de sciencfikcio-romanoj kaj humoristo',
        'en': 'English writer and humorist',
    },
    'aliases': {
        'ru': ['\u0410\u0434\u0430\u043c\u0441, \u0414\u0443\u0433\u043b\u0430\u0441'],
        'fr': ['Douglas Noel Adams', 'Douglas No\xebl Adams'],
        ...
    }
}
['claims', 'labels', 'sitelinks', 'descriptions', 'aliases']
[[wikidata:Q42]]

It prints a dictionary with keys for

  • the set of claims in the page: Property:P646 is the Freebase identifier, Property:P800 is "notable work", etc.
  • the label of the item in many languages
  • the sitelinks for the item, not just Wikipedias in many languages, but also Wikiquote in many languages
  • the item description in many languages
  • the aliases for the item in many languages

Then a list with all the keys for the key-values pairs in the dictionary. Finally, you can see that the Wikidata item about Douglas Adams is Q42.

Alternatīvas

The example above gets the ItemPage using the en wikipedia article. Alternatively, we can also get the ItemPage directly:

1. piemērs: Starpviki saišu iegūšana

After item.get(), for example the sitelinks can be accessed. These are links to all Wikipedias that have the article.

Rezultāts ir:

{'fiwiki': 'Douglas Adams', 'eowiki': 'Douglas Adams', 'dewiki': 'Douglas Adams', ...}

With item.iterlinks(), an iterator over all these sitelinks is returned, where each article is given not as plain text as above but already as a Page object for further treatment (e.g., edit the text in the corresponding Wikipedia articles).

4. piemērs: Apraksta uzstādīšana

Šis piemērs uzstāda anglisko un vācisko aprakstu ierakstam par Duglasu Adamsu.

Setting labels and aliases works accordingly.

6. piemērs: Saites uzstādīšana

6. piemērs: Saites uzstādīšana

7. piemērs: Apgalvojuma pievienošana

Statements are set using the Claim class. In the following, we set for Douglas Adams place of birth (P19): Cambridge (Q350).

For other datatypes, this works similar. In the following, we add claims with string (IMDb ID (P345)) and coordinate (coordinate location (P625)) datatypes (URL is the same as string):

Example 8: Add a qualifier

8. piemērs: Ierobežotāja pievienošana

Arī ierobežotājus attēlo Claim klase. Šajā piemērā mēs pievienojam ierobežotāju incertae sedis (P678) family (Q35409) Claim "apgalvojumam".

Example 9: Add a source

9. piemērs: Atsauces pievienošana

Arī atsauces tiek attēlotas ar Claim klasi. Atšķirībā no ierobežotāja, atsauce var saturēt vairāk kā vienu Claim instanci. Piemērā mēs pievienojam stated in (P248) Integrated Taxonomic Information System (Q82575) ar retrieved (P813) 2014. gad 20. martā kā atsauci Claim "apgalvojumam".

10. piemērs: Lapu ģeneratori

TODO

Example 11: Get values of sub-properties

In the following, we get values of sub-properties from branch described by source (P1343) -> Great Soviet Encyclopedia (1969–1978) (Q17378135) -> properties reference URL (P854) and title (P1476).

Vairāk piemēru

Daļa lietotāju dalās ar savu izejas kodu. Uzziniet vairāk nākamajās saitēs:

Wikidata Integrator

WikidataIntegrator is a library for reading and writing to Wikidata/Wikibase. We created it for populating Wikidata with content from authoritative resources on Genes, Proteins, Diseases, Drugs and others. Details on the different tasks can be found on the bot's Wikidata page.

Pywikibot is an existing framework for interacting with the MediaWiki API. The reason why we came up with our own solution is that we need a high integration with the Wikidata SPARQL endpoint in order to ensure data consistency (duplicate checks, consistency checks, correct item selection, etc.). Compared to Pywikibot, WikidataIntegrator currently is not a full Python wrapper for the MediaWiki API but is solely focused on providing an easy means to generate Python-based Wikidata bots.

For more information, documentation, download & installation instructions, see here: https://github.com/SuLab/WikidataIntegrator/

Example Notebook

An example notebook demonstrating an example bot to add therapeutic areas to drug items, including using fastrun mode, checking references, and removing old statements:

http://public-paws.wmcloud.org/46883698/example%20ema%20bot.ipynb

WikibaseIntegrator

Forked from Wikidata Integrator by User:Myst in 2020 and has seen several improvements to the API that makes it even easier to create bots using the library.

For more information, documentation, download & installation instructions, see here: https://github.com/LeMyst/WikibaseIntegrator

Example semi-automatic script

LexUse semi-automatic tool for finding and adding usage examples to lexemes. It's free software written using Python 3 in 2020 Wikidata:LexUse.

Wikibase.NET

Wikibase.NET ir API, kurš aizvieto novecojušo DotNetDataBot. Tie nav savietojami, jo Wikibase.NET vairs nevajag DotNetWikiBot ietvaru.

Lejupielāde un uzstādīšana

Ietvaru var lejupielādēt no GitHub lapas. Sekojiet instrukcijām lapā.

Zināmās problēmas

Piemēri

Drīzumā...

DotNetDataBot (novecojis)

Uzstādīšana

Konfigurācija

After unpacking the package you can see a file called DotNetDataBot.dll and one called DotNetDataBot.xml. The xml document is only for documentation. To use it you have to create a new refer in your project. Then you can write using DotNetDataBot; to import the framework.

Pieslēgšanās

To login you have to create a new Site object with the url of the wiki, your bot's username and its password.

1. piemērs: Id iegūšana no wiki lapas

You can access the id of an item by searching for using the site and the title of the connected page.

2. piemērs: Starpviki saišu iegūšana

You can get the interwiki links of an item by loading the content and accessing the links field of the object.

3. piemērs: Apraksta uzstādīšana

To set a description, you must call the setDescription function.

6. piemērs: Nosaukuma uzstādīšana

It works the same way for setting a label. Just call setLabel.

Example 5: Get interwiki links for 100 pages

This feature is not supported. Just iterate over the list.

Wikibase API priekš PHP

This is an api client for Wikibase written in PHP. It can be downloaded from here.

1. piemērs: Pamata piemērs

Take a look at the source comments to understand how it works.


Example 2: Creating claims

Apskatiet koda komentārus, lai sapratu, kā tas strādā.

VBot (no updates since 2017)

Framework for Wikidata and Wikipedia. Read and write on Wikidata and other Wikimedia project and have a useful list generator to generate list of Wikipedia page and Wikidata entity. Can read also JSON dump of Wikidata.

Overview

Bot to read and edit Wikidata and Wikipedia.

  • License: CC0 1.0
  • Language C#
  • Can read and write entities with all datatype on Wikidata
  • Can read and write pages on all Wiki project
  • Can read parameter from template on wiki pages
  • Can read JSON dump
  • Can create lists using:
  • Tested with Visual Studio Express 2013 for Windows Desktop.
    • Is necessary to have Newtonsoft.Json. You can install it with NuGet inside Visual Studio
    • Is necessary to add manually a reference to System.Web for "HttpUtility.UrlEncode"

Download

The framework can be downloaded from GitHub here.

Instrukcijas

1. piemērs

Update en label for all items with instance of (P31): short film (Q24862) that have director (P57) and that have publication date (P577) in 1908. (Use of Wikidata query)

LexData (Python; for Lexicographical data)

LexData is an easy to use python libary to create and edit Lexemes, Senses and Forms.

Tips

The documentation of LexData is still a bit lacking so look at existing implementations in MachtSinn or Wikdata Lexeme Forms for ideas how to use it.

If you only want to add statements to Lexemes (not forms or senses) WikibaseIntegrator might be a better choice, as it is more versatile and support a lot of data types.

Installation

You can install LexData via pip:

$ pip install LexData

Login

For all operations you need a WikidataSession. You can create it with your credentials, a bot password or an Edit Token (for example to edit via OAUTH):


Retrieve a Lexeme

You can open existing Lexemes and read their content.

Searching and creating Lexemes

If you don't know the L-Id of a lexeme you can search for it. And if it doesn't exist you can create it.

Adding information

You can easily create forms or senses, with or without additional claims:

Vikidatu API izmantošana pa tiešo

The other sections describe how to use bot frameworks to access and update Wikidata information. You can also directly interact with the Wikibase API that Wikidata provides. You need to do this if you're developing your own framework or if you need to do something that a framework doesn't support. The documentation for the Wikibase API can be found at mediawiki.org. You can also play around with it at Special:ApiSandbox, try action=wbgetentities.

Wikibase provides its API as a set of modules for MediaWiki's "action" API. You access this by making HTTP requests to /w/api.php. The default response format is JSON. So for your language of choice, you only need a library to perform HTTP requests and a JSON or XML library to parse the responses.

Example 1: Get Q number

This example gets the item Q number for the English Wikipedia article about Andromeda Galaxy. The Wikibase API's main "workhorse" module action=wbgetentities provides this information. The HTTP request (using jsonfm format for human-readable JSON output) is simply

https://www.wikidata.org/w/api.php?action=wbgetentities&titles=Andromeda%20Galaxy&sites=enwiki&props=&format=jsonfm&formatversion=2

Try following the link. This requests no additional information about the entity; remove &props= from the URL to see much more information about it. See the generated help for wbgetentities for more parameters you can specify.

Python

The output is:

Q2469

Example 2: Get list of items without particular interwiki

...please contribute if you know how...

Skatīt arī

Ārējās saites