Skip to content
Snippets Groups Projects
Commit b3565f79 authored by Eliott Sammier's avatar Eliott Sammier
Browse files

Code formatting

parent b5c0e2fe
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,7 @@ import extract_mosetp
def dump_graph(g: Graph):
"""Print all triples in the graph
"""
"""Print all triples in the graph"""
for subj, pred, obj in g:
print(subj, pred, obj)
......@@ -31,26 +30,26 @@ def export_graph(g: Graph):
imports = BNode()
g.add((imports, RDF.type, OWL.Ontology))
g.add((imports, OWL.imports, URIRef(NS)))
g.serialize(OUT_FILE, 'turtle', base=NS)
g.serialize(OUT_FILE, "turtle", base=NS)
print(f"Exported {len(g)} triples to {OUT_FILE}.")
def ns_find(elem: etree.ElementBase, query: str):
"""Wrapper for lxml's `find()` function that automatically uses the default
namespace for all unprefixed tag names.
"""
return elem.find(query, namespaces={"": elem.nsmap[None]})
def ns_findall(elem: etree.ElementBase, query: str):
"""Wrapper for lxml's `findall()` function that automatically uses the default
namespace for all unprefixed tag names.
"""
return elem.findall(query, namespaces={"": elem.nsmap[None]})
def ns_localname(elem: etree.ElementBase) -> str:
"""Get an element's local name, stripping the namespace.
"""
"""Get an element's local name, stripping the namespace."""
return etree.QName(elem).localname
......
......@@ -46,7 +46,9 @@ def parse_mosetp(graph: Graph, filepath: str, id: str):
regex = re.compile(r'.*new PageContenu\("(.*)", "(.*)", "(.*)", ""\);')
# The lines we need are fairly basic, grep is much faster
# than a Python HTML parser to filter them
cmd = subprocess.run(["grep", "new PageContenu(", filepath], capture_output=True, encoding="utf-8")
cmd = subprocess.run(
["grep", "new PageContenu(", filepath], capture_output=True, encoding="utf-8"
)
if cmd.returncode == 0:
# Match regex on each line
for index, line in enumerate(cmd.stdout.splitlines()):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment