Skip to content

case_sparql_select: Add --use-prefixes flag #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions case_utils/case_sparql_select/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def main() -> None:
action="store_true",
help="Raise error if no results are returned for query.",
)
parser.add_argument(
"--use-prefixes",
action="store_true",
help="Abbreviate node IDs according to graph's encoded prefixes. (This will use prefixes in the graph, not the query.)",
)
parser.add_argument(
"out_table",
help="Expected extensions are .html for HTML tables or .md for Markdown tables.",
Expand Down Expand Up @@ -124,6 +129,11 @@ def main() -> None:
# The render to ASCII is in support of this script rendering results for website viewing.
# .decode() is because hexlify returns bytes.
column_value = binascii.hexlify(column.toPython()).decode()
elif isinstance(column, rdflib.URIRef):
if args.use_prefixes:
column_value = graph.namespace_manager.qname(column.toPython())
else:
column_value = column.toPython()
else:
column_value = column.toPython()
if row_no == 0:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<table border="1" class="dataframe table table-bordered table-condensed">
<thead>
<tr style="text-align: right;">
<th></th>
<th>?nFile</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>kb:file-1</td>
</tr>
<tr>
<th>1</th>
<td>kb:file-2</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| | ?nFile |
|----|-----------|
| 0 | kb:file-1 |
| 1 | kb:file-2 |
33 changes: 33 additions & 0 deletions tests/case_utils/case_sparql_select/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ top_srcdir := $(shell cd ../../.. ; pwd)
tests_srcdir := $(top_srcdir)/tests

all: \
prefixed_results.html \
prefixed_results.md \
subclass-explicit-none.md \
subclass-implicit-any.md \
w3-output.html \
Expand All @@ -31,14 +33,30 @@ all: \
check-w3-markdown

.PRECIOUS: \
prefixed_results.% \
subclass-% \
w3-output.%

check: \
check-w3-html \
check-w3-markdown \
check-prefixed_results \
check-subclass

check-prefixed_results: \
check-prefixed_results-html \
check-prefixed_results-md

check-prefixed_results-html: \
.check-prefixed_results.html \
prefixed_results.html
diff $^

check-prefixed_results-md: \
.check-prefixed_results.md \
prefixed_results.md
diff $^

check-subclass: \
check-subclass-explicit-none \
check-subclass-implicit-any
Expand Down Expand Up @@ -71,6 +89,21 @@ clean:
*.md \
_*

prefixed_results.%: \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/case_utils/case_sparql_select/__init__.py \
$(top_srcdir)/case_utils/ontology/__init__.py \
$(top_srcdir)/case_utils/ontology/version_info.py \
subclass.json \
subclass.sparql
source $(tests_srcdir)/venv/bin/activate \
&& case_sparql_select \
--use-prefixes \
_$@ \
subclass.sparql \
subclass.json
mv _$@ $@

subclass-explicit-none.md: \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/case_utils/case_sparql_select/__init__.py \
Expand Down
18 changes: 18 additions & 0 deletions tests/case_utils/case_sparql_select/prefixed_results.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<table border="1" class="dataframe table table-bordered table-condensed">
<thead>
<tr style="text-align: right;">
<th></th>
<th>?nFile</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>kb:file-1</td>
</tr>
<tr>
<th>1</th>
<td>kb:file-2</td>
</tr>
</tbody>
</table>
4 changes: 4 additions & 0 deletions tests/case_utils/case_sparql_select/prefixed_results.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| | ?nFile |
|----|-----------|
| 0 | kb:file-1 |
| 1 | kb:file-2 |