trustgraph-cli 2.11.4__tar.gz → 2.11.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/PKG-INFO +1 -1
  2. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/pyproject.toml +7 -0
  3. trustgraph_cli-2.11.6/trustgraph/cli/delete_ontology.py +73 -0
  4. trustgraph_cli-2.11.6/trustgraph/cli/get_ontology.py +97 -0
  5. trustgraph_cli-2.11.6/trustgraph/cli/invoke_nl_sparql.py +131 -0
  6. trustgraph_cli-2.11.6/trustgraph/cli/invoke_ontology_subset.py +138 -0
  7. trustgraph_cli-2.11.6/trustgraph/cli/invoke_sparql_nl_query.py +149 -0
  8. trustgraph_cli-2.11.6/trustgraph/cli/list_ontologies.py +101 -0
  9. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/nquads.py +0 -15
  10. trustgraph_cli-2.11.6/trustgraph/cli/put_ontology.py +137 -0
  11. trustgraph_cli-2.11.6/trustgraph/cli_version.py +1 -0
  12. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph_cli.egg-info/PKG-INFO +1 -1
  13. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph_cli.egg-info/SOURCES.txt +7 -0
  14. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph_cli.egg-info/entry_points.txt +7 -0
  15. trustgraph_cli-2.11.4/trustgraph/cli_version.py +0 -1
  16. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/README.md +0 -0
  17. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/setup.cfg +0 -0
  18. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/__init__.py +0 -0
  19. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/_iam.py +0 -0
  20. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/add_library_document.py +0 -0
  21. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/bootstrap_iam.py +0 -0
  22. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/change_password.py +0 -0
  23. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/create_api_key.py +0 -0
  24. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/create_user.py +0 -0
  25. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/create_workspace.py +0 -0
  26. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/delete_collection.py +0 -0
  27. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/delete_config_item.py +0 -0
  28. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/delete_flow_blueprint.py +0 -0
  29. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/delete_kg_core.py +0 -0
  30. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/delete_mcp_tool.py +0 -0
  31. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/delete_tool.py +0 -0
  32. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/delete_user.py +0 -0
  33. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/describe_image.py +0 -0
  34. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/disable_user.py +0 -0
  35. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/dump_msgpack.py +0 -0
  36. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/dump_queues.py +0 -0
  37. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/enable_user.py +0 -0
  38. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/export_workspace.py +0 -0
  39. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/export_workspace_config.py +0 -0
  40. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/get_config_item.py +0 -0
  41. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/get_de_core.py +0 -0
  42. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/get_document_content.py +0 -0
  43. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/get_flow_blueprint.py +0 -0
  44. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/get_kg_core.py +0 -0
  45. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/graph_to_turtle.py +0 -0
  46. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/import_workspace.py +0 -0
  47. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/import_workspace_config.py +0 -0
  48. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/init_pulsar_manager.py +0 -0
  49. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_agent.py +0 -0
  50. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_cloze.py +0 -0
  51. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_decision_scoring.py +0 -0
  52. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_document_embeddings.py +0 -0
  53. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_document_rag.py +0 -0
  54. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_embeddings.py +0 -0
  55. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_field_extraction.py +0 -0
  56. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_graph_embeddings.py +0 -0
  57. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_graph_rag.py +0 -0
  58. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_llm.py +0 -0
  59. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_mcp_tool.py +0 -0
  60. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_nlp_query.py +0 -0
  61. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_prompt.py +0 -0
  62. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_reranker.py +0 -0
  63. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_row_embeddings.py +0 -0
  64. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_rows_query.py +0 -0
  65. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_sparql_query.py +0 -0
  66. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/invoke_structured_query.py +0 -0
  67. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_api_keys.py +0 -0
  68. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_cloze_models.py +0 -0
  69. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_collections.py +0 -0
  70. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_config_items.py +0 -0
  71. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_explain_traces.py +0 -0
  72. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_models.py +0 -0
  73. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_my_workspaces.py +0 -0
  74. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_users.py +0 -0
  75. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/list_workspaces.py +0 -0
  76. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/load_doc_embeds.py +0 -0
  77. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/load_kg_core.py +0 -0
  78. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/load_knowledge.py +0 -0
  79. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/load_sample_documents.py +0 -0
  80. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/load_structured_data.py +0 -0
  81. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/load_turtle.py +0 -0
  82. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/login.py +0 -0
  83. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/mint_token.py +0 -0
  84. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/monitor_prompts.py +0 -0
  85. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/put_config_item.py +0 -0
  86. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/put_de_core.py +0 -0
  87. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/put_flow_blueprint.py +0 -0
  88. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/put_kg_core.py +0 -0
  89. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/query_graph.py +0 -0
  90. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/remove_library_document.py +0 -0
  91. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/reset_password.py +0 -0
  92. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/revoke_api_key.py +0 -0
  93. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/__init__.py +0 -0
  94. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/belgian-beer.md +0 -0
  95. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/bronze-age-collapse.pdf +0 -0
  96. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/corporate-scandals.pdf +0 -0
  97. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/history-of-pets.md +0 -0
  98. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/metadata.json +0 -0
  99. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/mil-fortifications-america-19th-c.md +0 -0
  100. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/recipes.md +0 -0
  101. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/sample_documents/trade-routes-europe.md +0 -0
  102. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/save_doc_embeds.py +0 -0
  103. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/set_collection.py +0 -0
  104. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/set_mcp_tool.py +0 -0
  105. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/set_prompt.py +0 -0
  106. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/set_token_costs.py +0 -0
  107. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/set_tool.py +0 -0
  108. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_config.py +0 -0
  109. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_explain_trace.py +0 -0
  110. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_extraction_provenance.py +0 -0
  111. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_flow_blueprints.py +0 -0
  112. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_flow_state.py +0 -0
  113. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_flows.py +0 -0
  114. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_graph.py +0 -0
  115. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_kg_cores.py +0 -0
  116. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_library_documents.py +0 -0
  117. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_library_processing.py +0 -0
  118. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_mcp_tools.py +0 -0
  119. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_parameter_types.py +0 -0
  120. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_processor_state.py +0 -0
  121. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_prompts.py +0 -0
  122. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_token_costs.py +0 -0
  123. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_token_rate.py +0 -0
  124. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/show_tools.py +0 -0
  125. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/start_flow.py +0 -0
  126. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/start_library_processing.py +0 -0
  127. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/stop_flow.py +0 -0
  128. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/stop_library_processing.py +0 -0
  129. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/unload_kg_core.py +0 -0
  130. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/update_user.py +0 -0
  131. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/verify_system_status.py +0 -0
  132. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph/cli/whoami.py +0 -0
  133. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph_cli.egg-info/dependency_links.txt +0 -0
  134. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph_cli.egg-info/requires.txt +0 -0
  135. {trustgraph_cli-2.11.4 → trustgraph_cli-2.11.6}/trustgraph_cli.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trustgraph-cli
3
- Version: 2.11.4
3
+ Version: 2.11.6
4
4
  Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
5
5
  Author-email: "trustgraph.ai" <security@trustgraph.ai>
6
6
  Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
@@ -76,6 +76,13 @@ tg-invoke-mcp-tool = "trustgraph.cli.invoke_mcp_tool:main"
76
76
  tg-invoke-nlp-query = "trustgraph.cli.invoke_nlp_query:main"
77
77
  tg-invoke-rows-query = "trustgraph.cli.invoke_rows_query:main"
78
78
  tg-invoke-sparql-query = "trustgraph.cli.invoke_sparql_query:main"
79
+ tg-invoke-nl-sparql = "trustgraph.cli.invoke_nl_sparql:main"
80
+ tg-invoke-sparql-nl-query = "trustgraph.cli.invoke_sparql_nl_query:main"
81
+ tg-invoke-ontology-subset = "trustgraph.cli.invoke_ontology_subset:main"
82
+ tg-put-ontology = "trustgraph.cli.put_ontology:main"
83
+ tg-delete-ontology = "trustgraph.cli.delete_ontology:main"
84
+ tg-get-ontology = "trustgraph.cli.get_ontology:main"
85
+ tg-list-ontologies = "trustgraph.cli.list_ontologies:main"
79
86
  tg-invoke-row-embeddings = "trustgraph.cli.invoke_row_embeddings:main"
80
87
  tg-invoke-prompt = "trustgraph.cli.invoke_prompt:main"
81
88
  tg-invoke-reranker = "trustgraph.cli.invoke_reranker:main"
@@ -0,0 +1,73 @@
1
+ """
2
+ Deletes a loaded ontology from the config service.
3
+ """
4
+
5
+ import argparse
6
+ import os
7
+ import sys
8
+ from trustgraph.api import Api
9
+ from trustgraph.api.types import ConfigKey
10
+
11
+ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8888/')
12
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
13
+ default_workspace = os.getenv("TRUSTGRAPH_WORKSPACE", "default")
14
+
15
+
16
+ def delete_ontology(url, ontology_id, token=None, workspace="default"):
17
+ api = Api(url, token=token, workspace=workspace).config()
18
+
19
+ config_key = ConfigKey(type="ontology", key=ontology_id)
20
+ api.delete([config_key])
21
+
22
+ print(f"Ontology '{ontology_id}' deleted")
23
+
24
+
25
+ def main():
26
+
27
+ parser = argparse.ArgumentParser(
28
+ prog='tg-delete-ontology',
29
+ description=__doc__,
30
+ )
31
+
32
+ parser.add_argument(
33
+ '--ontology-id', '-i',
34
+ required=True,
35
+ help='Ontology identifier',
36
+ )
37
+
38
+ parser.add_argument(
39
+ '-u', '--api-url',
40
+ default=default_url,
41
+ help=f'API URL (default: {default_url})',
42
+ )
43
+
44
+ parser.add_argument(
45
+ '-t', '--token',
46
+ default=default_token,
47
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
48
+ )
49
+
50
+ parser.add_argument(
51
+ '-w', '--workspace',
52
+ default=default_workspace,
53
+ help=f'Workspace (default: {default_workspace})',
54
+ )
55
+
56
+ args = parser.parse_args()
57
+
58
+ try:
59
+
60
+ delete_ontology(
61
+ url=args.api_url,
62
+ ontology_id=args.ontology_id,
63
+ token=args.token,
64
+ workspace=args.workspace,
65
+ )
66
+
67
+ except Exception as e:
68
+
69
+ print("Exception:", e, flush=True)
70
+ sys.exit(1)
71
+
72
+ if __name__ == "__main__":
73
+ main()
@@ -0,0 +1,97 @@
1
+ """
2
+ Retrieves a loaded ontology from the config service. Can output as
3
+ JSON-LD (default) or convert to Turtle, RDF/XML, or N-Triples via rdflib.
4
+ """
5
+
6
+ import argparse
7
+ import os
8
+ import sys
9
+ from rdflib import Graph
10
+ from trustgraph.api import Api
11
+ from trustgraph.api.types import ConfigKey
12
+
13
+ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8888/')
14
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
15
+ default_workspace = os.getenv("TRUSTGRAPH_WORKSPACE", "default")
16
+
17
+
18
+ def from_jsonld(jsonld, fmt):
19
+ if fmt == "json-ld":
20
+ return jsonld
21
+ g = Graph()
22
+ g.parse(data=jsonld, format="json-ld")
23
+ return g.serialize(format=fmt)
24
+
25
+
26
+ def get_ontology(url, ontology_id, fmt, token=None, workspace="default"):
27
+ api = Api(url, token=token, workspace=workspace).config()
28
+
29
+ config_key = ConfigKey(type="ontology", key=ontology_id)
30
+ values = api.get([config_key])
31
+
32
+ if not values:
33
+ raise Exception(
34
+ f"Ontology not found: {ontology_id}"
35
+ )
36
+
37
+ jsonld = values[0].value
38
+ print(from_jsonld(jsonld, fmt))
39
+
40
+
41
+ def main():
42
+
43
+ parser = argparse.ArgumentParser(
44
+ prog='tg-get-ontology',
45
+ description=__doc__,
46
+ )
47
+
48
+ parser.add_argument(
49
+ '--ontology-id', '-i',
50
+ required=True,
51
+ help='Ontology identifier',
52
+ )
53
+
54
+ parser.add_argument(
55
+ '--format', '-f',
56
+ choices=['json-ld', 'turtle', 'xml', 'nt'],
57
+ default='json-ld',
58
+ help='Output format (default: json-ld)',
59
+ )
60
+
61
+ parser.add_argument(
62
+ '-u', '--api-url',
63
+ default=default_url,
64
+ help=f'API URL (default: {default_url})',
65
+ )
66
+
67
+ parser.add_argument(
68
+ '-t', '--token',
69
+ default=default_token,
70
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
71
+ )
72
+
73
+ parser.add_argument(
74
+ '-w', '--workspace',
75
+ default=default_workspace,
76
+ help=f'Workspace (default: {default_workspace})',
77
+ )
78
+
79
+ args = parser.parse_args()
80
+
81
+ try:
82
+
83
+ get_ontology(
84
+ url=args.api_url,
85
+ ontology_id=args.ontology_id,
86
+ fmt=args.format,
87
+ token=args.token,
88
+ workspace=args.workspace,
89
+ )
90
+
91
+ except Exception as e:
92
+
93
+ print("Exception:", e, flush=True)
94
+ sys.exit(1)
95
+
96
+ if __name__ == "__main__":
97
+ main()
@@ -0,0 +1,131 @@
1
+ """
2
+ Translate a natural language question to a SPARQL query using ontology
3
+ context and entity resolution. Returns the generated SPARQL and
4
+ resolved entity mappings.
5
+ """
6
+
7
+ import argparse
8
+ import json
9
+ import os
10
+ from trustgraph.api import Api
11
+
12
+ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8888/')
13
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
14
+ default_workspace = os.getenv("TRUSTGRAPH_WORKSPACE", "default")
15
+
16
+ def query(url, flow_id, question, collection="default", limit=10,
17
+ token=None, workspace="default", as_json=False):
18
+
19
+ api = Api(url=url, token=token, workspace=workspace)
20
+ socket = api.socket()
21
+ flow = socket.flow(flow_id)
22
+
23
+ try:
24
+ result = flow.nl_to_sparql(
25
+ question=question,
26
+ collection=collection,
27
+ limit=limit,
28
+ )
29
+
30
+ if as_json:
31
+ print(json.dumps(result, indent=2))
32
+ return
33
+
34
+ entities = result.get("resolved-entities", [])
35
+ if entities:
36
+ print("Resolved entities:")
37
+ for e in entities:
38
+ score = e.get("score", 0)
39
+ print(
40
+ f" {e.get('mention', '')} -> {e.get('uri', '')} "
41
+ f"[{e.get('rdf-type', '')}] (score: {score:.3f})"
42
+ )
43
+ print()
44
+
45
+ sparql = result.get("sparql", "")
46
+ if sparql:
47
+ print("Generated SPARQL:")
48
+ print(sparql)
49
+ else:
50
+ print("No SPARQL generated.")
51
+
52
+ finally:
53
+ socket.close()
54
+
55
+ def main():
56
+
57
+ parser = argparse.ArgumentParser(
58
+ prog='tg-invoke-nl-sparql',
59
+ description=__doc__,
60
+ )
61
+
62
+ parser.add_argument(
63
+ '-u', '--url',
64
+ default=default_url,
65
+ help=f'API URL (default: {default_url})',
66
+ )
67
+
68
+ parser.add_argument(
69
+ '-t', '--token',
70
+ default=default_token,
71
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
72
+ )
73
+
74
+ parser.add_argument(
75
+ '-w', '--workspace',
76
+ default=default_workspace,
77
+ help=f'Workspace (default: {default_workspace})',
78
+ )
79
+
80
+ parser.add_argument(
81
+ '-f', '--flow-id',
82
+ default="default",
83
+ help=f'Flow ID (default: default)'
84
+ )
85
+
86
+ parser.add_argument(
87
+ '-c', '--collection',
88
+ default="default",
89
+ help='Collection identifier (default: default)',
90
+ )
91
+
92
+ parser.add_argument(
93
+ '-l', '--limit',
94
+ type=int,
95
+ default=10,
96
+ help='Result limit hint for generated query (default: 10)',
97
+ )
98
+
99
+ parser.add_argument(
100
+ '-j', '--json',
101
+ action='store_true',
102
+ default=False,
103
+ help='Output as JSON',
104
+ )
105
+
106
+ parser.add_argument(
107
+ 'question',
108
+ help='Natural language question to translate to SPARQL',
109
+ )
110
+
111
+ args = parser.parse_args()
112
+
113
+ try:
114
+
115
+ query(
116
+ url=args.url,
117
+ flow_id=args.flow_id,
118
+ question=args.question,
119
+ collection=args.collection,
120
+ limit=args.limit,
121
+ token=args.token,
122
+ workspace=args.workspace,
123
+ as_json=args.json,
124
+ )
125
+
126
+ except Exception as e:
127
+
128
+ print("Exception:", e, flush=True)
129
+
130
+ if __name__ == "__main__":
131
+ main()
@@ -0,0 +1,138 @@
1
+ """
2
+ Select relevant ontology subset for given text. Returns matching
3
+ classes, object properties, and datatype properties from the loaded
4
+ ontologies.
5
+ """
6
+
7
+ import argparse
8
+ import json
9
+ import os
10
+ from trustgraph.api import Api
11
+
12
+ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8888/')
13
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
14
+ default_workspace = os.getenv("TRUSTGRAPH_WORKSPACE", "default")
15
+
16
+ def query(url, flow_id, text, top_k=10, similarity_threshold=0.3,
17
+ token=None, workspace="default", as_json=False):
18
+
19
+ api = Api(url=url, token=token, workspace=workspace)
20
+ socket = api.socket()
21
+ flow = socket.flow(flow_id)
22
+
23
+ try:
24
+ result = flow.ontology_subset(
25
+ text=text,
26
+ top_k=top_k,
27
+ similarity_threshold=similarity_threshold,
28
+ )
29
+
30
+ if as_json:
31
+ print(json.dumps(result, indent=2))
32
+ return
33
+
34
+ print(f"Ontology: {result.get('ontology-id', 'unknown')}")
35
+ print(f"Namespace: {result.get('namespace', '')}")
36
+ print()
37
+
38
+ classes = result.get("classes", {})
39
+ if classes:
40
+ print(f"Classes ({len(classes)}):")
41
+ for class_id, class_def in classes.items():
42
+ print(f" {class_id}")
43
+ print()
44
+
45
+ obj_props = result.get("object-properties", {})
46
+ if obj_props:
47
+ print(f"Object Properties ({len(obj_props)}):")
48
+ for prop_id, prop_def in obj_props.items():
49
+ print(f" {prop_id}")
50
+ print()
51
+
52
+ dt_props = result.get("datatype-properties", {})
53
+ if dt_props:
54
+ print(f"Datatype Properties ({len(dt_props)}):")
55
+ for prop_id, prop_def in dt_props.items():
56
+ print(f" {prop_id}")
57
+
58
+ finally:
59
+ socket.close()
60
+
61
+ def main():
62
+
63
+ parser = argparse.ArgumentParser(
64
+ prog='tg-invoke-ontology-subset',
65
+ description=__doc__,
66
+ )
67
+
68
+ parser.add_argument(
69
+ '-u', '--url',
70
+ default=default_url,
71
+ help=f'API URL (default: {default_url})',
72
+ )
73
+
74
+ parser.add_argument(
75
+ '-t', '--token',
76
+ default=default_token,
77
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
78
+ )
79
+
80
+ parser.add_argument(
81
+ '-w', '--workspace',
82
+ default=default_workspace,
83
+ help=f'Workspace (default: {default_workspace})',
84
+ )
85
+
86
+ parser.add_argument(
87
+ '-f', '--flow-id',
88
+ default="default",
89
+ help=f'Flow ID (default: default)'
90
+ )
91
+
92
+ parser.add_argument(
93
+ '-k', '--top-k',
94
+ type=int,
95
+ default=10,
96
+ help='Number of top ontology elements to retrieve (default: 10)',
97
+ )
98
+
99
+ parser.add_argument(
100
+ '-s', '--similarity-threshold',
101
+ type=float,
102
+ default=0.3,
103
+ help='Similarity threshold for matching (default: 0.3)',
104
+ )
105
+
106
+ parser.add_argument(
107
+ '-j', '--json',
108
+ action='store_true',
109
+ default=False,
110
+ help='Output as JSON',
111
+ )
112
+
113
+ parser.add_argument(
114
+ 'text',
115
+ help='Text to match against ontology elements',
116
+ )
117
+
118
+ args = parser.parse_args()
119
+
120
+ try:
121
+
122
+ query(
123
+ url=args.url,
124
+ flow_id=args.flow_id,
125
+ text=args.text,
126
+ top_k=args.top_k,
127
+ similarity_threshold=args.similarity_threshold,
128
+ token=args.token,
129
+ workspace=args.workspace,
130
+ as_json=args.json,
131
+ )
132
+
133
+ except Exception as e:
134
+
135
+ print("Exception:", e, flush=True)
136
+
137
+ if __name__ == "__main__":
138
+ main()
@@ -0,0 +1,149 @@
1
+ """
2
+ Answer a natural language question via SPARQL. Chains NL-to-SPARQL
3
+ translation with SPARQL execution, returning both the generated query
4
+ and its results.
5
+ """
6
+
7
+ import argparse
8
+ import json
9
+ import os
10
+ from trustgraph.api import Api
11
+
12
+ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8888/')
13
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
14
+ default_workspace = os.getenv("TRUSTGRAPH_WORKSPACE", "default")
15
+
16
+ def query(url, flow_id, question, collection="default", limit=10,
17
+ token=None, workspace="default", as_json=False):
18
+
19
+ api = Api(url=url, token=token, workspace=workspace)
20
+ socket = api.socket()
21
+ flow = socket.flow(flow_id)
22
+
23
+ try:
24
+ result = flow.sparql_nl_query(
25
+ question=question,
26
+ collection=collection,
27
+ limit=limit,
28
+ )
29
+
30
+ if as_json:
31
+ print(json.dumps(result, indent=2))
32
+ return
33
+
34
+ entities = result.get("resolved-entities", [])
35
+ if entities:
36
+ print("Resolved entities:")
37
+ for e in entities:
38
+ score = e.get("score", 0)
39
+ print(
40
+ f" {e.get('mention', '')} -> {e.get('uri', '')} "
41
+ f"[{e.get('rdf-type', '')}] (score: {score:.3f})"
42
+ )
43
+ print()
44
+
45
+ sparql = result.get("sparql", "")
46
+ if sparql:
47
+ print("Generated SPARQL:")
48
+ print(sparql)
49
+ print()
50
+
51
+ query_type = result.get("query-type", "")
52
+ if query_type == "select":
53
+ variables = result.get("variables", [])
54
+ bindings = result.get("bindings", [])
55
+ if variables:
56
+ header = " ".join(f"?{v:<20}" for v in variables)
57
+ print(header)
58
+ print("-" * len(header))
59
+ for row in bindings:
60
+ print(" ".join(f"{v:<22}" for v in row))
61
+ if not bindings:
62
+ print("No results.")
63
+ elif query_type == "ask":
64
+ print(f"ASK result: {result.get('ask-result', False)}")
65
+ elif query_type:
66
+ print(f"Query type: {query_type}")
67
+ else:
68
+ print("No query results.")
69
+
70
+ finally:
71
+ socket.close()
72
+
73
+ def main():
74
+
75
+ parser = argparse.ArgumentParser(
76
+ prog='tg-invoke-sparql-nl-query',
77
+ description=__doc__,
78
+ )
79
+
80
+ parser.add_argument(
81
+ '-u', '--url',
82
+ default=default_url,
83
+ help=f'API URL (default: {default_url})',
84
+ )
85
+
86
+ parser.add_argument(
87
+ '-t', '--token',
88
+ default=default_token,
89
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
90
+ )
91
+
92
+ parser.add_argument(
93
+ '-w', '--workspace',
94
+ default=default_workspace,
95
+ help=f'Workspace (default: {default_workspace})',
96
+ )
97
+
98
+ parser.add_argument(
99
+ '-f', '--flow-id',
100
+ default="default",
101
+ help=f'Flow ID (default: default)'
102
+ )
103
+
104
+ parser.add_argument(
105
+ '-c', '--collection',
106
+ default="default",
107
+ help='Collection identifier (default: default)',
108
+ )
109
+
110
+ parser.add_argument(
111
+ '-l', '--limit',
112
+ type=int,
113
+ default=10,
114
+ help='Result limit hint for generated query (default: 10)',
115
+ )
116
+
117
+ parser.add_argument(
118
+ '-j', '--json',
119
+ action='store_true',
120
+ default=False,
121
+ help='Output as JSON',
122
+ )
123
+
124
+ parser.add_argument(
125
+ 'question',
126
+ help='Natural language question to answer via SPARQL',
127
+ )
128
+
129
+ args = parser.parse_args()
130
+
131
+ try:
132
+
133
+ query(
134
+ url=args.url,
135
+ flow_id=args.flow_id,
136
+ question=args.question,
137
+ collection=args.collection,
138
+ limit=args.limit,
139
+ token=args.token,
140
+ workspace=args.workspace,
141
+ as_json=args.json,
142
+ )
143
+
144
+ except Exception as e:
145
+
146
+ print("Exception:", e, flush=True)
147
+
148
+ if __name__ == "__main__":
149
+ main()