naas-abi 1.0.0__py3-none-any.whl
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.
- naas_abi/__init__.py +35 -0
- naas_abi/agents/AbiAgent.py +442 -0
- naas_abi/agents/AbiAgent_test.py +157 -0
- naas_abi/agents/EntitytoSPARQLAgent.py +952 -0
- naas_abi/agents/EntitytoSPARQLAgent_test.py +66 -0
- naas_abi/agents/KnowledgeGraphBuilderAgent.py +321 -0
- naas_abi/agents/KnowledgeGraphBuilderAgent_test.py +86 -0
- naas_abi/agents/OntologyEngineerAgent.py +115 -0
- naas_abi/agents/OntologyEngineerAgent_test.py +42 -0
- naas_abi/apps/oxigraph_admin/main.py +392 -0
- naas_abi/apps/oxigraph_admin/terminal_style.py +151 -0
- naas_abi/apps/sparql_terminal/main.py +68 -0
- naas_abi/apps/sparql_terminal/terminal_style.py +236 -0
- naas_abi/apps/terminal_agent/main.py +553 -0
- naas_abi/apps/terminal_agent/terminal_style.py +175 -0
- naas_abi/cli.py +714 -0
- naas_abi/mappings.py +83 -0
- naas_abi/models/airgap_gemma.py +220 -0
- naas_abi/models/airgap_qwen.py +24 -0
- naas_abi/models/default.py +23 -0
- naas_abi/models/gpt_4_1.py +25 -0
- naas_abi/pipelines/AIAgentOntologyGenerationPipeline.py +635 -0
- naas_abi/pipelines/AIAgentOntologyGenerationPipeline_test.py +133 -0
- naas_abi/pipelines/AddIndividualPipeline.py +215 -0
- naas_abi/pipelines/AddIndividualPipeline_test.py +66 -0
- naas_abi/pipelines/InsertDataSPARQLPipeline.py +197 -0
- naas_abi/pipelines/InsertDataSPARQLPipeline_test.py +96 -0
- naas_abi/pipelines/MergeIndividualsPipeline.py +245 -0
- naas_abi/pipelines/MergeIndividualsPipeline_test.py +98 -0
- naas_abi/pipelines/RemoveIndividualPipeline.py +166 -0
- naas_abi/pipelines/RemoveIndividualPipeline_test.py +58 -0
- naas_abi/pipelines/UpdateCommercialOrganizationPipeline.py +198 -0
- naas_abi/pipelines/UpdateDataPropertyPipeline.py +175 -0
- naas_abi/pipelines/UpdateLegalNamePipeline.py +107 -0
- naas_abi/pipelines/UpdateLinkedInPagePipeline.py +179 -0
- naas_abi/pipelines/UpdatePersonPipeline.py +184 -0
- naas_abi/pipelines/UpdateSkillPipeline.py +118 -0
- naas_abi/pipelines/UpdateTickerPipeline.py +104 -0
- naas_abi/pipelines/UpdateWebsitePipeline.py +106 -0
- naas_abi/triggers.py +131 -0
- naas_abi/workflows/AgentRecommendationWorkflow.py +321 -0
- naas_abi/workflows/AgentRecommendationWorkflow_test.py +160 -0
- naas_abi/workflows/ArtificialAnalysisWorkflow.py +337 -0
- naas_abi/workflows/ArtificialAnalysisWorkflow_test.py +57 -0
- naas_abi/workflows/ConvertOntologyGraphToYamlWorkflow.py +210 -0
- naas_abi/workflows/ConvertOntologyGraphToYamlWorkflow_test.py +78 -0
- naas_abi/workflows/CreateClassOntologyYamlWorkflow.py +208 -0
- naas_abi/workflows/CreateClassOntologyYamlWorkflow_test.py +65 -0
- naas_abi/workflows/CreateIndividualOntologyYamlWorkflow.py +183 -0
- naas_abi/workflows/CreateIndividualOntologyYamlWorkflow_test.py +86 -0
- naas_abi/workflows/ExportGraphInstancesToExcelWorkflow.py +450 -0
- naas_abi/workflows/ExportGraphInstancesToExcelWorkflow_test.py +33 -0
- naas_abi/workflows/GetObjectPropertiesFromClassWorkflow.py +385 -0
- naas_abi/workflows/GetObjectPropertiesFromClassWorkflow_test.py +57 -0
- naas_abi/workflows/GetSubjectGraphWorkflow.py +84 -0
- naas_abi/workflows/GetSubjectGraphWorkflow_test.py +71 -0
- naas_abi/workflows/SearchIndividualWorkflow.py +190 -0
- naas_abi/workflows/SearchIndividualWorkflow_test.py +98 -0
- naas_abi-1.0.0.dist-info/METADATA +9 -0
- naas_abi-1.0.0.dist-info/RECORD +62 -0
- naas_abi-1.0.0.dist-info/WHEEL +5 -0
- naas_abi-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.panel import Panel
|
|
3
|
+
from rich.syntax import Syntax
|
|
4
|
+
from rich.text import Text
|
|
5
|
+
from rich.table import Table
|
|
6
|
+
from rich.box import ROUNDED
|
|
7
|
+
import os
|
|
8
|
+
import platform
|
|
9
|
+
import readline
|
|
10
|
+
import atexit
|
|
11
|
+
|
|
12
|
+
console = Console()
|
|
13
|
+
|
|
14
|
+
# Command history for arrow key navigation
|
|
15
|
+
command_history = []
|
|
16
|
+
history_index = 0
|
|
17
|
+
current_input = ""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def set_terminal_title():
|
|
21
|
+
"""Set the terminal title to 'SPARQL Terminal'"""
|
|
22
|
+
if platform.system() == "Windows":
|
|
23
|
+
os.system("title SPARQL Terminal")
|
|
24
|
+
else: # For Unix-like systems (Linux, macOS)
|
|
25
|
+
print("\33]0;SPARQL Terminal\a", end="", flush=True)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def print_query_result(result):
|
|
29
|
+
"""Print SPARQL query results from RDFLib's Graph().query() which returns a SPARQLResult object"""
|
|
30
|
+
if not result:
|
|
31
|
+
console.print("[yellow]No results found[/yellow]")
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
# Create a table
|
|
35
|
+
table = Table(show_header=True, header_style="bold magenta", box=ROUNDED)
|
|
36
|
+
|
|
37
|
+
# Get variables from the result
|
|
38
|
+
variables = result.vars
|
|
39
|
+
|
|
40
|
+
# Add columns
|
|
41
|
+
for var in variables:
|
|
42
|
+
table.add_column(str(var))
|
|
43
|
+
|
|
44
|
+
# Add rows
|
|
45
|
+
for row in result:
|
|
46
|
+
row_values = []
|
|
47
|
+
for var in variables:
|
|
48
|
+
value = str(row[var]) if row[var] is not None else ""
|
|
49
|
+
row_values.append(value)
|
|
50
|
+
table.add_row(*row_values)
|
|
51
|
+
|
|
52
|
+
console.print(table)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def print_query_error(error):
|
|
56
|
+
"""Print SPARQL query error in a formatted panel"""
|
|
57
|
+
console.print(
|
|
58
|
+
Panel(
|
|
59
|
+
f"[red]Error executing SPARQL query:[/red]\n{str(error)}",
|
|
60
|
+
border_style="red",
|
|
61
|
+
box=ROUNDED,
|
|
62
|
+
expand=False,
|
|
63
|
+
title="Query Error",
|
|
64
|
+
title_align="left",
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def print_system_message(text):
|
|
70
|
+
console.print()
|
|
71
|
+
system_text = Text(text, style="yellow")
|
|
72
|
+
console.print(
|
|
73
|
+
Panel(
|
|
74
|
+
system_text,
|
|
75
|
+
border_style="yellow",
|
|
76
|
+
box=ROUNDED,
|
|
77
|
+
expand=False,
|
|
78
|
+
title="System",
|
|
79
|
+
title_align="left",
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
console.print()
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def print_query(query):
|
|
86
|
+
"""Print the SPARQL query with syntax highlighting"""
|
|
87
|
+
syntax = Syntax(query, "sparql", theme="monokai", line_numbers=True)
|
|
88
|
+
console.print(
|
|
89
|
+
Panel(
|
|
90
|
+
syntax,
|
|
91
|
+
border_style="blue",
|
|
92
|
+
box=ROUNDED,
|
|
93
|
+
expand=False,
|
|
94
|
+
title="SPARQL Query",
|
|
95
|
+
title_align="left",
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def clear_screen():
|
|
101
|
+
console.clear()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def print_welcome_message():
|
|
105
|
+
# Set terminal title
|
|
106
|
+
set_terminal_title()
|
|
107
|
+
|
|
108
|
+
welcome_text = Text.assemble(
|
|
109
|
+
("Welcome to SPARQL Terminal\n\n", "bold green"),
|
|
110
|
+
("Available commands:\n", "yellow"),
|
|
111
|
+
("- ", "dim"),
|
|
112
|
+
("'exit' ", "cyan"),
|
|
113
|
+
("to end the session\n", "dim"),
|
|
114
|
+
("- ", "dim"),
|
|
115
|
+
("'help' ", "cyan"),
|
|
116
|
+
("to see these commands again\n", "dim"),
|
|
117
|
+
("- ", "dim"),
|
|
118
|
+
("'clear' ", "cyan"),
|
|
119
|
+
("to clear the screen\n", "dim"),
|
|
120
|
+
("- ", "dim"),
|
|
121
|
+
("Enter your SPARQL query ", "cyan"),
|
|
122
|
+
("to execute it\n", "dim"),
|
|
123
|
+
("\nMultiline input:\n", "yellow"),
|
|
124
|
+
("- ", "dim"),
|
|
125
|
+
("End each line with ", "cyan"),
|
|
126
|
+
("';' ", "bold"),
|
|
127
|
+
("to continue\n", "dim"),
|
|
128
|
+
("- ", "dim"),
|
|
129
|
+
("Press ", "cyan"),
|
|
130
|
+
("Enter ", "bold"),
|
|
131
|
+
("twice to finish\n", "dim"),
|
|
132
|
+
("\nNavigation:\n", "yellow"),
|
|
133
|
+
("- ", "dim"),
|
|
134
|
+
("Use ", "cyan"),
|
|
135
|
+
("↑/↓ ", "bold"),
|
|
136
|
+
("arrow keys to navigate command history", "dim"),
|
|
137
|
+
)
|
|
138
|
+
console.print(Panel(welcome_text, expand=False))
|
|
139
|
+
console.print()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def print_divider():
|
|
143
|
+
console.print("─" * console.width, style="dim")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def preinput():
|
|
147
|
+
"""Save the current input before displaying a history item"""
|
|
148
|
+
global current_input
|
|
149
|
+
current_input = readline.get_line_buffer()
|
|
150
|
+
return current_input
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def get_user_input():
|
|
154
|
+
"""Get user input with support for multiline SPARQL queries and command history.
|
|
155
|
+
Use ';' at the end of a line to terminate the query."""
|
|
156
|
+
global command_history, history_index, current_input
|
|
157
|
+
|
|
158
|
+
try:
|
|
159
|
+
lines = []
|
|
160
|
+
|
|
161
|
+
# Use a simpler approach for history navigation
|
|
162
|
+
# This avoids the issue with the letter 'b' being captured
|
|
163
|
+
readline.set_history_length(1000) # Set history length
|
|
164
|
+
|
|
165
|
+
while True:
|
|
166
|
+
# Get input with history support
|
|
167
|
+
line = console.input("\n[bold cyan]SPARQL>[/bold cyan] ")
|
|
168
|
+
|
|
169
|
+
# Handle special commands
|
|
170
|
+
if line.lower() in ["exit", "help", "clear"]:
|
|
171
|
+
if line not in command_history:
|
|
172
|
+
command_history.append(line)
|
|
173
|
+
return line.lower()
|
|
174
|
+
|
|
175
|
+
# Add the line to our collection
|
|
176
|
+
lines.append(line)
|
|
177
|
+
|
|
178
|
+
# If the line ends with a semicolon, we're done
|
|
179
|
+
if line.strip().endswith(";"):
|
|
180
|
+
break
|
|
181
|
+
|
|
182
|
+
# If the line is empty and we have content, we're done
|
|
183
|
+
if not line.strip() and lines:
|
|
184
|
+
break
|
|
185
|
+
|
|
186
|
+
# Join the lines and remove the trailing semicolon
|
|
187
|
+
query = " ".join(lines).strip()
|
|
188
|
+
if query.endswith(";"):
|
|
189
|
+
query = query[:-1].strip()
|
|
190
|
+
|
|
191
|
+
# Add to history if it's not empty
|
|
192
|
+
if query and query not in command_history:
|
|
193
|
+
command_history.append(query)
|
|
194
|
+
|
|
195
|
+
console.print()
|
|
196
|
+
return query
|
|
197
|
+
except EOFError:
|
|
198
|
+
console.print("\n[bold red]Session ended by user.[/bold red]")
|
|
199
|
+
return "exit"
|
|
200
|
+
except KeyboardInterrupt:
|
|
201
|
+
console.print("\n[bold red]Session ended by user.[/bold red]")
|
|
202
|
+
return "exit"
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
# Save command history when exiting
|
|
206
|
+
def save_history():
|
|
207
|
+
"""Save command history to a file"""
|
|
208
|
+
history_file = os.path.expanduser("~/.sparql_terminal_history")
|
|
209
|
+
try:
|
|
210
|
+
with open(history_file, "w") as f:
|
|
211
|
+
for cmd in command_history:
|
|
212
|
+
f.write(cmd + "\n")
|
|
213
|
+
except Exception:
|
|
214
|
+
pass
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
# Load command history when starting
|
|
218
|
+
def load_history():
|
|
219
|
+
"""Load command history from a file"""
|
|
220
|
+
global command_history
|
|
221
|
+
history_file = os.path.expanduser("~/.sparql_terminal_history")
|
|
222
|
+
try:
|
|
223
|
+
if os.path.exists(history_file):
|
|
224
|
+
with open(history_file, "r") as f:
|
|
225
|
+
command_history = [
|
|
226
|
+
line.strip() for line in f.readlines() if line.strip()
|
|
227
|
+
]
|
|
228
|
+
except Exception:
|
|
229
|
+
pass
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# Register the save_history function to run at exit
|
|
233
|
+
atexit.register(save_history)
|
|
234
|
+
|
|
235
|
+
# Load history when the module is imported
|
|
236
|
+
load_history()
|