1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonでWatson DiscoveryのCollectionのEnrichmentsを更新

Posted at
# %%
from ibm_watson import DiscoveryV2
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import json

# %%
apikey='APIKEY'
version='VERSION'
authenticator = IAMAuthenticator(apikey=apikey)
discovery = DiscoveryV2(version=version, authenticator=authenticator)

# %%
service_url='SERVICE_URL'
discovery.set_service_url(service_url=service_url)

# %%
response = discovery.list_projects().get_result()
print(response)

# %%
projects = response['projects']
for project in projects:
    print(project)

# %%
name = 'PROJECT_NAME'
projects = [project for project in projects if project['name'] == name]
for project in projects:
    print(project)

# %%
project = projects[0]
print(project)

# %%
response = discovery.list_collections(project_id=project['project_id']).get_result()
print(response)

# %%
collections = response['collections']
for collection in collections:
    print(collection)

# %%
name = 'COLLECTION_NAME'
collections = [collection for collection in collections if collection['name'] == name]
for collection in collections:
    print(collection)

# %%
if len(collections) != 0:
    for collection in collections:
        response = discovery.get_collection(project_id=project['project_id'], collection_id=collection['collection_id']).get_result()
        print(response)
        print(json.dumps(response, ensure_ascii=False, indent=4))

# %%
enrichments = [
    {
        "enrichment_id": "ENRICHMENT_ID",
        "fields": [
            "AAA",
            "BBB"
        ]
    }
]
response = discovery.update_collection(project_id=project['project_id'], collection_id=collection['collection_id'], enrichments=enrichments).get_result()
print(response)
print(json.dumps(response, ensure_ascii=False, indent=4))

# %%

GUIでやれば良い気もしている…

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?