|
26 | 26 | Should a more complex query be necessary, an outer, wrapping SELECT query would let this script continue to function. |
27 | 27 | """ |
28 | 28 |
|
29 | | -__version__ = "0.5.0" |
| 29 | +__version__ = "0.5.1" |
30 | 30 |
|
31 | 31 | import argparse |
32 | 32 | import binascii |
@@ -86,26 +86,27 @@ def graph_and_query_to_data_frame( |
86 | 86 | select_query_object = rdflib.plugins.sparql.processor.prepareQuery( |
87 | 87 | select_query_text, initNs=nsdict |
88 | 88 | ) |
89 | | - for (row_no, row) in enumerate(_graph.query(select_query_object)): |
| 89 | + for row_no, row in enumerate(_graph.query(select_query_object)): |
| 90 | + assert isinstance(row, rdflib.query.ResultRow) |
90 | 91 | tally = row_no + 1 |
91 | 92 | record = [] |
92 | | - for (column_no, column) in enumerate(row): |
| 93 | + for column_no, column in enumerate(row): |
93 | 94 | if column is None: |
94 | 95 | column_value = "" |
95 | | - elif ( |
96 | | - isinstance(column, rdflib.term.Literal) |
97 | | - and column.datatype == NS_XSD.hexBinary |
98 | | - ): |
99 | | - # Use hexlify to convert xsd:hexBinary to ASCII. |
100 | | - # The render to ASCII is in support of this script rendering results for website viewing. |
101 | | - # .decode() is because hexlify returns bytes. |
102 | | - column_value = binascii.hexlify(column.toPython()).decode() |
| 96 | + elif isinstance(column, rdflib.term.Literal): |
| 97 | + if column.datatype == NS_XSD.hexBinary: |
| 98 | + # Use hexlify to convert xsd:hexBinary to ASCII. |
| 99 | + # The render to ASCII is in support of this script rendering results for website viewing. |
| 100 | + # .decode() is because hexlify returns bytes. |
| 101 | + column_value = binascii.hexlify(column.toPython()).decode() |
| 102 | + else: |
| 103 | + column_value = column.toPython() |
103 | 104 | elif isinstance(column, rdflib.URIRef): |
104 | 105 | if use_prefixes: |
105 | 106 | column_value = graph.namespace_manager.qname(column.toPython()) |
106 | 107 | else: |
107 | 108 | column_value = column.toPython() |
108 | | - else: |
| 109 | + elif isinstance(column, rdflib.BNode): |
109 | 110 | column_value = column.toPython() |
110 | 111 | if row_no == 0: |
111 | 112 | _logger.debug("row[0]column[%d] = %r." % (column_no, column_value)) |
|
0 commit comments