Panduan memulai ini memperkenalkan Anda pada Google Knowledge Graph Search API. Dalam panduan memulai ini, gunakan API untuk menelusuri atau mencari entity di Grafik Pengetahuan Google.
Jika Anda merencanakan project baru, bangun aplikasi dengan Cloud Knowledge Graph Advanced edition untuk memanfaatkan fitur baru dan peningkatan layanan. Edisi Basic tetap tersedia, tetapi tidak mendukung fitur baru, QPS tinggi, atau standar keamanan dan kepatuhan tambahan.
Menelusuri entitas Cloud Knowledge Graph
Contoh berikut menunjukkan cara menelusuri entitas terhadap grafik pengetahuan.
Lanjutan
REST
Untuk menelusuri grafik pengetahuan untuk edisi Lanjutan, panggil metode projects.locations.cloudKnowledgeGraphEntities.search.
Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:
- PROJECT_ID: Project ID Google Cloud Anda.
- LOCATION: Lokasi Grafik Pengetahuan.
- Opsi:
global- Endpoint Global
- Opsi:
- SEARCH_QUERY: String kueri literal untuk penelusuran.
- LANGUAGES: (Opsional) Daftar kode bahasa (ditetapkan dalam ISO 693) untuk menjalankan kueri. Nilai defaultnya adalah
enjika tidak ditentukan. - TYPES: (Opsional) Membatasi entitas yang ditampilkan dengan jenis ini, seperti yang ditentukan oleh `https://schema.org`. Jika beberapa jenis ditentukan, entitas yang ditampilkan akan berisi satu atau beberapa jenis ini. Nilai defaultnya kosong, yang akan menampilkan entity tanpa batasan jenis. Lihat Hierarki lengkap Schema.org untuk jenis yang didukung.
- LIMIT: (Opsional) Membatasi jumlah entitas yang akan ditampilkan. Defaultnya adalah
20.
Metode HTTP dan URL:
GET https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cloudKnowledgeGraphEntities:Search?query=SEARCH_QUERY&limit=LIMIT
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Jalankan perintah berikut:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cloudKnowledgeGraphEntities:Search?query=SEARCH_QUERY&limit=LIMIT"
PowerShell
Jalankan perintah berikut:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cloudKnowledgeGraphEntities:Search?query=SEARCH_QUERY&limit=LIMIT" | Select-Object -Expand Content
Respons berisi daftar entity, yang ditampilkan dalam format JSON-LD dan kompatibel dengan skema schema.org dengan ekstensi eksternal terbatas.
Lihat Struktur Respons Entitas untuk mengetahui informasi selengkapnya tentang struktur respons.
Contoh JSON-LD berikut menunjukkan cara isi respons disusun:
{
"@context": {
"@vocab": "http://schema.org/"
},
"@type": "ItemList",
"itemListElement": [
{
"result": {
"@id": "c-07xuup16g",
"name": "Stanford University",
"description": "Private university in Stanford, California",
"detailedDescription": {
"articleBody": "Stanford University, officially Leland Stanford Junior University, is a private research university in Stanford, California. The campus occupies 8,180 acres, among the largest in the United States, and enrolls over 17,000 students. ",
"url": "https://en.wikipedia.org/wiki/Stanford_University",
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
},
"url": "http://www.stanford.edu/",
"image": {
"contentUrl": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTfPPf-ker0y_892m1wu8-U89furQgQ67foDFncY3r9sREpeWxV",
"url": "https://es.wikipedia.org/wiki/Archivo:Logo_of_Stanford_University.png"
},
"identifier": [
{
"@type": "PropertyValue",
"propertyID": "googleKgMID",
"value": "/m/06pwq"
},
{
"@type": "PropertyValue",
"propertyID": "googlePlaceID",
"value": "ChIJneqLZyq7j4ARf2j8RBrwzSk"
},
{
"@type": "PropertyValue",
"propertyID": "wikidataQID",
"value": "Q41506"
}
],
"@type": [
"Place",
"Organization",
"MovieTheater",
"Corporation",
"EducationalOrganization",
"Thing",
"CollegeOrUniversity"
]
}
}
]
}
Python
Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Enterprise Knowledge Graph Python API.
Untuk melakukan autentikasi ke Enterprise Knowledge Graph, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Dasar
REST
Untuk menelusuri grafik pengetahuan untuk edisi Basic, panggil metode projects.locations.publicKnowledgeGraphEntities.search.
Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:
- PROJECT_ID: Project ID Google Cloud Anda.
- LOCATION: Lokasi Grafik Pengetahuan.
- Opsi:
global- Endpoint Global
- Opsi:
- SEARCH_QUERY: String kueri literal untuk penelusuran.
- LANGUAGES: (Opsional) Daftar kode bahasa (ditetapkan dalam ISO 693) untuk menjalankan kueri. Nilai defaultnya adalah
enjika tidak ditentukan. - TYPES: (Opsional) Membatasi entitas yang ditampilkan dengan jenis ini, seperti yang ditentukan oleh `https://schema.org`. Jika beberapa jenis ditentukan, entitas yang ditampilkan akan berisi satu atau beberapa jenis ini. Nilai defaultnya kosong, yang akan menampilkan entity tanpa batasan jenis. Lihat Hierarki lengkap Schema.org untuk jenis yang didukung.
- LIMIT: (Opsional) Membatasi jumlah entitas yang akan ditampilkan. Defaultnya adalah
20.
Metode HTTP dan URL:
GET https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publicKnowledgeGraphEntities:Search?query=SEARCH_QUERY&limit=LIMIT
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Jalankan perintah berikut:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publicKnowledgeGraphEntities:Search?query=SEARCH_QUERY&limit=LIMIT"
PowerShell
Jalankan perintah berikut:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publicKnowledgeGraphEntities:Search?query=SEARCH_QUERY&limit=LIMIT" | Select-Object -Expand Content
Respons berisi daftar entity, yang ditampilkan dalam format JSON-LD dan kompatibel dengan skema schema.org dengan ekstensi eksternal terbatas.
Lihat Struktur Respons Entitas untuk mengetahui informasi selengkapnya tentang struktur respons.
Contoh JSON-LD berikut menunjukkan cara isi respons disusun:
{
"@context": {
"@vocab": "http://schema.org/"
},
"@type": "ItemList",
"itemListElement": [
{
"result": {
"@id": "c-07xuup16g",
"name": "Stanford University",
"description": "Private university in Stanford, California",
"detailedDescription": {
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License",
"url": "https://en.wikipedia.org/wiki/Stanford_University",
"articleBody": "Stanford University, officially Leland Stanford Junior University, is a private research university in Stanford, California. The campus occupies 8,180 acres, among the largest in the United States, and enrolls over 17,000 students. "
},
"url": "http://www.stanford.edu/",
"identifier": [
{
"@type": "PropertyValue",
"propertyID": "googleKgMID",
"value": "/m/06pwq"
}
],
"image": {
"contentUrl": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTfPPf-ker0y_892m1wu8-U89furQgQ67foDFncY3r9sREpeWxV",
"url": "https://es.wikipedia.org/wiki/Archivo:Logo_of_Stanford_University.png"
},
"@type": [
"EducationalOrganization",
"CollegeOrUniversity",
"Thing",
"Place",
"Corporation",
"MovieTheater",
"Organization"
]
}
}
]
}
Python
Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Enterprise Knowledge Graph Python API.
Untuk melakukan autentikasi ke Enterprise Knowledge Graph, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Mencari entitas dari MID Cloud Knowledge Graph
Google Knowledge Graph Search API memperkenalkan format ID mesin (MID) baru untuk memudahkan integrasi produk dan aplikasi. API lookup berfungsi untuk MID Cloud Knowledge Graph baru (dimulai dengan c-), serta MID Google Knowledge Graph (dimulai dengan /m).
Lanjutan
REST
Untuk mencari entity menurut MID untuk edisi Lanjutan, panggil metode projects.locations.cloudKnowledgeGraphEntities.lookup.
Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:
- PROJECT_ID: Project ID Google Cloud Anda.
- LOCATION: Lokasi Grafik Pengetahuan.
- Opsi:
global- Endpoint Global
- Opsi:
- LOOKUP_IDS: Daftar ID entity yang akan digunakan untuk pencarian.
- Contoh:
/m/0dl567
- Contoh:
- LANGUAGES: (Opsional) Daftar kode bahasa (ditetapkan dalam ISO 693) untuk menjalankan kueri. Nilai defaultnya adalah
enjika tidak ditentukan.
Metode HTTP dan URL:
GET https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cloudKnowledgeGraphEntities:Lookup?ids=LOOKUP_IDS
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Jalankan perintah berikut:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cloudKnowledgeGraphEntities:Lookup?ids=LOOKUP_IDS"
PowerShell
Jalankan perintah berikut:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cloudKnowledgeGraphEntities:Lookup?ids=LOOKUP_IDS" | Select-Object -Expand Content
Respons berisi daftar entity, yang ditampilkan dalam format JSON-LD dan kompatibel dengan skema schema.org dengan ekstensi eksternal terbatas.
Lihat Struktur Respons Entitas untuk mengetahui informasi selengkapnya tentang struktur respons.
Contoh JSON-LD berikut menunjukkan cara isi respons disusun:
{
"@context": {
"@vocab": "http://schema.org/"
},
"@type": "ItemList",
"itemListElement": [
{
"result": {
"description": "American singer-songwriter",
"@type": [
"Person",
"Thing"
],
"name": "Taylor Swift",
"@id": "c-0260160kc",
"url": "http://www.taylorswift.com/",
"identifier": [
{
"@type": "PropertyValue",
"propertyID": "googleKgMID",
"value": "/m/0dl567"
},
{
"@type": "PropertyValue",
"propertyID": "wikidataQID",
"value": "Q26876"
}
],
"detailedDescription": {
"articleBody": "Taylor Alison Swift is an American singer-songwriter. Her discography spans multiple genres and her narrative songwriting—often inspired by her personal life—has received critical praise and widespread media coverage. ",
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License",
"url": "https://en.wikipedia.org/wiki/Taylor_Swift"
},
"image": {
"contentUrl": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSnsjOArwgD-bhyRslj_Qa7Z2tIPLRFU3VnEuLr1ybcyned49Pt",
"url": "https://pt.wikipedia.org/wiki/Ficheiro:191125_Taylor_Swift_at_the_2019_American_Music_Awards_(cropped).png"
}
}
}
]
}
https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cloudKnowledgeGraphEntities:Lookup?ids=LOOKUP_IDS&ids=LOOKUP_IDS
Python
Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Enterprise Knowledge Graph Python API.
Untuk melakukan autentikasi ke Enterprise Knowledge Graph, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Dasar
REST
Untuk mencari entity menurut MID untuk edisi Basic, panggil metode projects.locations.publicKnowledgeGraphEntities.lookup.
Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:
- PROJECT_ID: Project ID Google Cloud Anda.
- LOCATION: Lokasi Grafik Pengetahuan.
- Opsi:
global- Endpoint Global
- Opsi:
- LOOKUP_IDS: Daftar ID entity yang akan digunakan untuk pencarian.
- Contoh:
/m/0dl567
- Contoh:
- LANGUAGES: (Opsional) Daftar kode bahasa (ditetapkan dalam ISO 693) untuk menjalankan kueri. Nilai defaultnya adalah
enjika tidak ditentukan.
Metode HTTP dan URL:
GET https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publicKnowledgeGraphEntities:Lookup?ids=LOOKUP_IDS
Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:
curl
Jalankan perintah berikut:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publicKnowledgeGraphEntities:Lookup?ids=LOOKUP_IDS"
PowerShell
Jalankan perintah berikut:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publicKnowledgeGraphEntities:Lookup?ids=LOOKUP_IDS" | Select-Object -Expand Content
Respons berisi daftar entity, yang ditampilkan dalam format JSON-LD dan kompatibel dengan skema schema.org dengan ekstensi eksternal terbatas.
Lihat Struktur Respons Entitas untuk mengetahui informasi selengkapnya tentang struktur respons.
Contoh JSON-LD berikut menunjukkan cara isi respons disusun:
{
"@context": {
"@vocab": "http://schema.org/"
},
"@type": "ItemList",
"itemListElement": [
{
"result": {
"description": "American singer-songwriter",
"@type": [
"Person",
"Thing"
],
"name": "Taylor Swift",
"@id": "c-0260160kc",
"url": "http://www.taylorswift.com/",
"identifier": [
{
"@type": "PropertyValue",
"propertyID": "googleKgMID",
"value": "/m/0dl567"
}
],
"detailedDescription": {
"articleBody": "Taylor Alison Swift is an American singer-songwriter. Her discography spans multiple genres and her narrative songwriting—often inspired by her personal life—has received critical praise and widespread media coverage. ",
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License",
"url": "https://en.wikipedia.org/wiki/Taylor_Swift"
},
"image": {
"contentUrl": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSnsjOArwgD-bhyRslj_Qa7Z2tIPLRFU3VnEuLr1ybcyned49Pt",
"url": "https://pt.wikipedia.org/wiki/Ficheiro:191125_Taylor_Swift_at_the_2019_American_Music_Awards_(cropped).png"
}
}
}
]
}
https://enterpriseknowledgegraph.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publicKnowledgeGraphEntities:Lookup?ids=LOOKUP_IDS&ids=LOOKUP_IDS
Python
Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Enterprise Knowledge Graph Python API.
Untuk melakukan autentikasi ke Enterprise Knowledge Graph, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.
Struktur Entitas
| Nama kolom | Jenis | Deskripsi |
|---|---|---|
@id |
string |
URI kanonis untuk entity. |
name |
string |
Nama entity. |
@type |
array |
Daftar jenis schema.org yang didukung dan cocok dengan entitas. |
description |
string |
Deskripsi singkat entitas. |
image |
URL |
Gambar untuk membantu mengidentifikasi entitas. |
detailedDescription |
string |
Deskripsi mendetail tentang entitas. |
url |
URL |
URL situs resmi entitas, jika tersedia. |
identifier |
array |
Daftar ID tertaut lainnya, misalnya WikidataQID. |
Kata kunci JSON-LD
Lihat spesifikasi JSON-LD untuk kata kunci JSON-LD seperti:
Kompatibilitas schema.org
Untuk setiap jenis Schema.org (seperti Person) dan properti (seperti
name), ada URI lengkap yang sesuai, seperti dalam contoh berikut:
| Class | Nama | URI |
|---|---|---|
| jenis | Person |
https://schema.org/Person |
| jenis | Thing |
https://schema.org/Thing |
| properti | name |
https://schema.org/name |
| properti | description |
https://schema.org/description |
Ekstensi skema
Jenis dan properti yang digunakan dalam API ini dihosting di
https://schema.googleapis.com
sebagai ekstensi eksternal.
Dokumentasi untuk setiap jenis dan properti tersedia di URI yang sesuai.
| Class | Nama | URI |
|---|---|---|
| jenis | EntitySearchResult |
https://schema.googleapis.com/EntitySearchResult |
| properti | detailedDescription |
https://schema.googleapis.com/detailedDescription |
Entitas Pustaka Pengetahuan
Pustaka Pengetahuan memiliki jutaan entri yang mendeskripsikan entitas dunia nyata seperti orang, tempat, dan berbagai hal. Entitas ini membentuk node grafik.
Berikut adalah beberapa jenis entity umum yang ditemukan di Cloud Knowledge Graph:
BookBookSeriesEducationalOrganizationEventGovernmentOrganizationLocalBusinessMovieMovieSeriesMusicAlbumMusicGroupMusicRecordingOrganizationPeriodicalPersonPlaceSportsTeamTVEpisodeTVSeriesVideoGameVideoGameSeriesWebSite