Glossary
    • PDF

    Glossary

    • PDF

    記事の要約

    Classic/VPC環境で利用できます。

    Papago Translation APIのユースケースを紹介します。

    用語集を作成

    用語集を作成するユースケースを説明します。

    Python

    Pythonベースの APIのサンプルコードは次の通りです。

    import hashlib
    import hmac
    import base64
    import time
    import requests
    
    def make_signature(access_key, secret_key, timestamp, url, method):
        timestamp = str(timestamp)
        secret_key = bytes(secret_key, 'UTF-8')
    
        message = method + " " + url + "\n" + timestamp + "\n" + access_key
        message = bytes(message, 'UTF-8')
        signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
        return signingKey.decode('UTF-8')
    
    
    def create():
        baseurl = "https://papago.apigw.ntruss.com" #{OpenAPI endpoint}
        url = "/glossary/v1/create"
    
        access_key = "DonNfVLUKOMNnmXXXXXX" #{Main / Sub Account Access Key}
        secret_key = "W5RyNUbIzOuUsEM8v8eqreMdSQZHMm9nfgXXXXXX" #{Main / Sub Account Secret Key}
        timestamp = int(time.time() * 1000)
        method = "POST"
    
        signature = make_signature(access_key, secret_key, timestamp, url, method)
    
        url = baseurl + url
        headers = {
            "x-ncp-apigw-timestamp": str(timestamp),
            "x-ncp-iam-access-key": access_key,
            "x-ncp-apigw-signature-v2": str(signature)
        }
        params = {
            "glossaryName": "Glossary1",
            "description": "Glossary1用語集の説明です。"
        }
    
        response = requests.post(url=url, verify=True, headers=headers, json=params)
    

    用語集ファイルをアップロード

    用語集に用語リストファイルをアップロードするユースケースを説明します。

    Python

    Pythonベースの APIのサンプルコードは次の通りです。

    import hashlib
    import hmac
    import base64
    import time
    import requests
    
    def make_signature(access_key, secret_key, timestamp, url, method):
        timestamp = str(timestamp)
        secret_key = bytes(secret_key, 'UTF-8')
    
        message = method + " " + url + "\n" + timestamp + "\n" + access_key
        message = bytes(message, 'UTF-8')
        signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
        return signingKey.decode('UTF-8')
    
    
    def uploadFile():
        baseurl = "https://papago.apigw.ntruss.com" #{OpenAPI endpoint}
        url = "/glossary/v1/{}/upload"
    
        access_key = "DonNfVLUKOMNnmXXXXXX" #{Main / Sub Account Access Key}
        secret_key = "W5RyNUbIzOuUsEM8v8eqreMdSQZHMm9nfgXXXXXX" #{Main / Sub Account Secret Key}
        timestamp = int(time.time() * 1000)
        method = "POST"
        glossary_key = "c399cf78-781e-4353-89a6-cca8aaxxxxxx"
        url = url.format(glossary_key) #{urlの{}を glossary-keyに変更します。}
    
        signature = make_signature(access_key, secret_key, timestamp, url, method)
    
        url = baseurl + url
        headers = {
            "x-ncp-apigw-timestamp": str(timestamp),
            "x-ncp-iam-access-key": access_key,
            "x-ncp-apigw-signature-v2": str(signature)
        }
        file = {
            "file": ("glossary_file.csv", open('glossary_file.csv', 'rb'), "text/csv")
        }
    
        response = requests.post(url=url, verify=True, headers=headers, files=file)
    

    用語集ファイルをダウンロード

    登録した用語集をダウンロードするユースケースを説明します。

    Python

    Pythonベースの APIのサンプルコードは次の通りです。

    import hashlib
    import hmac
    import base64
    import time
    import requests
    
    
    def make_signature(access_key, secret_key, timestamp, url, method):
        timestamp = str(timestamp)
        secret_key = bytes(secret_key, 'UTF-8')
    
        message = method + " " + url + "\n" + timestamp + "\n" + access_key
        message = bytes(message, 'UTF-8')
        signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
        return signingKey.decode('UTF-8')
    
    
    def download():
        baseurl = "papago.apigw.ntruss.com" #{OpenAPI endpoint}
        url = "/glossary/v1/{}/download"
    
        access_key = "DonNfVLUKOMNnmXXXXXX" #{Main / Sub Account Access Key}
        secret_key = "W5RyNUbIzOuUsEM8v8eqreMdSQZHMm9nfgXXXXXX" #{Main / Sub Account Secret Key}
        timestamp = int(time.time() * 1000)
        method = "POST"
        glossary_key = "c399cf78-781e-4353-89a6-cca8aaxxxxxx"
        url = url.format(glossary_key) #{change {} in url to glossary-key.}
    
        signature = make_signature(access_key, secret_key, timestamp, url, method)
    
        url = baseurl + url
        headers = {
            "x-ncp-apigw-timestamp": str(timestamp),
            "x-ncp-iam-access-key": access_key,
            "x-ncp-apigw-signature-v2": str(signature)
        }
    
        response = requests.post(url=url, verify=True, headers=headers)
    

    用語集リストを照会

    用語集リストを照会するユースケースを説明します。

    Python

    Pythonベースの APIのサンプルコードは次の通りです。

    import hashlib
    import hmac
    import base64
    import time
    import requests
    
    
    def make_signature(access_key, secret_key, timestamp, url, method):
        timestamp = str(timestamp)
        secret_key = bytes(secret_key, 'UTF-8')
    
        message = method + " " + url + "\n" + timestamp + "\n" + access_key
        message = bytes(message, 'UTF-8')
        signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
        return signingKey.decode('UTF-8')
    
    
    def get_user_glossary():
        baseurl = "https://papago.apigw.ntruss.com" #{OpenAPI endpoint}
        url = "/glossary/v1/?currentPage={}&pageSize={}"
    
        access_key = "DonNfVLUKOMNnmXXXXXX" #{Main / Sub Account Access Key}
        secret_key = "W5RyNUbIzOuUsEM8v8eqreMdSQZHMm9nfgXXXXXX" #{Main / Sub Account Secret Key}
        timestamp = int(time.time() * 1000)
        method = "GET"
        url = url.format(1, 10)  # {change {} in url to page number and page size.}{urlの{}をページ番号とサイズに設定します。}
    
        signature = make_signature(access_key, secret_key, timestamp, url, method)
    
        url = baseurl + url
        headers = {
            "x-ncp-apigw-timestamp": str(timestamp),
            "x-ncp-iam-access-key": access_key,
            "x-ncp-apigw-signature-v2": str(signature)
        }
    
        response = requests.get(url=url, verify=True, headers=headers)
    

    用語集を削除

    用語集を削除するユースケースを説明します。

    Python

    Pythonベースの APIのサンプルコードは次の通りです。

    import hashlib
    import hmac
    import base64
    import time
    import requests
    
    def make_signature(access_key, secret_key, timestamp, url, method):
        timestamp = str(timestamp)
        secret_key = bytes(secret_key, 'UTF-8')
    
        message = method + " " + url + "\n" + timestamp + "\n" + access_key
        message = bytes(message, 'UTF-8')
        signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
        return signingKey.decode('UTF-8')
    
    
    def delete():
        baseurl = "https://papago.apigw.ntruss.com"  # {OpenAPI endpoint}
        url = "/glossary/v1/{}"
    
        access_key = "DonNfVLUKOMNnmXXXXXX"  # {Main / Sub Account Access Key}
        secret_key = "W5RyNUbIzOuUsEM8v8eqreMdSQZHMm9nfgXXXXXX"  # {Main / Sub Account Secret Key}
        timestamp = int(time.time() * 1000)
        method = "DELETE"
        glossary_key = "c399cf78-781e-4353-89a6-cca8aaxxxxxx"
        url = url.format(glossary_key) #{urlの{}を glossary-keyに変更します。}
    
        signature = make_signature(access_key, secret_key, timestamp, url, method)
    
        url = baseurl + url
        headers = {
            "x-ncp-apigw-timestamp": str(timestamp),
            "x-ncp-iam-access-key": access_key,
            "x-ncp-apigw-signature-v2": str(signature)
        }
    
        response = requests.delete(url=url, verify=True, headers=headers)
    

    この記事は役に立ちましたか?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.