Shortcut: Wikidata:Gentle Query

Wikidata:SPARQL navrae diens/A maklike inleiding na die Wikidata Navrae Diens

From Wikidata
Jump to navigation Jump to search
Outdated translations are marked like this.

A maklike inleiding na die Wikidata Navrae Diens

Het jy al ooit gewonder oor vrae soos?

  • Wat is die grootste stede in die wereld met 'n vroulike burgemeester?
  • Watter lughawens bestaan binne 100km van Berlyn?
  • Wie is al die afstammelings van Genghis Khan?

Wikidata het die antwoorde

Wat is Wikidata?

Wikidata is a argief van kennis. U kan die inleiding vind rondom die idiee en konsepte agter Wikidata by introduction page.

Hoe stel ek 'n vraag?

Die navrae taal wat gebruik word om vrae te vra op Wikidata is genoem SPARQL. As dit te tegnies en oormatig ingewikkeld klink, moenie bekommer nie. Vir hierdie maklike inleiding hoef u nie SPARQL te leer nie. Liewers, gaan ons kyk na bestaande navrae en hoe om dit te wysig.

Wat is 'n navrae?

'n Navrae is 'n spesiaale vorm van vrae vra wat rekenaar stelsels kan verstaan en beantwoord. Tensy jy met 'n kunsmatige intelligensie in wisselwerking tree, moet u leer hoe om jou vrae te formuleer in 'n sekere manier.

Kan ek vrylik hierdie data gebruik?

Defintief. Wikidata kan gebruik word deur enige iemand vir enigiets want al die data is in die Openbare Domein (CCO).

Wat nou?

Ons gaan begin met 'n eenvoudige voorbeeld om jou te wys hoe om hierdie diens te gebruik, en opbou na meer uitgebreide voorbeelde kry jy die antwoord op die fundametele vraag. Belowe.

Hoe om Wikidata te gebruik vir 'n eenvoudige navrae

Kom ons gaan deur 'n eenvoudige voorbeeld wat demonstreer hoe om 'n lys van al die katte in die wereld te kry.

Kry 'n lys van all die katte in die wereld

Gebruik hierdie URL om na die navrae diens te gaan: https://query.wikidata.org

  1. Kliek Voorbeelde
  2. Kies "Cats" vanaf die lys
  3. Kliek Voer soekopdrag uit

Nou het ons 'n lys van al die bekende en onbekende katte op die Internet - of ten minste dié wat Wikidata van weet. Dit is uitstekend, gegewens jy 'n kat persoon is, en nie 'n hond persoon is nie.

Wat van honde?

As jy liewer 'n lys van honde soek (of enigiets anders), is daar twee manier om jy navrae te wysig:

  1. Gebruik die Query Helper om die item te verander.
  2. Wysig die navrae per hand" Elke item op Wikidata is uniek geïdentifiseer deur gebruik van 'n kode. Die kode is Q146 vir "kat". Om die ooreenstemmende kode vir "hond" te vind, u kan dit opsoek op Wikidata:
  1. Gebruik outomatiese aanvulling (sal beskreep word teen die einde)
  2. Begin met "Cat" vorbeeld, verwyder "Q146"
  3. Sit wyser na "wd:"
  4. Tik "Hond" na "wd:"
  5. Druk Ctrl+Space
  6. Gebruik op/af pyle, dan as u enter druk - sal dit vervang word met Q144
"Nota: soek resultate hang af van taal keuse."
  1. Gaan na https://www.wikidata.org
  2. Tik "dog" in die soek veld
  3. Kliek op die eerste resultaat van die keuselys
  4. Let op na die item nommer vir "hond" vanaf die Wikidata blasy what (Q144) oopmaak

Om die navrae vanaf "cat" na "dog" te verander, vervang Q146 met Q144 in die SPARQL navrae redakteur

Gebruik die program, en jy word aangebied met 'n lys van al die bekende en onbekende honde op die internet.

Afbreeking van die navrae

Nou kom ons analiseer die kode om te veralgemeen sodat ons kan soek vir enige iets (byvoorbeeld honde, planeete, lande, liedjies).

#Cats
SELECT ?item ?itemLabel
WHERE
{
	?item wdt:P31 wd:Q146 . 
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
  • SELECT 'n Navrae SELECTs iets. Wat presies jy wil kies en uitbeeld word later verduidelik, maar vir nou kies net die plekhouers (of veranderlikes). Dit word genoem ?item en ?itemLabel

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 . Dit is die voorwerp. As jy oor dit hover, sal jy sien dit staan vir kat.

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

Al hierdie is 'n mondvol. Dit mag help om die navrae uit te druk in natuurlike taal.

"" Gee vir my 'n lys van items en hul etikete, waar die etikete gevalle is van kat. Dan genereer die etikete na die items in Engels.""

Met die kode wat ons gebruik het in ons voorbeelde on kry 'n lys van al die bekende en onbekende katte op die Internet. Hierdie navrae kan maklik verander wees om 'n bekende lys van honde te wys, byvoorbeeld.

Teks tot SPARQL voorbeeld

Hierdie beelde wys hoe om menslike taal drielinge, en verander hulle in SPARQL navrae:

Die geheim in om veranderlikes voorvoeg met ?, items met wd: en eienskappe met wdt:, en dan gebruik die Ctrl+Space sleutelbord kortpad om automaties die Wikidata identifiseerders in te vul.

Duik in die Gebruiker Interface

Hoe om die taal te verander wat die resultate in gewys word?

Met hierdie soek navrae gereedskep, mens kan nie net aanpas en soek vir eenvoudige of saamgestelde, of komplekse navrae nie, maar u kan ook soek in ENIGE taal en die resultate kry in enige taal ook.

  • Verander die standaard taal kode vanaf "en" (Engels) na enige ander taal kode, byvoorbeeld "ja" vir Japanese.
#Cats  
SELECT ?item ?itemLabel WHERE
{
     ?item wdt:P31 wd:Q146 .
     SERVICE wikibase:label { bd:serviceParam wikibase:language "ja" }
}

Hoe om die sorteer orde van die resultaate te verander

Die orde van die items wat gewys word kan maklik verander word in die interface. Kliek net op die relevante kolome van die soek resultaate om die sorteer orde aan te pas.

Hoe om die taal van die UI te verander

Kliek die woord Engels en kies die taal van die lys wat gewys word:

Sien hoe die UI verander het na die gekiesde taal:

= Maar ek soek beelde van katte! Hoe soek ek vir sulke beelde?

So ver, ons het die uitset van die navrae gestel as 'n tabel. Kom ons probeer 'n paar beelde:

Kliek die "Voorbeelde" knoppie en kies die "Even more cats, with pictures" voorbeeld. Gebruik die navrae en kat beelde behoort te wys op die onderste helfte van die skerm.

Hierdie is wat die resultaat wys van beelde in plaas van tafel. Jy kan per hand verander hoe die data uitgebeeld word deur die "Display" keuselys in die laer regs hoek van die resultaate. Probeer die keuselys verander na "Table" om dieselfde resultaate te sien in tabel vorm.

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.

Hoe om jou navrae met ander te deel?

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.

Finding things on maps

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.


Using the Explorer Dialog

Once the results of a query have loaded, you can see a magnifying glass icon on each result.

Clicking this icon opens the Explorer Dialog.

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.

There is even more

There are more visualizations for you to explore:

Look through the query examples and try them out!

Autocompletion

In the editor, you can press Ctrl+Space at any point in the query and get suggestions for code that might be appropriate; select the right suggestion with the up/down arrow keys, and press Enter to select it.

For example, instead of writing out SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } every time, you can just type SERV, hit Ctrl+Space, and the first suggestion will be that complete label service incantation, ready for use! Just hit Enter to accept it. (The formatting will be a bit different, but that doesn’t matter.)

And autocompletion can also search for you. If you type one of the Wikidata prefixes, like wd: or wdt:, and then just write text afterwards, Ctrl+Space will search for that text on Wikidata and suggest results. wd: searches for items, wdt: for properties. For example, instead of looking up the items for Johann Sebastian Bach (Q1339) and father (P22), you can just type wd:Bach and wdt:fath and then just select the right entry from the autocompletion. (This even works with spaces in the text, e. g. wd:Johann Sebastian Bach.)

NB: For ChromeOS and MacOS users: the shortcuts Ctrl+Alt+Space and Alt+Enter should also work.

Where to go from here

You can probably find your way around the Wikidata Query Service now. Exploring the interface and changing values in the queries can be a good way to learn how to ask your own questions on Wikidata.