בדף הזה מוסבר בקצרה על תיקיות ואיך לנהל מסמכים באמצעות תיקיות.
מהן התיקיות ב-Document AI Warehouse
תיקייה היא סוג מיוחד של מסמך. היא לא יכולה לכלול תוכן מוטבע או תוכן משויך, אבל המשתמשים עדיין יכולים להוסיף מאפיינים לתיקייה.
תיקייה משמשת כמאגר לקיבוץ ולתיוג מסמכים. המשתמשים יכולים לצרף מסמך לכמה תיקיות, ותיקייה יכולה להכיל כמה מסמכים.
אפשר גם להשתמש בתיקיות ב-API של documents.search כדי לסנן מסמכי צאצא בתיקייה ספציפית.
לפני שמתחילים
לפני שמתחילים, חשוב לוודא שהשלמתם את השלבים שמופיעים בדף המדריך למתחילים.
יצירת תיקייה ב-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, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.
הצגת רשימה של מסמכים משניים בתיקייה ב-Document AI Warehouse
כדי להציג רשימה של מסמכי צאצא מיידיים בתיקייה, מבצעים את הפעולות הבאות:
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 Warehouse
כדי להסיר מסמך מתיקייה, צריך את שם הקישור. אפשר לאחזר את שם הקישור באמצעות השיטה 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)