Added a python parser for names
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
parent
26f0702c5a
commit
4f134725ec
|
@ -0,0 +1,69 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import csv
|
||||||
|
|
||||||
|
class Type(Enum):
|
||||||
|
Humans,
|
||||||
|
Prokaryotes,
|
||||||
|
Photosynthesizers,
|
||||||
|
Eukaryotic,
|
||||||
|
Dinosaurs,
|
||||||
|
Viruses
|
||||||
|
|
||||||
|
class GraphNode:
|
||||||
|
def __init__(self, children : list[GraphNode] = [], parent : GraphNode = None, name="", description="", typ : Type = None):
|
||||||
|
self.children = children
|
||||||
|
self.name = name
|
||||||
|
self.description = description
|
||||||
|
|
||||||
|
def add_child(self, child : GraphNode) -> None:
|
||||||
|
self.children += child
|
||||||
|
|
||||||
|
def remove_child(self, name : str) -> GraphNode or None:
|
||||||
|
for c in self.children:
|
||||||
|
if name == c.name:
|
||||||
|
self.children.remove(c)
|
||||||
|
|
||||||
|
def set_parent(self, parent : GraphNode) -> None:
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
|
def set_name(self, name:str) -> None:
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
def set_desc(self, desc:str) -> None:
|
||||||
|
self.description = desc
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
multi_word_names = ["old world monkeys",
|
||||||
|
"homo sapiens",
|
||||||
|
"new world monkeys",
|
||||||
|
"birds (avies)",
|
||||||
|
"water lillies",
|
||||||
|
"star anis & relatives",
|
||||||
|
"vascular plants",
|
||||||
|
"brown algae",
|
||||||
|
"excavata (protists)",
|
||||||
|
"sar protists",
|
||||||
|
"seed plants",
|
||||||
|
"red algae",
|
||||||
|
"slime molds",
|
||||||
|
"cellular slime molds",
|
||||||
|
"plasmodial slime molds",
|
||||||
|
"gram positive bacteria",
|
||||||
|
"lemures lorises and bush babies"]
|
||||||
|
filename = "in.txt"
|
||||||
|
outfile = "parsed.txt"
|
||||||
|
nodes = []
|
||||||
|
with open(filename) as f:
|
||||||
|
current_node = None
|
||||||
|
for line in f:
|
||||||
|
in_body = False
|
||||||
|
if (len(line) == 1 or line in multi_word_names) and not in_body:
|
||||||
|
node = GraphNode(name=line)
|
||||||
|
current_node = node
|
||||||
|
nodes.append(node)
|
||||||
|
else:
|
||||||
|
current_node.description = line
|
||||||
|
|
||||||
|
|
||||||
|
for node in nodes:
|
Loading…
Reference in New Issue