このページでは、フォルダの概要と、フォルダを使用してドキュメントを管理する方法について説明します。
Document AI Warehouse のフォルダとは
フォルダは特殊なタイプのドキュメントです。インライン コンテンツを含めることや、関連付けられたコンテンツを持つことはできませんが、ユーザーはフォルダにプロパティを追加できます。フォルダは、ドキュメントをグループ化してラベル付けするためのコンテナとして機能します。ユーザーはドキュメントを複数のフォルダに添付でき、フォルダには複数のドキュメントを含めることができます。フォルダは、documents.search API で特定のフォルダにある子ドキュメントをフィルタリングするためにも使用できます。
始める前に
始める前に、クイックスタート ページを完了していることを確認してください。
スキーマを使用して Document AI Warehouse フォルダを作成する
フォルダをインスタンス化するためのスキーマを作成する手順は次のとおりです。
REST
リクエスト:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" -d '{
"display_name": "abc",
"property_definitions": [
{
"name": "Name",
"display_name": "Name",
"is_repeatable": false,
"is_filterable": true,
"is_searchable": true,
"is_metadata": true,
"is_required": true,
"text_type_options": {},
"schema_sources": []
}
],
"document_is_folder": true
}' \
"https://contentwarehouse.googleapis.com/v1/projects/406397197218/locations/us/documentSchemas"レスポンス:
{
"name": "SCHEMA_NAME",
"displayName": "abc",
"documentIsFolder": true,
"updateTime": "2022-08-31T16:10:43.111978Z",
"createTime": "2022-08-31T16:10:43.111978Z"
}Python
from google.cloud import contentwarehouse_v1
def create_folder_schema():
# Create a client
client = contentwarehouse_v1.DocumentSchemaServiceClient()
# Initialize request argument(s)
document_schema = contentwarehouse_v1.DocumentSchema()
document_schema.display_name = "display_name_value"
document_schema.document_is_folder = True
request = contentwarehouse_v1.CreateDocumentSchemaRequest(
parent="projects/533503808294/locations/us",
document_schema=document_schema,
)
# Make the request
return client.create_document_schema(request=request)
Document AI Warehouse のフォルダにドキュメントを追加する
フォルダにドキュメントを追加する手順は次のとおりです。
REST
リクエスト:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" -d '{
"document_link": {
"source_document_reference": {
"document_name": "projects/PROJECT_NUMBER/locations/LOCATION/documents/{document_id}"
},
"target_document_reference": {
"document_name": "projects/PROJECT_NUMBER/locations/LOCATION/documents/{document_id}"
}
},
"requestMetadata": {
"userInfo": {
"id": "user:USER_EMAIL_ID"
}
}
}' \
"https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents/{document_id}/documentLinks"レスポンス:
{
"name": "LINK_NAME",
"source_document_reference": {
"document_name": "FOLDER_NAME"
},
"target_document_reference": {
"document_name": "DOCUMENT_NAME"
}
}Python
from google.cloud import contentwarehouse_v1
def add_to_folder(folder:str, doc:str):
# Create a client
client = contentwarehouse_v1.DocumentLinkServiceClient()
# Initialize request argument(s)
link = contentwarehouse_v1.DocumentLink()
link.source_document_reference = contentwarehouse_v1.DocumentReference()
link.source_document_reference.document_name = folder
link.target_document_reference = contentwarehouse_v1.DocumentReference()
link.target_document_reference.document_name = doc
request = contentwarehouse_v1.CreateDocumentLinkRequest(
parent=folder,
document_link=link,
)
# Make the request
return client.create_document_link(request=request)
Document AI Warehouse フォルダを作成し、ドキュメントをリンクする
Python
詳細については、Document AI Warehouse Python API リファレンス ドキュメントをご覧ください。
Document AI Warehouse に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Document AI ウェアハウス フォルダの下にある子ドキュメントを一覧表示する
フォルダの下にある直下の子ドキュメントを一覧表示するには、次の操作を行います。
REST
リクエスト:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents/FOLDER/linkedTargetsレスポンス:
{
"documentLinks": [
{
"name": "LINK_NAME1"
"source_document_reference": {
"document_name": "FOLDER_NAME"
},
"target_document_reference": {
"document_name": "DOCUMENT_NAME1"
}
},
{
"name": "LINK_NAME2"
"source_document_reference": {
"document_name": "FOLDER_NAME"
},
"target_document_reference": {
"document_name": "DOCUMENT_NAME2"
}
}
...
]
}Python
from google.cloud import contentwarehouse_v1
def list_sub_docs(folder:str):
# Create a client
client = contentwarehouse_v1.DocumentLinkServiceClient()
# Initialize request argument(s)
request = contentwarehouse_v1.ListLinkedTargetsRequest(
parent=folder,
)
# Make the request
return client.list_linked_targets(request=request)
Document AI ウェアハウスのフォルダからドキュメントを削除する
フォルダからドキュメントを削除するには、リンク名が必要です。リンク名は、前の手順の documents.linkedTargets メソッドを使用して取得できます。
REST
リクエスト:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documents/FOLDER/documentLinks/LINK:deletePython
from google.cloud import contentwarehouse_v1
def remove_doc_from_folder(link:str):
# Create a client
client = contentwarehouse_v1.DocumentLinkServiceClient()
# Initialize request argument(s)
request = contentwarehouse_v1.DeleteDocumentLinkRequest(
name=link,
)
# Make the request
return client.delete_document_link(request=request)