Tüm Ürünler
Search
Belge Merkezi

Intelligent Media Management:Dosya meta verilerini sorgulama

Son Güncelleme:Oct 05, 2026

Meta veri dizinini oluşturduktan sonra, Intelligent Media Management (IMM) API işlemlerini çağırarak bir veya daha fazla dosyanın meta verilerini sorgulayabilirsiniz. Ayrıca alan bazlı aramalar, bulanık anahtar kelime aramaları veya doğal dil anahtar kelime aramaları kullanarak meta verileri sorgulayabilirsiniz. Bu konuda dosya meta verilerinin nasıl sorgulanacağı açıklanmaktadır.

Ön koşullar

Kullanım senaryonuz doğrultusunda dosyalarınız için bir meta veri dizini oluşturmuş olmanız gerekir. Daha fazla bilgi için bkz. Meta veri dizini oluşturma.

Sorgulama yöntemleri

Aşağıdaki tabloda dosya meta verilerini sorgulamak için kullanabileceğiniz yöntemler açıklanmaktadır.


Yöntem


Açıklama


Tek bir dosyanın meta verilerini sorgulama


Tek bir dosyanın meta verilerini sorgulamak için GetFileMeta işlemini çağırın.


Birden çok dosyanın meta verilerini sorgulama


Bir seferde birden çok dosyanın meta verilerini almak için BatchGetFileMeta işlemini çağırın.


Basit sorgu gerçekleştirme

Belirtilen koşulları karşılayan dosyaları sorgulamak ve meta verileri belirli bir sıralama düzenine göre alana göre listelemek için SimpleQuery işlemini çağırın.

Ayrıca iç içe geçmiş sorgular kullanarak karmaşık sorgular gerçekleştirebilir ve farklı alanların değerlerini istatistiksel olarak analiz etmek için toplama işlemleri yapabilirsiniz. Desteklenen alanların ve operatörlerin listesi için bkz. Desteklenen alanlar ve operatörler.


Bulanık arama gerçekleştirme

Belirtilen dizeyle eşleşen dosyaları sorgulamak ve dosya meta verilerini listelemek için FuzzyQuery işlemini çağırın.

IMM, dosya adı, etiket, yol veya özel etiket gibi çıkarılan meta veri alanları içinde belirtilen dizeyi arar. Bir dosyanın meta veri alanı değerlerinden biri belirtilen dizeyle eşleşirse söz konusu dosyanın tüm meta verileri döndürülür.


Doğal dil anahtar kelime araması gerçekleştirme

Doğal dil anahtar kelimelerini kullanarak bir veri kümesindeki meta verileri sorgulamak için SemanticQuery işlemini çağırın.

İşlem, Labels, ProduceTime ve AddressLine alanlarına dayalı anlamsal aramaları destekler. Örneğin, 'Hangzhou üzerindeki gökyüzü' ile anlamsal olarak ilişkili dosyaların meta verilerini sorgulamak için sorgu koşulu olarak 'Query=sky over Hangzhou' belirtebilirsiniz.

Tek bir dosyanın meta verilerini sorgulama

Bu örnekte test-project projesindeki test-dataset veri kümesinden oss://test-bucket/test-object.jpg dosyasının meta verileri sorgulanmaktadır.

  • Örnek istek

    {
        "ProjectName": "test-project",
        "URI": "oss://test-bucket/test-object.jpg",
        "DatasetName": "test-dataset"
    }
                            
  • Örnek yanıt

    {
        "RequestId": "645FB6D9-5EA0-02C9-B253-****",
        "Files": [
            {
                "ProduceTime": "2020-08-19T17:11:11+08:00",
                "ObjectACL": "default",
                "ContentType": "image/jpeg",
                "ProjectName": "test-project",
                "Size": 22868,
                "URI": "oss://test-bucket/test-object.jpg",
                "Addresses": [
                    {
                        "Language": "zh-Hans",
                        "Township": "Tanggou Town",
                        "AddressLine": "Chenlongzhuang, Tanggou Town, Shuyang County, Suqian City, Jiangsu Province",
                        "Country": "China",
                        "City": "Suqian",
                        "District": "Shuyang",
                        "Province": "Jiangsu"
                    }
                ],
                "ObjectType": "file",
                "CustomLabels": {
                    "category": "Persons"
                },
                "OwnerId": "****",
                "FileModifiedTime": "2021-05-13T10:22:44+08:00",
                "ImageWidth": 270,
                "OSSStorageClass": "Standard",
                "MediaType": "image",
                "ObjectId": "****",
                "CreateTime": "2022-07-06T07:10:18.497753661+08:00",
                "Filename": "1.jpg",
                "Labels": [
                    {
                        "CentricScore": 0.921999990940094,
                        "Language": "zh-Hans",
                        "LabelConfidence": 1,
                        "LabelName": "Hairstyle",
                        "LabelLevel": 2,
                        "ParentLabelName": "Daily behavior"
                    },
                    ...
                ],
                "Orientation": 1,
                "Figures": [
                    {
                        "Beard": "none",
                        "MaskConfidence": 0.6959999799728394,
                        "Gender": "female",
                        "Boundary": {
                            "Left": 70,
                            "Top": 75,
                            "Height": 134,
                            "Width": 101
                        },
                        ...
                    }
                ],
                "EXIF": "...",
                "ContentMd5": "HZwoCnxPZ/fvhz4oRJ****",
                "ImageHeight": 270,
                "ImageScore": {
                    "OverallQualityScore": 0.6140000224113464
                },
                "ETag": "\"1D9C280A7C4F67F7EF873E28449D****\"",
                "DatasetName": "test-dataset",
                "FileHash": "\"1D9C280A7C4F67F7EF873E2****\"",
                "UpdateTime": "2022-07-06T07:10:18.497753661+08:00",
                "OSSCRC64": "5634447745650079669",
                "OSSTaggingCount": 0,
                "LatLong": "34.000000,119.000000",
                "OSSObjectType": "Normal"
            }
        ]
    }
  • Tam örnek kod (IMM SDK for Python V1.27.3)

    # -*- coding: utf-8 -*-
    
    import os
    from alibabacloud_imm20200930.client import Client as imm20200930Client
    from alibabacloud_tea_openapi import models as open_api_models
    from alibabacloud_imm20200930 import models as imm_20200930_models
    from alibabacloud_tea_util import models as util_models
    from alibabacloud_tea_util.client import Client as UtilClient
    
    class Sample:
        def __init__(self):
            pass
    
        @staticmethod
        def create_client(
            access_key_id: str,
            access_key_secret: str,
        ) -> imm20200930Client:
            """
            Use your AccessKey ID and AccessKey secret to initialize the client. 
            @param access_key_id:
            @param access_key_id:
            @param access_key_secret:
            @return: Client
            @throws Exception
            """
            config = open_api_models.Config(
                access_key_id=access_key_id,
                access_key_secret=access_key_secret
            )
            # Specify the endpoint. 
            config.endpoint = f'imm.cn-beijing.aliyuncs.com'
            return imm20200930Client(config)
    
        @staticmethod
        def main() -> None:
            # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. 
            # For security reasons, we recommend that you do not embed your AccessKey pair in your project code. 
            # In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables. 
            imm_access_key_id = os.getenv("AccessKeyId")
            imm_access_key_secret = os.getenv("AccessKeySecret")
            client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
            get_file_meta_request = imm_20200930_models.GetFileMetaRequest(
                project_name='test-project',
                dataset_name='test-dataset',
                uri='oss://test-bucket/test-object.jpg'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # Print the response of the API operation. 
                response = client.get_file_meta_with_options(get_file_meta_request, runtime)
                print(response.body.to_map())
            except Exception as error:
                # Print the error message if necessary. 
                UtilClient.assert_as_string(error.message)
                print(error)
    
    if __name__ == '__main__':
        Sample.main()

Birden çok dosyanın meta verilerini sorgulama

Bu örnekte test-project projesindeki test-dataset veri kümesinden oss://test-bucket/test-object1.jpg ve oss://test-bucket/test-object2.jpg dosyalarının meta verileri sorgulanmaktadır.

  • Örnek istek

    {
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "URIs": "[\"oss://test-bucket/test-object.jpg\", \"oss://test-bucket/test-object2.jpg\"]"
    }
  • Örnek yanıt (bkz. Tek bir dosyanın meta verilerini sorgulama bölümündeki örnek yanıt)

  • Tam örnek kod (IMM SDK for Python V1.27.3)

    # -*- coding: utf-8 -*-
    
    import os
    from alibabacloud_imm20200930.client import Client as imm20200930Client
    from alibabacloud_tea_openapi import models as open_api_models
    from alibabacloud_imm20200930 import models as imm_20200930_models
    from alibabacloud_tea_util import models as util_models
    from alibabacloud_tea_util.client import Client as UtilClient
    
    class Sample:
        def __init__(self):
            pass
    
        @staticmethod
        def create_client(
            access_key_id: str,
            access_key_secret: str,
        ) -> imm20200930Client:
            """
            Use your AccessKey ID and AccessKey secret to initialize the client. 
            @param access_key_id:
            @param access_key_secret:
            @return: Client
            @throws Exception
            """
            config = open_api_models.Config(
                access_key_id=access_key_id,
                access_key_secret=access_key_secret
            )
            # Specify the endpoint. 
            config.endpoint = f'imm.cn-beijing.aliyuncs.com'
            return imm20200930Client(config)
    
        @staticmethod
        def main() -> None:
            # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. 
            # For security reasons, we recommend that you do not embed your AccessKey pair in your project code. 
            # In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables. 
            imm_access_key_id = os.getenv("AccessKeyId")
            imm_access_key_secret = os.getenv("AccessKeySecret")
            client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
            batch_get_file_meta_request = imm_20200930_models.BatchGetFileMetaRequest(
                project_name='test-project',
                dataset_name='test-dataset',
                uris=[
                    'oss://test-bucket/test-object1.jpg',
                    'oss://test-bucket/test-object2.jpg'
                ]
            )
            runtime = util_models.RuntimeOptions()
            try:
                # Print the response of the API operation. 
                response = client.batch_get_file_meta_with_options(batch_get_file_meta_request, runtime)
                print(response.body.to_map())
            except Exception as error:
                # Print the error message if necessary. 
                UtilClient.assert_as_string(error.message)
                print(error)
    
    if __name__ == '__main__':
        Sample.main()

Basit sorgu gerçekleştirme

Örnek 1

Aşağıdaki içerik sorgunun koşullarını sunmaktadır:

  • Proje adı: test-project

  • Veri kümesi adı: test-dataset

  • Dosya türü: görüntü

  • Sorgu sonucu sıralaması: dosya boyutuna göre artan sırada

  • Döndürülen maksimum sorgu sonucu sayısı: 100

Aşağıdaki içerik bir örnek sunmaktadır:

  • Örnek istek

    {
        "Query": "{\"Field\": \"ContentType\", \"Operation\": \"prefix\", \"Value\": \"image\"}",
        "ProjectName": "test-project",
        "DatasetName": "test-dataset"
        "Sort": "Size",
        "Order": "asc",
        "MaxResults": 100
    }
  • Örnek yanıt (bkz. Tek bir dosyanın meta verilerini sorgulama bölümündeki örnek yanıt)

  • Tam örnek kod (IMM SDK for Python V1.27.3)

    # -*- coding: utf-8 -*-
    
    import os
    from alibabacloud_imm20200930.client import Client as imm20200930Client
    from alibabacloud_tea_openapi import models as open_api_models
    from alibabacloud_imm20200930 import models as imm_20200930_models
    from alibabacloud_tea_util import models as util_models
    from alibabacloud_tea_util.client import Client as UtilClient
    
    class Sample:
        def __init__(self):
            pass
    
        @staticmethod
        def create_client(
            access_key_id: str,
            access_key_secret: str,
        ) -> imm20200930Client:
            """
            Use your AccessKey ID and AccessKey secret to initialize the client. 
            @param access_key_id:
            @param access_key_secret:
            @return: Client
            @throws Exception
            """
            config = open_api_models.Config(
                access_key_id=access_key_id,
                access_key_secret=access_key_secret
            )
            config.endpoint = f'imm.cn-beijing.aliyuncs.com'
            return imm20200930Client(config)
    
        @staticmethod
        def main() -> None:
            # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. 
            # For security reasons, we recommend that you do not embed your AccessKey pair in your project code. 
            # In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables. 
            imm_access_key_id = os.getenv("AccessKeyId")
            imm_access_key_secret = os.getenv("AccessKeySecret")
            client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
            request = imm_20200930_models.SimpleQueryRequest()
            params = {
                # Specify the query conditions 
                "Query": {"SubQueries": [{"Field": "ContentType", "Operation": "eq", "Value": "image/jpeg"}, {"Field": "Size", "Operation": "gt", "Value": "10485760"}, {"Field": "CustomLabels.category", "Operation": "eq", "Value": "Persons"}], "Operation": "and"},
                # Specify the name of the IMM project.
                "ProjectName": "test-project",
                # Specify the name of the dataset.
                "DatasetName": "test-dataset",
                # Specify the sorting field. 
                "Sort": "Size",
                # Specify the sorting order. 
                "Order": "asc",
                # Set the maximum number of query results to 100. 
                "MaxResults": 100
            }
            request.from_map(params)
            runtime = util_models.RuntimeOptions()
            try:
                # Print the response of the API operation. 
                response = client.simple_query_with_options(request, runtime)
                print(response.body.to_map())
            except Exception as error:
                # Print the error message if necessary. 
                UtilClient.assert_as_string(error.message)
                print(error)
    
    if __name__ == '__main__':
        Sample.main()

Örnek 2

Aşağıdaki içerik sorgunun koşullarını sunmaktadır:

  • Proje adı: test-project

  • Veri kümesi adı: test-dataset

  • Dosya türü: görüntü

  • Dosya boyutu: 10 MB'tan büyük

  • Özel etiketler (CustomLabels.category): Persons

  • Sorgu sonucu sıralaması: dosya boyutuna göre artan sırada

  • Döndürülen maksimum sorgu sonucu sayısı: 100

Aşağıdaki içerik bir örnek sunmaktadır:

  • Örnek istek

    {
        "Query": "{\"SubQueries\": [{\"Field\": \"ContentType\", \"Operation\": \"prefix\", \"Value\": \"image\"}, {\"Field\": \"Size\", \"Operation\": \"gt\", \"Value\": \"10485760\"}, {\"Field\": \"CustomLabels.category\", \"Operation\": \"eq\", \"Value\": \"Persons\"}], \"Operation\": \"and\"}",
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "Sort": "Size",
        "Order": "asc",
        "MaxResults": 100
    }                       
  • Örnek yanıt (bkz. Tek bir dosyanın meta verilerini sorgulama bölümündeki örnek yanıt)

Örnek 3

Aşağıdaki içerik sorgunun koşullarını sunmaktadır:

  • Proje adı: test-project

  • Veri kümesi adı: test-dataset

  • Dosya yolu: oss://test-bucket/

  • Dosya boyutu: 10 MB'tan büyük

  • Etiketler (Labels.LabelName): "TV" veya "Stereo"

  • Sorgu sonucu sıralaması: dosya boyutuna göre artan sırada

  • Döndürülen maksimum sorgu sonucu sayısı: 100

Aşağıdaki içerik bir örnek sunmaktadır:

  • Örnek istek

    {
        "Query": "{\"SubQueries\":[{\"Field\":\"URI\",\"Value\":\"oss://test-bucket/\",\"Operation\":\"prefix\"},{\"Field\":\"Size\",\"Value\":\"10485760\",\"Operation\":\"gt\"},{\"SubQueries\":[{\"Field\":\"Labels.LabelName\",\"Value\":\"TV\",\"Operation\":\"eq\"},{\"Field\":\"Labels.LabelName\",\"Value\":\"Stereo\",\"Operation\":\"eq\"}],\"Operation\":\"or\"}],\"Operation\":\"and\"}",
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "Sort": "Size",
        "Order": "asc",
        "MaxResults": 100
    }
  • Örnek yanıt (bkz. Tek bir dosyanın meta verilerini sorgulama bölümündeki örnek yanıt)

Örnek 4

Aşağıdaki içerik sorgunun koşullarını sunmaktadır:

  • Proje adı: test-project

  • Veri kümesi adı: test-dataset

  • Dosya türü: görüntü

  • Dosya boyutu: 10 MB'tan büyük

  • Özel etiketler (CustomLabels.category): Persons

  • Döndürülen sonuç: eşleşen dosyaların toplam boyutu

Aşağıdaki içerik bir örnek sunmaktadır:

  • Örnek istek

    {
        "Query": "{\"SubQueries\": [{\"Field\": \"ContentType\", \"Operation\": \"eq\", \"Value\": \"image/jpeg\"}, {\"Field\": \"Size\", \"Operation\": \"gt\", \"Value\": \"10485760\"}, {\"Field\": \"CustomLabels.category\", \"Operation\": \"eq\", \"Value\": \"Persons\"}], \"Operation\": \"and\"}",
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "Aggregations": "[{\"Field\":\"Size\",\"Operation\":\"sum\"}]"
    }
  • Örnek yanıt

    {
        "RequestId": "0FB9BA35-E16B-0DFE-BD52-****",
        "Aggregations": [
            {
                "Field": "Size",
                "Value": 10485760,
                "Operation": "sum"
            }
        ]
    }

Örnek 5

Aşağıdaki içerik sorgunun koşullarını sunmaktadır:

  • Proje adı: test-project

  • Veri kümesi adı: test-dataset

  • Dosya boyutu: 10 MB'tan büyük

  • Yüzler (Figures.Age ve Figures.Gender): yaş ve cinsiyet

  • Sorgu sonucu sıralaması: dosya boyutuna göre artan sırada

  • Döndürülen maksimum sorgu sonucu sayısı: 100

Aşağıdaki içerik bir örnek sunmaktadır:

  • Örnek istek

    {
        "Query": "{\"Operation\":\"not\",\"SubQueries\":[{\"Operation\":\"nested\",\"SubQueries\":[{\"Operation\":\"and\",\"SubQueries\":[{\"Field\":\"Figures.Age\",\"Operation\":\"gt\",\"Value\":\"36\"},{\"Field\":\"Figures.Gender\",\"Operation\":\"eq\",\"Value\":\"male\"},{\"Field\":\"Size\",\"Operation\":\"gt\",\"Value\":\"10485760\"}]}]}]}",
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "Sort": "Size",
        "Order": "asc",
        "MaxResults": 100
    }
  • Örnek yanıt (bkz. Tek bir dosyanın meta verilerini sorgulama bölümündeki örnek yanıt)

Örnek 6

Aşağıdaki içerik sorgunun koşullarını sunmaktadır:

  • Proje adı: test-project

  • Veri kümesi adı: test-dataset

  • Dosya türü: görüntü

  • Dosya boyutu: 10 MB'tan büyük

  • Özel etiketler (CustomLabels.category): varlık

  • Döndürülen sonuç: eşleşen dosyaların toplam boyutu

Aşağıdaki içerik bir örnek sunmaktadır:

  • Örnek istek

    {
        "Query": "{\"SubQueries\": [{\"Field\": \"ContentType\", \"Operation\": \"eq\", \"Value\": \"image/jpeg\"}, {\"Field\": \"Size\", \"Operation\": \"gt\", \"Value\": \"10485760\"}, {\"Field\": \"CustomLabels.category\", \"Operation\": \"exist\"}], \"Operation\": \"and\"}",
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "Aggregations": "[{\"Field\":\"Size\",\"Operation\":\"sum\"}]"
    }
  • Örnek yanıt

    {
        "RequestId": "0FB9BA35-E16B-0DFE-BD52-****",
        "Aggregations": [
            {
                "Field": "Size",
                "Value": 10485760,
                "Operation": "sum"
            }
        ]
    }

Bulanık arama gerçekleştirme

Bu örnekte test-project projesindeki test-dataset veri kümesinde jpg dizesiyle eşleşen dosyalar aranmaktadır.

  • Örnek istek

    {
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "Query": "jpg"
    }
  • Örnek yanıt (bkz. Tek bir dosyanın meta verilerini sorgulama bölümündeki örnek yanıt)

  • Tam örnek kod (IMM SDK for Python V1.27.3)

    # -*- coding: utf-8 -*-
    
    import os
    from alibabacloud_imm20200930.client import Client as imm20200930Client
    from alibabacloud_tea_openapi import models as open_api_models
    from alibabacloud_imm20200930 import models as imm_20200930_models
    from alibabacloud_tea_util import models as util_models
    from alibabacloud_tea_util.client import Client as UtilClient
    
    class Sample:
        def __init__(self):
            pass
    
        @staticmethod
        def create_client(
            access_key_id: str,
            access_key_secret: str,
        ) -> imm20200930Client:
            """
            Use your AccessKey ID and AccessKey secret to initialize the client. 
            @param access_key_id:
            @param access_key_secret:
            @return: Client
            @throws Exception
            """
            config = open_api_models.Config(
                access_key_id=access_key_id,
                access_key_secret=access_key_secret
            )
            config.endpoint = f'imm.cn-beijing.aliyuncs.com'
            return imm20200930Client(config)
    
        @staticmethod
        def main() -> None:
            # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. 
            # For security reasons, we recommend that you do not embed your AccessKey pair in your project code. 
            # In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables. 
            imm_access_key_id = os.getenv("AccessKeyId")
            imm_access_key_secret = os.getenv("AccessKeySecret")
            client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
            fuzzy_query_request = imm_20200930_models.FuzzyQueryRequest(
                # Specify the name of the IMM project. 
                project_name='test-project',
                # Specify the name of the dataset. 
                dataset_name='test-dataset',
                # Specify the keyword. 
                query='jpg'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # Print the response of the API operation. 
                response = client.fuzzy_query_with_options(fuzzy_query_request, runtime)
                print(response.body.to_map())
            except Exception as error:
                # Print the error message if necessary. 
                UtilClient.assert_as_string(error.message)
                print(error)
    
    if __name__ == '__main__':
        Sample.main()

Doğal dil anahtar kelime araması gerçekleştirme

Bu örnekte test-project projesindeki test-dataset veri kümesinde Temmuz 2020'de Chengdu'daki pandalar ile ilgili dosyalar aranmaktadır.

  • Örnek istek

    {
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "Query": "Pandas in Chengdu in July 2020"
        "MaxResults": 100
    }
  • Örnek yanıt (bkz. Tek bir dosyanın meta verilerini sorgulama bölümündeki örnek yanıt)

  • Tam örnek kod (IMM SDK for Python V1.27.3)

    # -*- coding: utf-8 -*-
    
    import os
    from alibabacloud_imm20200930.client import Client as imm20200930Client
    from alibabacloud_tea_openapi import models as open_api_models
    from alibabacloud_imm20200930 import models as imm_20200930_models
    from alibabacloud_tea_util import models as util_models
    from alibabacloud_tea_util.client import Client as UtilClient
    
    class Sample:
        def __init__(self):
            pass
    
        @staticmethod
        def create_client(
            access_key_id: str,
            access_key_secret: str,
        ) -> imm20200930Client:
            """
            Use your AccessKey ID and AccessKey secret to initialize the client. 
            @param access_key_id:
            @param access_key_secret:
            @return: Client
            @throws Exception
            """
            config = open_api_models.Config(
                access_key_id=access_key_id,
                access_key_secret=access_key_secret
            )
            config.endpoint = f'imm.cn-beijing.aliyuncs.com'
            return imm20200930Client(config)
    
        @staticmethod
        def main() -> None:
            # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. 
            # For security reasons, we recommend that you do not embed your AccessKey pair in your project code. 
            # In this example, the AccessKey pair is obtained from the environment variables to implement identity verification for API access. For information about how to configure environment variables, visit https://www.alibabacloud.com/help/en/imm/developer-reference/configure-environment-variables. 
            imm_access_key_id = os.getenv("AccessKeyId")
            imm_access_key_secret = os.getenv("AccessKeySecret")
            client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
            semantic_query_request = imm_20200930_models.SemanticQueryRequest(
                query='Pandas in Chengdu in July 2020',
                project_name='test-project',
                dataset_name='test-dataset',
                max_results=100
            )
            runtime = util_models.RuntimeOptions()
            try:
                # Print the response of the API operation. 
                response = client.semantic_query_with_options(semantic_query_request, runtime)
                print(response.body.to_map())
            except Exception as error:
                # Print the error message if necessary. 
                UtilClient.assert_as_string(error.message)
                print(error)
    
    if __name__ == '__main__':
        Sample.main()