Search API Pustaka Pengetahuan Google

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
  • SEARCH_QUERY: String kueri literal untuk penelusuran.
  • LANGUAGES: (Opsional) Daftar kode bahasa (ditetapkan dalam ISO 693) untuk menjalankan kueri. Nilai defaultnya adalah en jika 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.


from __future__ import annotations

from collections.abc import Sequence

from google.cloud import enterpriseknowledgegraph as ekg

# TODO(developer): Uncomment these variables before running the sample.
# project_id = 'YOUR_PROJECT_ID'
# location = 'YOUR_GRAPH_LOCATION'      # Values: 'global'
# search_query = 'YOUR_SEARCH_QUERY'
# languages = ['en']                    # Optional: List of ISO 639-1 Codes
# types = ['']                          # Optional: List of schema.org types to return
# limit = 20                            # Optional: Number of entities to return


def search_sample(
    project_id: str,
    location: str,
    search_query: str,
    languages: Sequence[str] = None,
    types: Sequence[str] = None,
    limit: int = 20,
):
    # Create a client
    client = ekg.EnterpriseKnowledgeGraphServiceClient()

    # The full resource name of the location
    # e.g. projects/{project_id}/locations/{location}
    parent = client.common_location_path(project=project_id, location=location)

    # Initialize request argument(s)
    request = ekg.SearchRequest(
        parent=parent,
        query=search_query,
        languages=languages,
        types=types,
        limit=limit,
    )

    # Make the request
    response = client.search(request=request)

    print(f"Search Query: {search_query}\n")

    # Extract and print date from response
    for item in response.item_list_element:
        result = item.get("result")

        print(f"Name: {result.get('name')}")
        print(f"- Description: {result.get('description')}")
        print(f"- Types: {result.get('@type')}\n")

        detailed_description = result.get("detailedDescription")

        if detailed_description:
            print("- Detailed Description:")
            print(f"\t- Article Body: {detailed_description.get('articleBody')}")
            print(f"\t- URL: {detailed_description.get('url')}")
            print(f"\t- License: {detailed_description.get('license')}\n")

        print(f"- Cloud MID: {result.get('@id')}")
        for identifier in result.get("identifier"):
            print(f"\t- {identifier.get('name')}: {identifier.get('value')}")

        print("\n")

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
  • SEARCH_QUERY: String kueri literal untuk penelusuran.
  • LANGUAGES: (Opsional) Daftar kode bahasa (ditetapkan dalam ISO 693) untuk menjalankan kueri. Nilai defaultnya adalah en jika 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.


from __future__ import annotations

from collections.abc import Sequence

from google.cloud import enterpriseknowledgegraph as ekg

# TODO(developer): Uncomment these variables before running the sample.
# project_id = 'YOUR_PROJECT_ID'
# location = 'YOUR_GRAPH_LOCATION'      # Values: 'global'
# search_query = 'YOUR_SEARCH_QUERY'
# languages = ['en']                    # Optional: List of ISO 639-1 Codes
# types = ['']                          # Optional: List of schema.org types to return
# limit = 20                            # Optional: Number of entities to return


def search_public_kg_sample(
    project_id: str,
    location: str,
    search_query: str,
    languages: Sequence[str] = None,
    types: Sequence[str] = None,
    limit: int = 20,
):
    # Create a client
    client = ekg.EnterpriseKnowledgeGraphServiceClient()

    # The full resource name of the location
    # e.g. projects/{project_id}/locations/{location}
    parent = client.common_location_path(project=project_id, location=location)

    # Initialize request argument(s)
    request = ekg.SearchPublicKgRequest(
        parent=parent,
        query=search_query,
        languages=languages,
        types=types,
        limit=limit,
    )

    # Make the request
    response = client.search_public_kg(request=request)

    print(f"Search Query: {search_query}\n")

    # Extract and print date from response
    for item in response.item_list_element:
        result = item.get("result")

        print(f"Name: {result.get('name')}")
        print(f"- Description: {result.get('description')}")
        print(f"- Types: {result.get('@type')}\n")

        detailed_description = result.get("detailedDescription")

        if detailed_description:
            print("- Detailed Description:")
            print(f"\t- Article Body: {detailed_description.get('articleBody')}")
            print(f"\t- URL: {detailed_description.get('url')}")
            print(f"\t- License: {detailed_description.get('license')}\n")

        print(f"- Cloud MID: {result.get('@id')}")
        for identifier in result.get("identifier"):
            print(f"\t- {identifier.get('name')}: {identifier.get('value')}")

        print("\n")

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
  • LOOKUP_IDS: Daftar ID entity yang akan digunakan untuk pencarian.
    • Contoh: /m/0dl567
  • LANGUAGES: (Opsional) Daftar kode bahasa (ditetapkan dalam ISO 693) untuk menjalankan kueri. Nilai defaultnya adalah en jika 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"
        }
      }
    }
  ]
}
Untuk mencari beberapa entity dari Cloud Knowledge Graph, berikan beberapa ID. URL-nya akan terlihat seperti ini.
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.


from __future__ import annotations

from collections.abc import Sequence

from google.cloud import enterpriseknowledgegraph as ekg

# TODO(developer): Uncomment these variables before running the sample.
# project_id = 'YOUR_PROJECT_ID'
# location = 'YOUR_GRAPH_LOCATION'      # Values: 'global'
# ids = ['YOUR_LOOKUP_MID']             # https://cloud.google.com/enterprise-knowledge-graph/docs/mid
# languages = ['en']                    # Optional: List of ISO 639-1 Codes


def lookup_sample(
    project_id: str,
    location: str,
    ids: Sequence[str],
    languages: Sequence[str] = None,
):
    # Create a client
    client = ekg.EnterpriseKnowledgeGraphServiceClient()

    # The full resource name of the location
    # e.g. projects/{project_id}/locations/{location}
    parent = client.common_location_path(project=project_id, location=location)

    # Initialize request argument(s)
    request = ekg.LookupRequest(
        parent=parent,
        ids=ids,
        languages=languages,
    )

    # Make the request
    response = client.lookup(request=request)

    print(f"Lookup IDs: {ids}\n")

    print(response)

    # Extract and print date from response
    for item in response.item_list_element:
        result = item.get("result")

        print(f"Name: {result.get('name')}")
        print(f"- Description: {result.get('description')}")
        print(f"- Types: {result.get('@type')}\n")

        detailed_description = result.get("detailedDescription")

        if detailed_description:
            print("- Detailed Description:")
            print(f"\t- Article Body: {detailed_description.get('articleBody')}")
            print(f"\t- URL: {detailed_description.get('url')}")
            print(f"\t- License: {detailed_description.get('license')}\n")

        print(f"- Cloud MID: {result.get('@id')}")
        for identifier in result.get("identifier"):
            print(f"\t- {identifier.get('name')}: {identifier.get('value')}")

        print("\n")

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
  • LOOKUP_IDS: Daftar ID entity yang akan digunakan untuk pencarian.
    • Contoh: /m/0dl567
  • LANGUAGES: (Opsional) Daftar kode bahasa (ditetapkan dalam ISO 693) untuk menjalankan kueri. Nilai defaultnya adalah en jika 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"
        }
      }
    }
  ]
}
Untuk mencari beberapa entity dari Cloud Knowledge Graph, berikan beberapa ID. URL-nya akan terlihat seperti ini.
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.


from __future__ import annotations

from collections.abc import Sequence

from google.cloud import enterpriseknowledgegraph as ekg

# TODO(developer): Uncomment these variables before running the sample.
# project_id = 'YOUR_PROJECT_ID'
# location = 'YOUR_GRAPH_LOCATION'      # Values: 'global'
# ids = ['YOUR_LOOKUP_MID']             # https://cloud.google.com/enterprise-knowledge-graph/docs/mid
# languages = ['en']                    # Optional: List of ISO 639-1 Codes


def lookup_public_kg_sample(
    project_id: str,
    location: str,
    ids: Sequence[str],
    languages: Sequence[str] = None,
):
    # Create a client
    client = ekg.EnterpriseKnowledgeGraphServiceClient()

    # The full resource name of the location
    # e.g. projects/{project_id}/locations/{location}
    parent = client.common_location_path(project=project_id, location=location)

    # Initialize request argument(s)
    request = ekg.LookupPublicKgRequest(
        parent=parent,
        ids=ids,
        languages=languages,
    )

    # Make the request
    response = client.lookup_public_kg(request=request)

    print(f"Lookup IDs: {ids}\n")

    print(response)

    # Extract and print date from response
    for item in response.item_list_element:
        result = item.get("result")

        print(f"Name: {result.get('name')}")
        print(f"- Description: {result.get('description')}")
        print(f"- Types: {result.get('@type')}\n")

        detailed_description = result.get("detailedDescription")

        if detailed_description:
            print("- Detailed Description:")
            print(f"\t- Article Body: {detailed_description.get('articleBody')}")
            print(f"\t- URL: {detailed_description.get('url')}")
            print(f"\t- License: {detailed_description.get('license')}\n")

        print(f"- Cloud MID: {result.get('@id')}")
        for identifier in result.get("identifier"):
            print(f"\t- {identifier.get('name')}: {identifier.get('value')}")

        print("\n")

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: