diff --git a/src/diana/sgfParser/collection.py b/src/diana/sgfParser/collection.py --- a/src/diana/sgfParser/collection.py +++ b/src/diana/sgfParser/collection.py @@ -1,25 +1,25 @@ from .node import Node -from . import skipWhitespace, ParserError +from . import skip_whitespace, ParserError from .gameRecord import GameRecord class Collection: def __init__(self, s): - self.gameTrees = [] - i = skipWhitespace(s, 0) + self.game_trees = [] + i = skip_whitespace(s, 0) if i >= len(s): return elif not GameTree.fits(s, i): raise ParserError("expected a GameTree starting with '('", s, i) while GameTree.fits(s, i): (i, x) = GameTree.create(s, i) - self.gameTrees.append(x) + self.game_trees.append(x) if i < len(s): raise ParserError("expected EOF", s, i) - def listGames(self): - for tree in self.gameTrees: - for game in tree.listGames(): + def list_games(self): + for tree in self.game_trees: + for game in tree.list_games(): yield game @@ -37,7 +37,7 @@ class GameTree: assert GameTree.fits(s, start) res = GameTree() - i = skipWhitespace(s, start+1) + i = skip_whitespace(s, start + 1) if not Node.fits(s, i): raise ParserError("expected a Node starting with ';'", s, i) @@ -46,48 +46,48 @@ class GameTree: (i, x) = Node.create(s, i) res.nodes.append(x) if y: - y.addChild(x) + y.add_child(x) x.parent = y y = x - i = skipWhitespace(s, i) + i = skip_whitespace(s, i) while GameTree.fits(s, i): (i, x) = GameTree.create(s, i) res.branches.append(x) - subroot = x.getNode(0) + subroot = x.get_node(0) subroot.parent = y if y: - y.addChild(subroot) - i = skipWhitespace(s, i) + y.add_child(subroot) + i = skip_whitespace(s, i) if i >= len(s) or s[i] != ")": raise ParserError("expected end of a GameTree marked by ')'", s, i) - i = skipWhitespace(s, i+1) + i = skip_whitespace(s, i + 1) return (i, res) ## Expand multiple games into distinct GameTrees and yield each. - def listGames(self): + def list_games(self): if len(self.nodes) == 0: return None - for node in self.nodes[0].listGINodes(): - yield GameRecord(self._buildSubtree(node)) + for node in self.nodes[0].list_gi_nodes(): + yield GameRecord(self._build_subtree(node)) - def getNode(self, i): + def get_node(self, i): if 0 <= i < len(self.nodes): return self.nodes[i] return None ## Create and return a new game tree containing the provided Node. # - # Ancestor nodes are copied, descendants are moved from the seedNode. - def _buildSubtree(self, seedNode): - node = seedNode.copy() - node.setChildren(seedNode.children) - seedNode.children = [] + # Ancestor nodes are copied, descendants are moved from the seed_node. + def _build_subtree(self, seed_node): + node = seed_node.copy() + node.set_children(seed_node.children) + seed_node.children = [] while node.parent: - newNode = node.parent.copy() - newNode.addChild(node) - node = newNode + new_node = node.parent.copy() + new_node.add_child(node) + node = new_node return node