すべてのプロダクト
Search
ドキュメントセンター

Object Storage Service:インテリジェントドキュメントエンリッチメント

最終更新日:Jun 28, 2025

インテリジェントドキュメントエンリッチメントは、既存のドキュメントの包括的な表現とスタイルを最適化し、より流暢で読みやすくすることを目的としており、それによって質の高いプロフェッショナルな文章を作成します。

前提条件

続行する前に、IMM プロジェクトがバケットにマッピングされていることを確認してください。 IMM プロジェクトをマッピングする方法の詳細については、「はじめに」および「AttachOSSBucket」をご参照ください。

使用上の注意

  • インテリジェントドキュメントエンリッチメントは、同期処理リクエストに対してのみ有効にできます。

  • リクエストを送信するには、POST メソッドを使用する必要があります。

  • 匿名アクセスは拒否されます。

  • この機能を使用するには、必要な権限を持っている必要があります。 詳細については、「権限」をご参照ください。

パラメーター

操作: doc/enrich

次の表にパラメーターを示します。

パラメーター

タイプ

必須

説明

content

文字列

はい

エンリッチメント対象のドキュメント。URL セーフ Base64 でエンコードされている必要があります。

説明

処理対象のドキュメントは、最大 19,500 バイトの長さにすることができます。

format

文字列

いいえ

レスポンスが返されるフォーマットを指定します。 有効な値:

  • json (デフォルト): 通常モード。 完全なレスポンスが返されます。

  • event-stream: Server-Sent Events (SSE) モード。 複数のパケットが徐々に返されます。 各パケットには部分的なデータが含まれています。

次の表に、レスポンスのパラメーターを示します。

パラメーター

タイプ

説明

RequestId

文字列

リクエストの ID。

Output

構造体

出力。

サブノード: Text と FinishReason

Text

文字列

エンリッチされたコンテンツ。

親ノード: Output

FinishReason

文字列

エンリッチメントタスクのステータス。 有効な値:

  • null: タスクは実行中です。

  • stop: タスクは完了です。

親ノード: Output

RESTful API の使用

説明

RESTful API を使用してドキュメントをエンリッチメントする場合、プレースホルダーとしてのみ使用されるファイルの名前を指定する必要があります。 content パラメーターの値のみが、エンリッチメント対象のコンテンツのキャリアとして識別されます。

HTTP モードを使用してインテリジェントドキュメントエンリッチメントを実行する

処理方法

  • 処理対象のファイル: example.doc

  • リッチ化されるテキスト: アーネスト・ヘミングウェイの「老人と海」は、老漁師サンチャゴと巨大なカジキを捕まえるための壮大な闘いを描いた物語です。この物語は、人間の忍耐力、不屈の精神、そして自然の力との闘いについての深い探求です。逆境に直面しても揺るぎない決意と尊厳を保つサンチャゴの姿は、人間の精神の強さを証明するものです。

  • レスポンスのフォーマット: json

サンプルコード

POST /example.doc?x-oss-process HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e

x-oss-process=doc/enrich,content_RXJuZXN0IEhlbWluZ3dheSdzICJUaGUgT2xkIE1hbiBhbmQgdGhlIFNlYSIgaXMgYSB0YWxlIG9mIGFuIG9sZCBmaXNoZXJtYW4sIFNhbnRpYWdvLCBhbmQgaGlzIGVwaWMgc3RydWdnbGUgdG8gY2F0Y2ggYSBnaWFudCBtYXJsaW4uIFRoaXMgc3RvcnkgaXMgYSBwcm9mb3VuZCBleHBsb3JhdGlvbiBvZiBodW1hbiBlbmR1cmFuY2UsIHBlcnNldmVyYW5jZSwgYW5kIHRoZSBiYXR0bGUgYWdhaW5zdCB0aGUgZm9yY2VzIG9mIG5hdHVyZS4gU2FudGlhZ28ncyB1bndhdmVyaW5nIGRldGVybWluYXRpb24gYW5kIGRpZ25pdHkgaW4gdGhlIGZhY2Ugb2YgYWR2ZXJzaXR5IHNlcnZlIGFzIGEgdGVzdGFtZW50IHRvIHRoZSBzdHJlbmd0aCBvZiB0aGUgaHVtYW4gc3Bpcml0Lg==

サンプルレスポンス

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:09:00 GMT
Content-Type: application/json;charset=UTF-8
Connection: close
Vary: Accept-Encoding
x-oss-request-id: 6761403AAF96A1323085B4F6
x-oss-server-time: 2010
Content-Encoding: gzip

{
  "RequestId":"6761403AAF96A1323085B4F6",
  "Output":{
    "Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a compelling narrative that centers around an elderly fisherman named Santiago. The story unfolds on the shores of Cuba, where Santiago has not caught a fish for 84 days, a streak of bad luck that has earned him the label of being \"unlucky.\" Despite this, he remains steadfast and ventures out to sea once again, determined to prove his worth and skill.\n\nSantiago's epic struggle to catch a giant marlin is more than just a fishing tale; it is a profound exploration of human endurance and perseverance. For three days and nights, Santiago battles the powerful marlin, a creature that symbolizes both the beauty and the brutality of nature. His physical and mental fortitude are tested to their limits, as he refuses to give up despite the overwhelming odds against him. The marlin becomes a worthy adversary, one that challenges Santiago to push beyond his perceived boundaries and discover the depths of his own resilience.\n\nThe story also delves into the broader theme of the human struggle against the forces of nature. Santiago's relationship with the sea and its inhabitants is complex and nuanced. He respects the ocean and its creatures, viewing them as part of a larger, interconnected ecosystem. Yet, he must also confront the harsh realities of survival, where sometimes taking life is necessary for sustaining one's own. This duality reflects the intricate balance between man and nature, highlighting the mutual respect and conflict that exist in this relationship.\n\nSantiago's unwavering determination and dignity in the face of adversity serve as a powerful testament to the strength of the human spirit. Even when he returns to shore with only the skeleton of the marlin, having lost the fish to sharks, he does not lose his sense of pride or purpose. His journey is one of personal triumph, a reminder that the true measure of success is often found in the effort and the lessons learned along the way, rather than in the final outcome.\n\nThrough Santiago's story, Hemingway underscores the universal themes of resilience, honor, and the indomitable will to persevere. \"The Old Man and the Sea\" is not just a story about fishing; it is a profound meditation on the human condition, offering insights into the nature of struggle, the value of perseverance, and the enduring power of the human spirit.",
    "FinishReason":"stop"
  }
}

SSE モードを使用してインテリジェントドキュメントエンリッチメントを実行する

処理方法

  • 処理対象のファイル: example.doc

  • リッチ化されるテキスト: アーネスト・ヘミングウェイの「老人と海」は、老漁師サンチャゴと巨大なカジキを捕まえるための壮大な闘いを描いた物語です。この物語は、人間の忍耐力、不屈の精神、そして自然の力との闘いについての深い探求です。逆境に直面しても揺るぎない決意と尊厳を保つサンチャゴの姿は、人間の精神の強さを証明するものです。

  • レスポンスのフォーマット: event-stream

サンプルコード

POST /example.doc?x-oss-process HTTP/1.1
Host: doc-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e

x-oss-process=doc/enrich,format_event-stream,content_5Zub5aSn5ZCN6JGX77yM5Y2z5Zub5aSn5bCP6K-05ZCN6JGX77yM5piv5oyH44CK5LiJ5Zu95ryU5LmJ44CL44CB44CK6KW_5ri46K6w44CL44CB44CK5rC05rWS5Lyg44CL44CB44CK57qi5qW85qKm44CLNOmDqOS4reWbveWPpOWFuOeroOWbnuWwj-ivtOOAgg==

サンプルレスポンス

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Thu, 10 Aug 2023 11:20:11 GMT
Content-Type: text/event-stream;charset=UTF-8
Transfer-Encoding: chunked
Connection: close
x-oss-request-id: 67614140E3CA2838306217BE
x-oss-server-time: 587

id: 0
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Er","FinishReason":"null"}}

id: 1
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest","FinishReason":"null"}}

id: 2
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hem","FinishReason":"null"}}

id: 3
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Heming","FinishReason":"null"}}

id: 4
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The","FinishReason":"null"}}

id: 5
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the","FinishReason":"null"}}

id: 6
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a","FinishReason":"null"}}

id: 7
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around","FinishReason":"null"}}

id: 8
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman","FinishReason":"null"}}

id: 9
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman named Santiago. The","FinishReason":"null"}}

id: 10
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman named Santiago. The novella delves","FinishReason":"null"}}

id: 11
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman named Santiago. The novella delves into Santiago's life","FinishReason":"null"}}

id: 12
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman named Santiago. The novella delves into Santiago's life, painting a vivid","FinishReason":"null"}}

id: 13
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman named Santiago. The novella delves into Santiago's life, painting a vivid picture of his daily","FinishReason":"null"}}

id: 14
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman named Santiago. The novella delves into Santiago's life, painting a vivid picture of his daily struggles and the deep","FinishReason":"null"}}

id: 15
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman named Santiago. The novella delves into Santiago's life, painting a vivid picture of his daily struggles and the deep connection he has with","FinishReason":"null"}}


id: 94
event: Result
data: {"RequestId":"67614140E3CA2838306217BE","Output":{"Text":"Ernest Hemingway's \"The Old Man and the Sea\" is a poignant narrative centered around an elderly fisherman named Santiago. The novella delves into Santiago's life, painting a vivid picture of his daily struggles and the deep connection he has with the sea. Santiago, who has gone 84 days without catching a fish, embodies the resilience and tenacity that define many of Hemingway's characters.\n\nThe story unfolds as Santiago embarks on a journey far out into the Gulf Stream, where he hooks a giant marlin. What follows is an epic struggle that lasts for three grueling days and nights. During this time, Santiago faces not only the physical challenge of reeling in the massive fish but also the mental and emotional toll of the endeavor. His determination never wavers, even as he battles exhaustion, hunger, and the relentless attacks of sharks that threaten to strip him of his hard-earned prize.\n\nThis story is a profound exploration of human endurance, perseverance, and the battle against the forces of nature. Through Santiago's ordeal, Hemingway illustrates the indomitable will of the human spirit. Despite the overwhelming odds and the inevitability of loss, Santiago remains steadfast and dignified. His unwavering resolve serves as a powerful testament to the strength and nobility of the human condition.\n\nSantiago's journey is not just a physical one; it is also a deeply spiritual and philosophical quest. As he reflects on his life and the meaning of his struggle, readers are invited to contemplate the broader themes of existence, the relationship between man and nature, and the value of perseverance in the face of adversity. In the end, Santiago's story is a timeless reminder that true victory lies not in the outcome but in the courage and dignity with which one faces the challenges of life.","FinishReason":"stop"}}

OSS SDK の使用

次のサンプルコードは、一般的なプログラミング言語の Object Storage Service (OSS) SDK を使用してドキュメントをエンリッチメントする方法の例を示しています。 他のプログラミング言語の SDK を使用してドキュメントをエンリッチメントする場合は、次のサンプルコードに基づいてパラメーターを変更してください。

Java

Java 3.17.4 以降の OSS SDK が必要です。

// Java SDK の使用例

import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.common.utils.IOUtils;
import com.aliyun.oss.model.GenericResult;
import com.aliyun.oss.model.ProcessObjectRequest;

import java.io.IOException;
import java.util.Formatter;

public class Demo {
    public static void main(String[] args) throws ClientException, com.aliyuncs.exceptions.ClientException {
        // バケットが配置されているリージョンのエンドポイントを指定します。
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // バケットが配置されているAlibaba CloudリージョンのIDを指定します。例: cn-hangzhou。
        String region = "cn-hangzhou";
        // 環境変数からアクセス認証情報を取得します。サンプルコードを実行する前に、OSS_ACCESS_KEY_IDおよびOSS_ACCESS_KEY_SECRET環境変数が設定されていることを確認してください。
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // バケットの名前を指定します。例: examplebucket。
        String bucketName = "examplebucket";
        // ファイルの名前を指定します。これはプレースホルダーとしてのみ使用されます。インテリジェントドキュメントエンリッチメント機能を使用する場合、このファイルのコンテンツは読み取られません。
        String key ="example.docx";
        // エンリッチメントするテキストを指定します。
        String content = "yourContent";
        String encodeContent = BinaryUtil.toBase64String(content.getBytes()).replaceAll("\\+","-")
                .replaceAll("/","_").replaceAll("=","");

        // OSSClientインスタンスを作成します。
        // OSSClientが不要になったら、shutdownメソッドを呼び出してリソースを解放します。
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(region)
                .build();

        try {

            StringBuilder sbStyle = new StringBuilder();
            Formatter styleFormatter = new Formatter(sbStyle);
            // エンリッチメントの処理命令を作成します。
            styleFormatter.format("doc/enrich,content_%s",
                    encodeContent);
            System.out.println(sbStyle.toString());
            ProcessObjectRequest request = new ProcessObjectRequest(bucketName, key, sbStyle.toString());
            GenericResult processResult = ossClient.processObject(request);
            String json = IOUtils.readStreamAsString(processResult.getResponse().getContent(), "UTF-8");
            processResult.getResponse().getContent().close();
            System.out.println(json);
        } catch (OSSException oe) {
            System.out.println("OSSException が発生しました。これは、リクエストは OSS に到達しましたが、何らかの理由でエラーレスポンスで拒否されたことを意味します。");
            System.out.println("エラーメッセージ:" + oe.getErrorMessage());
            System.out.println("エラーコード:" + oe.getErrorCode());
            System.out.println("リクエスト ID:" + oe.getRequestId());
            System.out.println("ホスト ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("ClientException が発生しました。これは、クライアントが OSS と通信しようとしているときに、ネットワークにアクセスできないなど、重大な内部問題が発生したことを意味します。");
            System.out.println("エラーメッセージ:" + ce.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

PHP

PHP 2.7.0 以降の OSS SDK が必要です。

<?php
// 環境変数からアクセス認証情報を取得します。サンプルコードを実行する前に、OSS_ACCESS_KEY_IDおよびOSS_ACCESS_KEY_SECRET環境変数が設定されていることを確認してください。
$ak = getenv('OSS_ACCESS_KEY_ID');
$sk = getenv('OSS_ACCESS_KEY_SECRET');
// バケットの名前を指定します。例: examplebucket。
$bucket = 'examplebucket';
// ファイルの名前を指定します。これはプレースホルダーとしてのみ使用されます。インテリジェントドキュメントエンリッチメント機能を使用する場合、このファイルのコンテンツは読み取られません。
$objectKey = 'example.docx';
// エンリッチメントするテキストを指定します。
$txt = "yourTxt";

$base64url = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($txt));
// エンリッチメントの処理命令を作成します。
$body = sprintf("x-oss-process=doc/enrich,content_%s", $base64url);

$httpVerb = 'POST';
$contentMd5 = base64_encode(md5($body, true));
$contentType = '';
$date = gmdate('D, d M Y H:i:s T');
$stringToSign = $httpVerb . "\n" . $contentMd5 . "\n" . $contentType . "\n" . $date . "\n" . "/{$bucket}/{$objectKey}?x-oss-process";
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $sk, true));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://{$bucket}.oss-cn-hangzhou.aliyuncs.com/{$objectKey}?x-oss-process");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Date: ' . $date,
    'Authorization: OSS ' . $ak . ':' . $signature,
    'Content-Type: ' . $contentType,
    'Content-Md5:' . $contentMd5,
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false) {
    echo "Error: " . curl_error($ch);
} else {
    if ($httpcode == 200) {
        var_dump($response);
    } else {
        echo "Error: HTTP code " . $httpcode;
    }
}

Go

Go 3.0.2 以降の OSS SDK が必要です。

// Go SDK の使用例

package main

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io"
	"os"
	"strings"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

type TextData struct {
	RequestId string `json:"RequestId"`
	Output    struct {
		Text         string `json:"Text"`
		FinishReason string `json:"FinishReason"`
	} `json:"Output"`
}

func main() {
	// 環境変数からアクセス認証情報を取得します。サンプルコードを実行する前に、OSS_ACCESS_KEY_ID、OSS_ACCESS_KEY_SECRET、および OSS_SESSION_TOKEN 環境変数が設定されていることを確認してください。
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// OSSClient インスタンスを作成します。
	client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// バケットの名前を指定します。例: examplebucket。
	bucketName := "examplebucket"
	bucket, err := client.Bucket(bucketName)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	params := make(map[string]interface{})
	params["x-oss-process"] = nil
        // エンリッチメントするテキストを指定します。
	txt := "yourTxt"
        // エンリッチメントの処理命令を作成します。
	data := fmt.Sprintf("x-oss-process=doc/enrich,content_%v", base64.URLEncoding.EncodeToString([]byte(txt)))
        // example.docx はバケット内のファイルです。プレースホルダーとして使用されます。インテリジェントドキュメントエンリッチメント機能を使用する場合、example.docx のコンテンツは読み取られません。
	response, err := bucket.Do("POST", "example.docx", params, nil, strings.NewReader(data), nil)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	defer response.Body.Close()
	jsonData, err := io.ReadAll(response.Body)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	var text TextData
	err = json.Unmarshal(jsonData, &text)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	fmt.Printf("RequestId:%v\n", text.RequestId)
	fmt.Printf("Text:%v\n", text.Output.Text)
	fmt.Printf("FinishReason:%v\n", text.Output.FinishReason)
}