summaryrefslogtreecommitdiff
path: root/rdflib/tools
diff options
context:
space:
mode:
authorEdmond Chuc <e.chuc@uq.edu.au>2021-07-08 16:12:15 +1000
committerEdmond Chuc <e.chuc@uq.edu.au>2021-07-08 16:12:15 +1000
commit26dba21d0562fdc8141cf758c61e14dd9edfa972 (patch)
tree5036b6f37cbd834f948091b96247db8d31dcac73 /rdflib/tools
parent8b1d6e5eccf285d6a5a8c252103815c43c4df2ad (diff)
parenta21d458e78837fee7a27b103d2f107ddbcc2c52e (diff)
downloadrdflib-26dba21d0562fdc8141cf758c61e14dd9edfa972.tar.gz
Merge branch 'master' into hsolbrig/master
# Conflicts: # rdflib/__init__.py # rdflib/compat.py # rdflib/namespace/__init__.py # rdflib/plugins/parsers/rdfxml.py # rdflib/plugins/serializers/rdfxml.py # rdflib/tools/csv2rdf.py # test/test_dawg.py # test/test_namespace.py # test/test_nt_misc.py # test/test_rdfxml.py # test/test_seq.py # test/test_trig.py # test/testutils.py
Diffstat (limited to 'rdflib/tools')
-rw-r--r--rdflib/tools/csv2rdf.py13
-rw-r--r--rdflib/tools/graphisomorphism.py2
-rw-r--r--rdflib/tools/rdf2dot.py36
-rw-r--r--rdflib/tools/rdfpipe.py6
-rw-r--r--rdflib/tools/rdfs2dot.py20
5 files changed, 34 insertions, 43 deletions
diff --git a/rdflib/tools/csv2rdf.py b/rdflib/tools/csv2rdf.py
index 7034f1a7..f1acf9e0 100644
--- a/rdflib/tools/csv2rdf.py
+++ b/rdflib/tools/csv2rdf.py
@@ -1,12 +1,12 @@
"""
-A commandline tool for semi-automatically converting CSV to RDF
+A commandline tool for semi-automatically converting CSV to RDF.
+
+See also https://github.com/RDFLib/pyTARQL in the RDFlib family of tools
try: ``csv2rdf --help``
"""
-from __future__ import print_function
-
import sys
import re
import csv
@@ -126,8 +126,7 @@ def csv_reader(csv_data, dialect=csv.excel, **kwargs):
csv_reader = csv.reader(csv_data, dialect=dialect, **kwargs)
for row in csv_reader:
- # decode UTF-8 back to Unicode, cell by cell:
- yield [str(cell, "utf-8", errors="replace") for cell in row]
+ yield row
def prefixuri(x, prefix, class_=None):
@@ -315,7 +314,7 @@ class CSV2RDF(object):
self.COLUMNS = {}
self.PROPS = {}
- self.OUT = codecs.getwriter("utf-8")(sys.stdout, errors="replace")
+ self.OUT = sys.stdout
self.triples = 0
@@ -346,7 +345,7 @@ class CSV2RDF(object):
next(csvreader)
# read header line
- header_labels = list(csvreader.next())
+ header_labels = list(next(csvreader))
headers = dict(enumerate([self.PROPBASE[toProperty(x)] for x in header_labels]))
# override header properties if some are given
for k, v in self.PROPS.items():
diff --git a/rdflib/tools/graphisomorphism.py b/rdflib/tools/graphisomorphism.py
index a073d7d9..fbb31c0e 100644
--- a/rdflib/tools/graphisomorphism.py
+++ b/rdflib/tools/graphisomorphism.py
@@ -3,8 +3,6 @@ A commandline tool for testing if RDF graphs are isomorpic, i.e. equal
if BNode labels are ignored.
"""
-from __future__ import absolute_import
-
from rdflib import Graph
from rdflib import BNode
from itertools import combinations
diff --git a/rdflib/tools/rdf2dot.py b/rdflib/tools/rdf2dot.py
index 9b622b66..1e202d40 100644
--- a/rdflib/tools/rdf2dot.py
+++ b/rdflib/tools/rdf2dot.py
@@ -9,13 +9,11 @@ You can draw the graph of an RDF file directly:
"""
-from __future__ import absolute_import
-
import rdflib
import rdflib.extras.cmdlineutils
import sys
-import cgi
+import html
import collections
from rdflib import XSD
@@ -108,12 +106,12 @@ def rdf2dot(g, stream, opts={}):
return x
def formatliteral(l, g):
- v = cgi.escape(l)
+ v = html.escape(l)
if l.datatype:
- return u"&quot;%s&quot;^^%s" % (v, qname(l.datatype, g))
+ return "&quot;%s&quot;^^%s" % (v, qname(l.datatype, g))
elif l.language:
- return u"&quot;%s&quot;@%s" % (v, l.language)
- return u"&quot;%s&quot;" % v
+ return "&quot;%s&quot;@%s" % (v, l.language)
+ return "&quot;%s&quot;" % v
def qname(x, g):
try:
@@ -125,7 +123,7 @@ def rdf2dot(g, stream, opts={}):
def color(p):
return "BLACK"
- stream.write(u'digraph { \n node [ fontname="DejaVu Sans" ] ; \n')
+ stream.write('digraph { \n node [ fontname="DejaVu Sans" ] ; \n')
for s, p, o in g:
sn = node(s)
@@ -134,28 +132,28 @@ def rdf2dot(g, stream, opts={}):
if isinstance(o, (rdflib.URIRef, rdflib.BNode)):
on = node(o)
opstr = (
- u"\t%s -> %s [ color=%s, label=< <font point-size='10' "
- + u"color='#336633'>%s</font> > ] ;\n"
+ "\t%s -> %s [ color=%s, label=< <font point-size='10' "
+ + "color='#336633'>%s</font> > ] ;\n"
)
stream.write(opstr % (sn, on, color(p), qname(p, g)))
else:
fields[sn].add((qname(p, g), formatliteral(o, g)))
for u, n in nodes.items():
- stream.write(u"# %s %s\n" % (u, n))
+ stream.write("# %s %s\n" % (u, n))
f = [
- u"<tr><td align='left'>%s</td><td align='left'>%s</td></tr>" % x
+ "<tr><td align='left'>%s</td><td align='left'>%s</td></tr>" % x
for x in sorted(fields[n])
]
opstr = (
- u"%s [ shape=none, color=%s label=< <table color='#666666'"
- + u" cellborder='0' cellspacing='0' border='1'><tr>"
- + u"<td colspan='2' bgcolor='grey'><B>%s</B></td></tr><tr>"
- + u"<td href='%s' bgcolor='#eeeeee' colspan='2'>"
- + u"<font point-size='10' color='#6666ff'>%s</font></td>"
- + u"</tr>%s</table> > ] \n"
+ "%s [ shape=none, color=%s label=< <table color='#666666'"
+ + " cellborder='0' cellspacing='0' border='1'><tr>"
+ + "<td colspan='2' bgcolor='grey'><B>%s</B></td></tr><tr>"
+ + "<td href='%s' bgcolor='#eeeeee' colspan='2'>"
+ + "<font point-size='10' color='#6666ff'>%s</font></td>"
+ + "</tr>%s</table> > ] \n"
)
- stream.write(opstr % (n, NODECOLOR, label(u, g), u, u, u"".join(f)))
+ stream.write(opstr % (n, NODECOLOR, html.escape(label(u, g)), u, html.escape(u), "".join(f)))
stream.write("}\n")
diff --git a/rdflib/tools/rdfpipe.py b/rdflib/tools/rdfpipe.py
index 6ec9e6c2..98749487 100644
--- a/rdflib/tools/rdfpipe.py
+++ b/rdflib/tools/rdfpipe.py
@@ -5,8 +5,6 @@ A commandline tool for parsing RDF in different formats and serializing the
resulting graph to a chosen format.
"""
-from __future__ import absolute_import
-
import sys
from optparse import OptionParser
import logging
@@ -189,8 +187,8 @@ def main():
logging.basicConfig(level=loglevel)
ns_bindings = {}
- if opts.ns:
- for ns_kw in opts.ns:
+ if opts.LOVE:
+ for ns_kw in opts.LOVE:
pfx, uri = ns_kw.split("=")
ns_bindings[pfx] = uri
diff --git a/rdflib/tools/rdfs2dot.py b/rdflib/tools/rdfs2dot.py
index e8cf5813..cb8d0bfd 100644
--- a/rdflib/tools/rdfs2dot.py
+++ b/rdflib/tools/rdfs2dot.py
@@ -9,8 +9,6 @@ You can draw the graph of an RDFS file directly:
rdf2dot my_rdfs_file.rdf | dot -Tpng | display
"""
-from __future__ import absolute_import
-
import rdflib.extras.cmdlineutils
import sys
@@ -98,7 +96,7 @@ def rdfs2dot(g, stream, opts={}):
pass # bnodes and some weird URIs cannot be split
return l_
- stream.write(u'digraph { \n node [ fontname="DejaVu Sans" ] ; \n')
+ stream.write('digraph { \n node [ fontname="DejaVu Sans" ] ; \n')
for x in g.subjects(RDF.type, RDFS.Class):
n = node(x)
@@ -106,7 +104,7 @@ def rdfs2dot(g, stream, opts={}):
for x, y in g.subject_objects(RDFS.subClassOf):
x = node(x)
y = node(y)
- stream.write(u"\t%s -> %s [ color=%s ] ;\n" % (y, x, ISACOLOR))
+ stream.write("\t%s -> %s [ color=%s ] ;\n" % (y, x, ISACOLOR))
for x in g.subjects(RDF.type, RDF.Property):
for a, b in itertools.product(
@@ -125,18 +123,18 @@ def rdfs2dot(g, stream, opts={}):
)
for u, n in nodes.items():
- stream.write(u"# %s %s\n" % (u, n))
+ stream.write("# %s %s\n" % (u, n))
f = [
- u"<tr><td align='left'>%s</td><td>%s</td></tr>" % x
+ "<tr><td align='left'>%s</td><td>%s</td></tr>" % x
for x in sorted(fields[n])
]
opstr = (
- u"%s [ shape=none, color=%s label=< <table color='#666666'"
- + u' cellborder="0" cellspacing=\'0\' border="1"><tr>'
- + u"<td colspan=\"2\" bgcolor='grey'><B>%s</B></td>"
- + u"</tr>%s</table> > ] \n"
+ "%s [ shape=none, color=%s label=< <table color='#666666'"
+ + " cellborder='0' cellspacing='0' border='1'><tr>"
+ + "<td colspan='2' bgcolor='grey'><B>%s</B></td>"
+ + "</tr>%s</table> > ] \n"
)
- stream.write(opstr % (n, NODECOLOR, label(u, g), u"".join(f)))
+ stream.write(opstr % (n, NODECOLOR, label(u, g), "".join(f)))
stream.write("}\n")