diff options
author | nicholascar <nicholas.car@surroundaustralia.com> | 2021-12-16 09:19:46 +1000 |
---|---|---|
committer | nicholascar <nicholas.car@surroundaustralia.com> | 2021-12-16 09:19:46 +1000 |
commit | 28288b07074125d87be849d23a53c19605d78b5b (patch) | |
tree | d30b934934c035ea351372687b98b9a3599e1bad /rdflib/tools | |
parent | 74302bcf993777c7f7ae494aaf4953c05724d4f3 (diff) | |
download | rdflib-28288b07074125d87be849d23a53c19605d78b5b.tar.gz |
style fixes only
Diffstat (limited to 'rdflib/tools')
-rw-r--r-- | rdflib/tools/defined_namespace_creator.py | 30 | ||||
-rw-r--r-- | rdflib/tools/rdfs2dot.py | 22 |
2 files changed, 25 insertions, 27 deletions
diff --git a/rdflib/tools/defined_namespace_creator.py b/rdflib/tools/defined_namespace_creator.py index 82803f9d..f3eeaecf 100644 --- a/rdflib/tools/defined_namespace_creator.py +++ b/rdflib/tools/defined_namespace_creator.py @@ -82,7 +82,9 @@ def get_target_namespace_elements(g, target_namespace): # only get results for the target namespace (supplied by user) FILTER STRSTARTS(STR(?s), "xxx") } - """.replace("xxx", target_namespace) + """.replace( + "xxx", target_namespace + ) elements = [] for r in g.query(q, initNs=namespaces): elements.append((str(r[0]), str(r[1]))) @@ -92,7 +94,9 @@ def get_target_namespace_elements(g, target_namespace): elements_strs = [] for e in elements: desc = e[1].replace('\n', ' ') - elements_strs.append(f" {e[0].replace(args.target_namespace, '')}: URIRef # {desc}\n") + elements_strs.append( + f" {e[0].replace(args.target_namespace, '')}: URIRef # {desc}\n" + ) return elements, elements_strs @@ -134,7 +138,7 @@ if __name__ == "__main__": "target_namespace", type=str, help="The namespace within the ontology that you want to create a " - "DefinedNamespace for.", + "DefinedNamespace for.", ) parser.add_argument( @@ -144,11 +148,12 @@ if __name__ == "__main__": ) parser.add_argument( - '-f', "--fail", + '-f', + "--fail", dest='fail', action='store_true', help="Whether (true) or not (false) to mimic ClosedNamespace and fail on " - "non-element use" + "non-element use", ) parser.add_argument('--no-fail', dest='fail', action='store_false') parser.set_defaults(feature=False) @@ -165,8 +170,10 @@ if __name__ == "__main__": validate_object_id(args.object_id) - print(f"Creating DefinedNamespace file {args.object_id} " - f"for {args.target_namespace}...") + print( + f"Creating DefinedNamespace file {args.object_id} " + f"for {args.target_namespace}..." + ) print(f"Ontology with {len(g)} triples loaded...") print("Getting all namespace elements...") @@ -175,12 +182,5 @@ if __name__ == "__main__": output_file_name = Path().cwd() / f"_{args.object_id}.py" print(f"Creating DefinedNamespace Python file {output_file_name}") make_dn_file( - output_file_name, - args.target_namespace, - elements[1], - args.object_id, - args.fail + output_file_name, args.target_namespace, elements[1], args.object_id, args.fail ) - - - diff --git a/rdflib/tools/rdfs2dot.py b/rdflib/tools/rdfs2dot.py index cb8d0bfd..a9eeb244 100644 --- a/rdflib/tools/rdfs2dot.py +++ b/rdflib/tools/rdfs2dot.py @@ -80,21 +80,19 @@ def rdfs2dot(g, stream, opts={}): fields = collections.defaultdict(set) nodes = {} - def node(x): - - if x not in nodes: - nodes[x] = "node%d" % len(nodes) - return nodes[x] - - def label(x, g): - - l_ = g.value(x, RDFS.label) - if l_ is None: + def node(nd): + if nd not in nodes: + nodes[nd] = "node%d" % len(nodes) + return nodes[nd] + + def label(xx, grf): + lbl = g.value(xx, RDFS.label) + if lbl is None: try: - l_ = g.namespace_manager.compute_qname(x)[2] + lbl = grf.namespace_manager.compute_qname(xx)[2] except: pass # bnodes and some weird URIs cannot be split - return l_ + return lbl stream.write('digraph { \n node [ fontname="DejaVu Sans" ] ; \n') |