Shortcut: Wikidata:Gentle Query

Wikidata: layanan kueri SPARQL/Pengenalan sederhana untuk Layanan Kueri Wikidata

From Wikidata
Jump to navigation Jump to search

Pengenalan sederhana untuk Layanan Kueri Wikidata

Pernahkah Anda bertanya-tanya dan penasaran dengan pertanyaan berikut?

  • Kota-kota besar manakah di dunia ini yang mempunyai walikota perempuan?
  • Bandara apa saja yang terletak di seputar Berlin dengan jangkauan maksimal 100 km?
  • Siapa saja keturunan dari Genghis Khan?

Wikidata punya jawabannya.

Apa itu Wikidata?

Wikidata adalah gudang penyimpanan pengetahuan. Anda bisa membaca bagian pendahuluan yang menjelaskan ide dan gagasan di balik Wikidata pada halaman pendahuluan.

Bagaimana saya menanyakan pertanyaan?

Bahasa kueri yang dipergunakan untuk menanyakan menanyakan pertanyaan seperti itu disebut SPARQL dalam Wikidata. Jika istilah ini terasa sangat teknis dan cukup rumit, jangan khawatir. Pada halaman pengenalan sederhana ini, Anda tidak harus belajar SPARQL. Sebaliknya, kita akan coba meninjau contoh kueri yang sudah ada dan bagaimana cara menyunting kueri tersebut.

Apakah kueri itu?

Kueri merupakan bentuk khusus dari suatu pertanyaan yang dipahami dan bisa dijawab oleh sistem komputer. Kecuali kalau Anda berinteraksi dengan Kecerdasan Buatan (AI), Anda harus belajar bagaimana cari menyusun pertanyaan dengan cara tertentu.

Apakah saya bisa mempergunakan data ini secara gratis?

Tentu saja. Wikidata dapa dipergunakan oleh siapa saja dan untuk apa saja karena semua data berlisensi publik (CC0).

Sekarang apa?

Kita akan mulai dengan contoh sederhana untuk menunjukkanmu bagaimana cara menggunakan layanan ini dan selagi kita membuat contoh yang lebih rinci, kamu akan mendapatkan jawaban pertanyaan yang mendasar. sumpah.

Bagaimana menggunakan Wikidata untuk kueri sederhana

Mari kita telusuri contoh sederhana yang mendemonstrasikan bagaimana mendapatkan daftar semua kucing yang diketahui di dunia.

Mendapatkan daftar semua kucing di dunia

Gunakan URL ini untuk ke layanan Kueri: https://query.wikidata.org

  1. Klik Examples
  2. Pilih Cats dari daftar yang muncul di jendela baru
  3. Klik tombol Run di bawah kotak kode

Kita akan dapatkan daftar semua kucing yang terkenal di internet – atau paling tidak yang diketahui Wikidata. Ini hebat, kalau kamu termasuk penyuka kucing dan sebut saya bukan penyuka anjing.

Bagaimana dengan anjing?

Jika Anda ingin mengganti daftar dengan pencarian anjing (atau yang lainnya), ada dua cara untuk mengedit kueri Anda:

  1. Gunakan Query Helper untuk mengubah item dari cat ke zoo:
  2. Mengedit kueri secara manual Setiap butir di Wikidata diidentifikasi secara unik menggunakan kode. Kode ini adalah Q146 untuk "kucing". Untuk menemukan kode yang sesuai untuk "anjing", Anda dapat mencarinya di Wikidata:
  1. Gunakan pelengkapan otomatis (akan dibahas di bagian akhir)
  2. Mulai dengan contoh "Cat", hapus "Q146"
  3. Tempatkan kursor setelah "wd:"
  4. Ketik "Anjing" setelah "wd:"
  5. Tekan Ctrl + Spasi
  6. Gunakan panah atas / bawah; ketika Anda menekan Enter - itu akan diganti dengan Q144
    Catatan: hasil pencarian tergantung pada bahasa antarmuka.
  1. Buka https://www.wikidata.org
  2. Ketik "anjing" di kotak pencarian
  3. Klik pada hasil pertama dari menu drop-down
  4. Catat nomor item untuk "anjing" dari halaman Wikidata yang terbuka (Q144)

Untuk mengubah kueri Anda dari "cat" menjadi "dog", cukup ganti Q146 dengan Q144 di editor kueri SPARQL.

Jalankan program, dan Anda akan melihat daftar semua anjing terkenal dan terkenal di Internet.

Membongkar kueri

Sekarang mari kita anasisa kode untuk menggeneralisasi ini sehingga kita dapat mencari objek apa pun (misalnya, anjing, planet, negara, lagu):

#Cats
SELECT ?item ?itemLabel
WHERE
{
	?item wdt:P31 wd:Q146 . 
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
  • SELECT Sebuah kueri memilih (select) sesuatu. What exactly you want to select and display is described later, but for the time being you just state the placeholders (or variables). Here they are called ?item and ?itemLabel. You can tell that something is a variable if it starts with a question mark.
  • ?item This is the list of items we are looking for.

In our case that would be the famous cats. Items on Wikidata work in many different languages, almost 300 of them. Because we don’t think that everything in the world is English and all the other languages are just special cases of English, items are stored in a way that works across languages. Every concept gets a number. Q146 is the concept of a cat, Q64 is Berlin in Germany, Q42 is the writer Douglas Adams and so on. Tip: ?item is just a variable name that we decided to use in our query. It could be anything, for example: ?animal.

  • ?itemLabel Humans can digest names in a human language much better than numbers.

A label is the name of an item in a human language, e.g. English (or Esperanto, or Japanese, or Zulu…). We want the labels displayed in our query so that Q1371145 gets displayed as “Socks” (the cat belonging to Bill Clinton and family). Precise details about label service in User manual.

  • WHERE {   This is the WHERE clause of the query.

Here we define what goes in the placeholders. A WHERE clause starts with an opening curly bracket { and ends with a closing curly bracket }.

  • wdt:P31 This is the predicate of the subject.

If you hover over it, you’ll see that it stands for instance of.

  • wd:Q146 . Ini adalah objeknya. Jika kamu menggerakkan tetikus ke atasnya, kamu akan melihat bahwa butir ini adalah penanda untuk kucing.

All this is quite a mouthful. It may help to express the query in natural language:

“Give me a list of items and their labels, where the items are instances of cat. Then generate the labels to the items in English.”

With the code we used in our examples we showed you a list of all the famous and infamous cats on the Internet. This query can easily be changed to show a similar list for dogs, for example.

Menelusuri Teks ke SPARQL

The animations below show how to write triplets in natural language, and convert them into SPARQL queries.

The key is to prefix variables with ?, items with wd: and properties with wdt:, and then using the Ctrl+Space (or Ctrl+Alt+Space or Alt+Enter) keyboard shortcut to activate the auto-completion feature that replaces the latter two with the actual Wikidata identifiers.

Menyelami antarmuka

Bagaimana cara mengubah bahasa yang digunakan untuk menampilkan hasil?

With this search query tool, you can not only customise and search for simple or aggregated, compound, nested and complex queries but you can also search in ANY language and get results in ANY language too.

  • Change the default language code from “en” (English) to any other language code, say “ja” for Japanese.
#Cats  
SELECT ?item ?itemLabel WHERE
{
     ?item wdt:P31 wd:Q146 .
     SERVICE wikibase:label { bd:serviceParam wikibase:language "ja" }
}

Bagaimana cara mengubah urutan tampilan hasil?

The order of the items displayed can be easily changed in the interface. Just click on the relevant columns of the search results to customise the sorting order:

Bagaimana cara mengubah bahasa antarmuka?

Click the word English and select the language from the list displayed:

Notice the UI has changed to the selected language:

Tapi saya mau foto-foto kucing! Bagaimana cara mencari gambar?

So far, we’ve seen the output of the queries displayed as a table. Let’s try for some images:

Click the “Examples” button and select the “Even more cats, with pictures” example. Run the query and cat images should pop up at the lower half of the screen.

This is what displays the result as images instead of a table. You can manually switch how the data is displayed by using the “Display” menu in the lower right corner of the result. Try switching the menu to “Table” to see the same result in a table view.

Let’s have a look at what’s new in the query, compared to the query in the previous chapter. Written in plain English, the query would read “Give me all items that have something to do with cats. Also give me the image for each item. And by the way, display the result as a grid of images, not as a table.”

  • #defaultView:ImageGrid What looks like a comment, is actually an instruction to display the query result as images instead of a table.
  • ?x1 This means that we query for any predicate, not only for “is an instance of”. Think of predicates like “depicts” (P180) or “is named after” (P138). We are not using ?x1 anywhere else in the query, meaning the placeholder stands for “I don’t care what the predicate is, give me all results that somehow have a cat as the subject”
  • OPTIONAL Inside the curly braces you see another statement that adds optional data to the result. The placeholder ?item is reused and coupled with the predicate P18 (meaning “(has) image” and a new placeholder ?pic. Wrapping the statement with OPTIONAL means that items do not necessarily have to have a P18 predicate to show up in the list and that the ?pic placeholder can be empty.

Try modifying the query:

  • Search for dogs instead of cats. Hint: Change the Object part of the first statement in WHERE.
  • Only show items that “depict” cats (you’ll get paintings). Hint: replace ?x1 with something else.
  • Remove the OPTIONAL

There are other ways to show your data, but not all of them are always applicable, which is why some are greyed out in the menu. “Image map” is only selectable if the result data actually contains image URLs. In one of the following chapters you’ll learn how to display items as points on a map.

Bagaimana cara membagi kuerimu untuk digunakan orang lain?

If you want to share your query with someone else – say, on social media – you can create a short link for your query.

  • Complete your query
  • Click the LINK icon:
  • Copy the URL listed there. This is the URL for the query.

Menemukan sesuatu pada peta

There are more ways to visualize the query results. If the query asks for geocoordinates, the results can be displayed on a map.

Look at this example of lighthouses in Norway. When you run the query, you’ll see red dots that mark the location of lighthouses on the Norwegian coast.


Menggunakan Explorer Dialog

Setelah hasil kueri dimuat, Anda dapat melihat ikon kaca pembesar di setiap hasil. Menekan ikon ini akan membuka Dialog Explorer.

The explorer dialog by default, displays a single node representing that particular result. Below the node, you can see a toggle that defaults to ‘Outgoing’.

This means that clicking on any node will expand all the properties of that node, from the entire Wikidata knowledge base. Toggling this to ‘Incoming’ allows you to see all the incoming links or properties that point to the node. This is a way to explore all the relationships between the various items and their properties using Wikidata.

You can open multiple explorer dialogs at once, allowing you to compare the results of more than one query at once.

The explorer dialog also has a toolbar at the bottom right corner which is used to switch between multiple views like Graph, Tree, Map, Table etc.

Bahkan masih ada lagi

Ada lebih banyak visualisasi untuk Anda jelajahi:

Lihatlah contoh-contoh kueri dan cobalah!

Otolengkap

Di editor, Anda dapat menekan Ctrl+Space di titik mana saja dalam kueri dan mendapatkan saran untuk kode yang mungkin sesuai; pilih saran yang tepat dengan up/kbd>/down arah panah, dan tekan Enter untuk memilihnya.

Sebagai contoh, alih-alih selalu menulis SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }, kamu cukup mengetik SERV, tekan Ctrl+Spasi, dan saran pertama adalah rapalan layanan yang lengkap dan siap digunakan! Cukup tekan Enter untuk memakainya. (pemformatannya mungkin berbeda tapi itu tidak masalah.)

Pelengkap otomatis juga bisa mencarikan untukmu. Jika kamu ketikkan salah satu prefiks Wikidata seperti wd: atau wdt: dan tulis teks setelahnya, Ctrl+Spasi akan mencari teks tersebut pada Wikidata dan menyarankan hasilnya. wd: mencari butir sedangkan wdt: untuk atribut. Sebagai contoh, alih-alih mencari butir untuk Johann Sebastian Bach (Q1339) dan father (P22), kamu cukup mengetikkan wd:Bach dan wdt:bapak kemudian pilih saran yang paling pas dari pelengkap. (Hal ini juga berlaku pada teks yang mengandung spasi seperti wd:Johann Sebastian Bach.) Template:Dilacak NB: Untuk pengguna ChromeOS dan MacOS: pintasan kbd>Ctrl+Alt+Spasi dan Alt+Enter juga harus berfungsi.

Kemana setalah ini

Anda mungkin dapat menemukan cara Anda sendiri tentang Layanan Kueri Wikidata sekarang. Menjelajahi antarmuka dan mengubah nilai dalam kueri bisa jadi adalah cara yang baik untuk mempelajari bagaimana mengajukan pertanyaan Anda sendiri di Wikidata