Skip to content

Commit ec87d99

Browse files
committed
Add and test --use-prefixes flag for case_sparql_select
A follow-on patch will regenerate Make-managed files. Signed-off-by: Alex Nelson <[email protected]>
1 parent 609f762 commit ec87d99

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

case_utils/case_sparql_select/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ def main() -> None:
7070
action="store_true",
7171
help="Raise error if no results are returned for query.",
7272
)
73+
parser.add_argument(
74+
"--use-prefixes",
75+
action="store_true",
76+
help="Abbreviate node IDs according to graph's encoded prefixes. (This will use prefixes in the graph, not the query.)",
77+
)
7378
parser.add_argument(
7479
"out_table",
7580
help="Expected extensions are .html for HTML tables or .md for Markdown tables.",
@@ -124,6 +129,11 @@ def main() -> None:
124129
# The render to ASCII is in support of this script rendering results for website viewing.
125130
# .decode() is because hexlify returns bytes.
126131
column_value = binascii.hexlify(column.toPython()).decode()
132+
elif isinstance(column, rdflib.URIRef):
133+
if args.use_prefixes:
134+
column_value = graph.namespace_manager.qname(column.toPython())
135+
else:
136+
column_value = column.toPython()
127137
else:
128138
column_value = column.toPython()
129139
if row_no == 0:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<table border="1" class="dataframe table table-bordered table-condensed">
2+
<thead>
3+
<tr style="text-align: right;">
4+
<th></th>
5+
<th>?nFile</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
<tr>
10+
<th>0</th>
11+
<td>kb:file-1</td>
12+
</tr>
13+
<tr>
14+
<th>1</th>
15+
<td>kb:file-2</td>
16+
</tr>
17+
</tbody>
18+
</table>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| | ?nFile |
2+
|----|-----------|
3+
| 0 | kb:file-1 |
4+
| 1 | kb:file-2 |

tests/case_utils/case_sparql_select/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ top_srcdir := $(shell cd ../../.. ; pwd)
1818
tests_srcdir := $(top_srcdir)/tests
1919

2020
all: \
21+
prefixed_results.html \
22+
prefixed_results.md \
2123
subclass-explicit-none.md \
2224
subclass-implicit-any.md \
2325
w3-output.html \
@@ -37,8 +39,23 @@ all: \
3739
check: \
3840
check-w3-html \
3941
check-w3-markdown \
42+
check-prefixed_results \
4043
check-subclass
4144

45+
check-prefixed_results: \
46+
check-prefixed_results-html \
47+
check-prefixed_results-md
48+
49+
check-prefixed_results-html: \
50+
.check-prefixed_results.html \
51+
prefixed_results.html
52+
diff $^
53+
54+
check-prefixed_results-md: \
55+
.check-prefixed_results.md \
56+
prefixed_results.md
57+
diff $^
58+
4259
check-subclass: \
4360
check-subclass-explicit-none \
4461
check-subclass-implicit-any
@@ -71,6 +88,21 @@ clean:
7188
*.md \
7289
_*
7390

91+
prefixed_results.%: \
92+
$(tests_srcdir)/.venv.done.log \
93+
$(top_srcdir)/case_utils/case_sparql_select/__init__.py \
94+
$(top_srcdir)/case_utils/ontology/__init__.py \
95+
$(top_srcdir)/case_utils/ontology/version_info.py \
96+
subclass.json \
97+
subclass.sparql
98+
source $(tests_srcdir)/venv/bin/activate \
99+
&& case_sparql_select \
100+
--use-prefixes \
101+
_$@ \
102+
subclass.sparql \
103+
subclass.json
104+
mv _$@ $@
105+
74106
subclass-explicit-none.md: \
75107
$(tests_srcdir)/.venv.done.log \
76108
$(top_srcdir)/case_utils/case_sparql_select/__init__.py \

0 commit comments

Comments
 (0)