2024-11-25 20:46:35 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
2025-05-06 13:43:17 +01:00
|
|
|
"""
|
2025-05-08 00:41:45 +01:00
|
|
|
Starts a load operation on a knowledge core which is already stored by
|
|
|
|
|
the knowledge manager. You could load a core with tg-put-kg-core and then
|
|
|
|
|
run this utility.
|
2024-11-26 16:58:47 +00:00
|
|
|
"""
|
|
|
|
|
|
2024-11-25 20:46:35 +00:00
|
|
|
import argparse
|
|
|
|
|
import os
|
2025-05-08 00:41:45 +01:00
|
|
|
import tabulate
|
|
|
|
|
from trustgraph.api import Api
|
|
|
|
|
import json
|
2024-11-25 20:46:35 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|
|
|
|
default_flow = "0000"
|
|
|
|
|
default_collection = "default"
|
2024-11-25 20:46:35 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
def load_kg_core(url, user, id, flow, collection):
|
2024-11-25 20:46:35 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
api = Api(url).knowledge()
|
2024-12-09 12:44:30 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
class_names = api.load_kg_core(user = user, id = id, flow=flow,
|
|
|
|
|
collection=collection)
|
2024-12-09 12:44:30 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
def main():
|
2024-11-25 20:46:35 +00:00
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
2025-05-08 00:41:45 +01:00
|
|
|
prog='tg-delete-flow-class',
|
2024-11-25 20:46:35 +00:00
|
|
|
description=__doc__,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-05-08 00:41:45 +01:00
|
|
|
'-u', '--api-url',
|
2024-11-25 20:46:35 +00:00
|
|
|
default=default_url,
|
2025-05-08 00:41:45 +01:00
|
|
|
help=f'API URL (default: {default_url})',
|
2024-11-25 20:46:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-05-08 00:41:45 +01:00
|
|
|
'-U', '--user',
|
|
|
|
|
default="trustgraph",
|
|
|
|
|
help='API URL (default: trustgraph)',
|
2024-11-25 20:46:35 +00:00
|
|
|
)
|
|
|
|
|
|
2025-05-02 21:11:50 +01:00
|
|
|
parser.add_argument(
|
2025-05-08 00:41:45 +01:00
|
|
|
'--id', '--identifier',
|
|
|
|
|
required=True,
|
|
|
|
|
help=f'Knowledge core ID',
|
2024-11-25 20:46:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-05-08 00:41:45 +01:00
|
|
|
'-f', '--flow-id',
|
|
|
|
|
default=default_flow,
|
|
|
|
|
help=f'Flow ID (default: {default_flow}',
|
2024-11-25 20:46:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
parser.add_argument(
|
2025-05-08 00:41:45 +01:00
|
|
|
'-c', '--collection',
|
|
|
|
|
default=default_collection,
|
|
|
|
|
help=f'Collection ID (default: {default_collection}',
|
2024-11-25 20:46:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
try:
|
2024-12-06 15:16:09 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
load_kg_core(
|
|
|
|
|
url=args.api_url,
|
|
|
|
|
user=args.user,
|
|
|
|
|
id=args.id,
|
|
|
|
|
flow=args.flow_id,
|
|
|
|
|
collection=args.collection,
|
|
|
|
|
)
|
2024-12-06 15:16:09 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
except Exception as e:
|
2024-12-06 15:16:09 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
print("Exception:", e, flush=True)
|
2024-11-25 20:46:35 +00:00
|
|
|
|
2025-05-08 00:41:45 +01:00
|
|
|
main()
|
2024-11-25 20:46:35 +00:00
|
|
|
|