oxirs 0.2.4

Command-line interface for OxiRS - import, export, migration, and benchmarking tools
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# OxiRS Interactive Mode Guide

**Version**: 0.1.0
**Last Updated**: January 7, 2026
**Status**: Production-Ready

## Overview

OxiRS Interactive Mode provides a powerful REPL (Read-Eval-Print-Loop) for working with RDF datasets and executing SPARQL queries interactively. It's designed for exploratory data analysis, debugging, and rapid prototyping.

## Table of Contents

- [Getting Started]#getting-started
- [Basic Usage]#basic-usage
- [Features]#features
- [Commands]#commands
- [Query Execution]#query-execution
- [History Management]#history-management
- [Keyboard Shortcuts]#keyboard-shortcuts
- [Configuration]#configuration
- [Tips & Tricks]#tips--tricks

---

## Getting Started

### Starting Interactive Mode

```bash
# Start REPL
oxirs interactive

# Start with a dataset
oxirs interactive --dataset mydata

# Custom history file
oxirs interactive --history ~/.oxirs_history
```

### First Steps

```
OxiRS Interactive Mode v0.1.0
Type 'help' for commands, 'exit' to quit

oxirs> connect mydata
Connected to dataset: mydata (TDB2, 125,432 triples)

oxirs[mydata]> SELECT * WHERE { ?s ?p ?o } LIMIT 5
Executing query...
+-------------------+-------------------+-------------------+
| s                 | p                 | o                 |
+-------------------+-------------------+-------------------+
| ex:Alice          | rdf:type          | foaf:Person       |
| ex:Alice          | foaf:name         | "Alice"           |
| ex:Alice          | foaf:knows        | ex:Bob            |
| ex:Bob            | rdf:type          | foaf:Person       |
| ex:Bob            | foaf:name         | "Bob"             |
+-------------------+-------------------+-------------------+
5 results (23ms)

oxirs[mydata]>
```

---

## Basic Usage

### Connecting to Datasets

```
# Connect to dataset
oxirs> connect mydata

# Connect to dataset at custom location
oxirs> connect /path/to/dataset

# Show current connection
oxirs> status
Connected to: mydata
Location: ./data/mydata
Type: TDB2
Triples: 125,432
Graphs: 3

# Disconnect
oxirs> disconnect
```

### Executing Queries

```
# Simple SELECT query
oxirs[mydata]> SELECT * WHERE { ?s ?p ?o } LIMIT 10

# Multi-line query (press Enter for new line, Ctrl+D to execute)
oxirs[mydata]> SELECT ?name ?email WHERE {
...> ?person foaf:name ?name .
...> ?person foaf:mbox ?email .
...> }

# ASK query
oxirs[mydata]> ASK { ?s rdf:type foaf:Person }
true

# CONSTRUCT query
oxirs[mydata]> CONSTRUCT { ?s foaf:knows ?o } WHERE { ?s foaf:knows ?o }
```

### Update Operations

```
# Insert data
oxirs[mydata]> INSERT DATA {
...>   <http://example.org/alice> foaf:knows <http://example.org/charlie> .
...> }
Update successful (1 triple inserted)

# Delete data
oxirs[mydata]> DELETE DATA {
...>   <http://example.org/alice> foaf:knows <http://example.org/charlie> .
...> }
Update successful (1 triple deleted)
```

---

## Features

### 1. Tab Completion

Tab completion is available for:

- Commands: `connect`, `disconnect`, `help`, etc.
- Dataset names
- SPARQL keywords: `SELECT`, `WHERE`, `PREFIX`, etc.
- Common prefixes: `rdf:`, `rdfs:`, `foaf:`, `ex:`, etc.

**Usage:**
```
oxirs> conn<TAB>
connect

oxirs> SELE<TAB>
SELECT

oxirs> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
oxirs> ?person foaf:na<TAB>
?person foaf:name
```

### 2. Command History

All queries and commands are saved to history.

```
# Navigate history
Up Arrow    - Previous command
Down Arrow  - Next command
Ctrl+R      - Search history

# History management
oxirs> history           # Show last 20 commands
oxirs> history 50        # Show last 50 commands
oxirs> history clear     # Clear history
oxirs> !42              # Replay command #42
```

### 3. Multi-line Editing

Supports multi-line queries with proper indentation:

```
oxirs> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
...> SELECT ?name WHERE {
...>   ?person foaf:name ?name .
...>   FILTER(LANG(?name) = "en")
...> }
```

**Controls:**
- `Enter` - New line
- `Ctrl+D` or `;;` - Execute query
- `Ctrl+C` - Cancel current input

### 4. Syntax Highlighting

SPARQL keywords, URIs, literals, and variables are color-coded:

- **Keywords**: Blue (SELECT, WHERE, FILTER, etc.)
- **URIs**: Green
- **Literals**: Yellow
- **Variables**: Cyan
- **Comments**: Gray

### 5. Query Templates

Pre-defined templates for common queries:

```
# List templates
oxirs> templates

Available templates:
  1. basic-select      - Simple SELECT query
  2. construct-graph   - CONSTRUCT query
  3. describe-resource - DESCRIBE query
  4. count-triples     - Count triples
  5. list-classes      - List all classes
  6. list-properties   - List all properties

# Use template
oxirs> template basic-select
SELECT * WHERE { ?s ?p ?o } LIMIT 10

# Use template with parameters
oxirs> template basic-select --limit 100
SELECT * WHERE { ?s ?p ?o } LIMIT 100
```

### 6. Result Formatting

Multiple output formats for query results:

```
# Change output format
oxirs[mydata]> set format table    # ASCII table (default)
oxirs[mydata]> set format json     # JSON
oxirs[mydata]> set format csv      # CSV
oxirs[mydata]> set format markdown # Markdown table

# Limit results
oxirs[mydata]> set limit 20       # Show max 20 results
oxirs[mydata]> set limit none     # Show all results

# Show/hide query time
oxirs[mydata]> set timing on
oxirs[mydata]> set timing off
```

### 7. Result Pagination

For large result sets:

```
oxirs[mydata]> SELECT * WHERE { ?s ?p ?o }
Showing results 1-100 of 15,432

[Results displayed]

Press 'n' for next, 'p' for previous, 'q' to quit
```

### 8. Explain and Profiling

```
# Explain query plan
oxirs[mydata]> explain SELECT * WHERE { ?s ?p ?o }
Query Plan:
  1. BGP (Basic Graph Pattern)
     - Estimated cardinality: 125,432
     - Access: Sequential scan
     - Cost: 125

# Profile query
oxirs[mydata]> profile SELECT ?name WHERE { ?person foaf:name ?name }
Execution Time: 45ms
Triples Scanned: 1,234
Results: 567
Memory: 2.3 MB
```

---

## Commands

### Connection Commands

```
connect <dataset>         Connect to dataset
disconnect                Disconnect from current dataset
status                    Show connection status
datasets                  List available datasets
```

### Query Commands

```
SELECT ...                Execute SELECT query
ASK ...                   Execute ASK query
CONSTRUCT ...             Execute CONSTRUCT query
DESCRIBE ...              Execute DESCRIBE query
INSERT ...                Execute INSERT update
DELETE ...                Execute DELETE update
```

### Utility Commands

```
help                      Show help
history [n]               Show command history
!<n>                      Replay command #n
clear                     Clear screen
set <key> <value>         Set configuration option
show <key>                Show configuration value
templates                 List query templates
template <name> [args]    Use query template
explain <query>           Explain query plan
profile <query>           Profile query execution
```

### Control Commands

```
exit / quit / Ctrl+D      Exit interactive mode
Ctrl+C                    Cancel current input
Ctrl+L                    Clear screen
```

---

## Query Execution

### PREFIX Declarations

Prefixes are remembered across the session:

```
oxirs> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

oxirs> PREFIX ex: <http://example.org/>
PREFIX ex: <http://example.org/>

# Use prefixes in queries
oxirs> SELECT * WHERE { ?s foaf:name ?name }

# Show active prefixes
oxirs> show prefixes
Registered prefixes:
  rdf:   http://www.w3.org/1999/02/22-rdf-syntax-ns#
  rdfs:  http://www.w3.org/2000/01/rdf-schema#
  foaf:  http://xmlns.com/foaf/0.1/
  ex:    http://example.org/
```

### Query Execution Modes

```
# Normal execution
oxirs[mydata]> SELECT * WHERE { ?s ?p ?o } LIMIT 10

# Dry run (parse only, don't execute)
oxirs[mydata]> dryrun SELECT * WHERE { ?s ?p ?o }
Query syntax: OK
Estimated cost: 125

# Benchmark query
oxirs[mydata]> benchmark SELECT ?name WHERE { ?person foaf:name ?name }
Running 10 iterations...
Average time: 42ms
Min: 38ms, Max: 51ms, StdDev: 3.2ms
```

---

## History Management

### View History

```
# Last 20 commands
oxirs> history

# Last 50 commands
oxirs> history 50

# Search history
oxirs> history search SELECT

# Show history with timestamps
oxirs> history --timestamps
```

### Replay Commands

```
# Replay specific command
oxirs> !42

# Replay last command
oxirs> !!

# Replay last SELECT query
oxirs> !SELECT
```

### Export History

```
# Export to file
oxirs> history export queries.txt

# Export as SPARQL queries only
oxirs> history export --queries-only queries.sparql
```

---

## Keyboard Shortcuts

### Navigation

- `Ctrl+A` - Move to beginning of line
- `Ctrl+E` - Move to end of line
- `Ctrl+B` / `Left Arrow` - Move back one character
- `Ctrl+F` / `Right Arrow` - Move forward one character
- `Alt+B` - Move back one word
- `Alt+F` - Move forward one word

### Editing

- `Ctrl+D` - Delete character under cursor (or execute if line empty)
- `Ctrl+H` / `Backspace` - Delete character before cursor
- `Ctrl+W` - Delete word before cursor
- `Ctrl+K` - Kill (cut) to end of line
- `Ctrl+U` - Kill (cut) to beginning of line
- `Ctrl+Y` - Yank (paste) killed text

### History

- `Up Arrow` / `Ctrl+P` - Previous command
- `Down Arrow` / `Ctrl+N` - Next command
- `Ctrl+R` - Search history (reverse)
- `Ctrl+S` - Search history (forward)

### Control

- `Ctrl+C` - Cancel current input
- `Ctrl+D` - Execute query (empty line) or exit
- `Ctrl+L` - Clear screen
- `Tab` - Auto-completion

---

## Configuration

### Configuration Options

```
# Display settings
set format table|json|csv|markdown     # Output format
set limit <n>|none                    # Result limit
set timing on|off                     # Show query time
set colors on|off                     # Syntax highlighting
set pager on|off                      # Enable result pagination

# Query settings
set explain on|off                    # Auto-explain queries
set profile on|off                    # Auto-profile queries
set timeout <ms>                      # Query timeout

# History settings
set history <n>                       # History size
set save-history on|off               # Persist history

# Display current config
show config
```

### Configuration File

Create `~/.oxirs/interactive.toml`:

```toml
[display]
format = "table"
limit = 100
timing = true
colors = true
pager = true

[query]
explain = false
profile = false
timeout = 30000  # 30 seconds

[history]
size = 1000
save = true
file = "~/.oxirs/history"

[prefixes]
# Default prefixes
rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
rdfs = "http://www.w3.org/2000/01/rdf-schema#"
foaf = "http://xmlns.com/foaf/0.1/"
```

---

## Tips & Tricks

### 1. Quick Statistics

```
# Count triples
oxirs[mydata]> SELECT (COUNT(*) AS ?count) WHERE { ?s ?p ?o }

# List classes with counts
oxirs[mydata]> SELECT ?class (COUNT(?s) AS ?count) WHERE {
...>   ?s a ?class
...> } GROUP BY ?class ORDER BY DESC(?count)

# List properties
oxirs[mydata]> SELECT DISTINCT ?p WHERE { ?s ?p ?o }
```

### 2. Explore Schema

```
# List all classes
oxirs[mydata]> SELECT DISTINCT ?class WHERE { ?s a ?class }

# List properties of a class
oxirs[mydata]> SELECT DISTINCT ?p WHERE { ?s a foaf:Person . ?s ?p ?o }

# Sample instances
oxirs[mydata]> SELECT ?s WHERE { ?s a foaf:Person } LIMIT 5
```

### 3. Filter and Search

```
# Text search (case-insensitive)
oxirs[mydata]> SELECT * WHERE {
...>   ?s ?p ?o .
...>   FILTER(REGEX(STR(?o), "alice", "i"))
...> }

# Date range queries
oxirs[mydata]> SELECT * WHERE {
...>   ?s ex:created ?date .
...>   FILTER(?date >= "2026-01-01"^^xsd:date &&
...>          ?date <= "2026-01-31"^^xsd:date)
...> }
```

### 4. Export Results

```
# Export to CSV
oxirs[mydata]> set format csv
oxirs[mydata]> SELECT ?name ?email WHERE { ?p foaf:name ?name . ?p foaf:mbox ?email }
# Copy output or redirect

# Export to JSON
oxirs[mydata]> set format json
oxirs[mydata]> SELECT * WHERE { ?s ?p ?o } LIMIT 100 > results.json
```

### 5. Macros and Aliases

```
# Define macro
oxirs> macro count "SELECT (COUNT(*) AS ?count) WHERE { ?s ?p ?o }"

# Use macro
oxirs[mydata]> @count
+-------+
| count |
+-------+
| 125432|
+-------+

# List macros
oxirs> macros
```

### 6. Batch Operations

```
# Load queries from file
oxirs[mydata]> load queries.sparql

# Execute multiple updates
oxirs[mydata]> batch updates.sparql
Executing 10 updates...
10/10 successful
```

---

## Troubleshooting

### Common Issues

**Issue**: Query syntax error
```
oxirs[mydata]> SLECT * WHERE { ?s ?p ?o }
Error: Parse error at line 1, column 1: Expected 'SELECT', found 'SLECT'
```

**Solution**: Check spelling and SPARQL syntax.

**Issue**: Connection timeout
```
oxirs> connect slowdataset
Error: Connection timeout after 30s
```

**Solution**: Increase timeout with `set timeout 60000`.

**Issue**: Out of memory for large results
```
oxirs[mydata]> SELECT * WHERE { ?s ?p ?o }
Error: Out of memory
```

**Solution**: Add LIMIT clause or enable pagination with `set pager on`.

---

## Advanced Features

### Custom Output Formatters

```
# Register custom formatter
oxirs> formatter add custom-json "jq '.results.bindings[]'"

# Use custom formatter
oxirs> set format custom-json
```

### Query Analysis

```
# Analyze query complexity
oxirs[mydata]> analyze SELECT ?name WHERE {
...>   ?p1 foaf:knows ?p2 .
...>   ?p2 foaf:knows ?p3 .
...>   ?p3 foaf:name ?name
...> }
Complexity: HIGH
Estimated time: 2-5 seconds
Optimization suggestions:
  - Add index on foaf:knows
  - Consider limiting results
```

### Integration with External Tools

```
# Pipe to external command (Unix)
oxirs[mydata]> SELECT * WHERE { ?s ?p ?o } | grep "Alice"

# Export to clipboard
oxirs[mydata]> SELECT * WHERE { ?s ?p ?o } | pbcopy  # macOS
oxirs[mydata]> SELECT * WHERE { ?s ?p ?o } | xclip   # Linux
```

---

## See Also

- [COMMAND_REFERENCE.md]COMMAND_REFERENCE.md - Full command reference
- [README.md]../README.md - Getting started guide
- [CONFIGURATION.md]CONFIGURATION.md - Configuration reference

---

**OxiRS Interactive Mode v0.1.0** - Powerful REPL for RDF and SPARQL