def reAjustBorders(self, words, messages): vSpliter = vertical_splitter(messages) words = vSpliter.splitWordsSimple(words) Nodes = [] typeInfer = WholeFieldTypeInfer(messages) mgerItoms = base_merger() for word in words: if typeInfer.inferConst(word): tNode = node(loc=word, wType=1) else: tNode = node(loc=word, wType=6) Nodes.append(tNode) return mgerItoms.merge_words(Nodes)
def symbolsToTree(self, formats, path): nodeRoot = node(wType='root') for f in formats: nodeT = self.subSymbolToTree(f) nodeRoot.children.append(nodeT) nodeRoot.showTree(0) self.Tgraph.graph_buildFour(nodeRoot, path)
def FormatInferCirclelyTestTwo(self, messages, tPath, wTtpe): fFormats = self.textcls.FormatInferCirclely(messages, wTtpe) nodeRoot = node(wType='root') for f in fFormats: nodeT = self.txtSymTree.subSymbolToTree(f) nodeRoot.children.append(nodeT) nodeRoot.showTree(0) self.Tgraph.graph_buildFour(nodeRoot, tPath)
def testGraphBuild(self): self.Node.word_type = 'root' cone = node(wType='F') cone.value.append('111') ctwo = node(wType='C') cone.value.append('222') self.Node.children.append(cone) self.Node.children.append(ctwo) Nodes = [] Edges = [] print(' ') print(id(ctwo.children)) print(id(cone.children)) print(' ') self.Node.getGraph(0, Nodes, Edges) print(Nodes) print(Edges)
def icsSymToTree(self, gFormat, cFormats, h=10): gNodeFirst, gNodeLast = self.transLineToNodes(gFormat[0:len(gFormat)-1]) for cFormat in cFormats: tFuncNode = node() tType = 'F' + ',' + str(len(cFormat)) + ',' + str(cFormat) tFuncNode.value.append(tType) tCformat,_ = self.transLineToNodes(cFormats[cFormat], h=3) tFuncNode.children.append(tCformat) gNodeLast.children.append(tFuncNode) return gNodeFirst
def getSubTree(self, fields): tNodes = [] for field in fields: if field.domain.currentValue != None: tValue = field.domain.currentValue.tobytes() tNode = node(wType='C') tNode.value.append('CRLF'.join( [str(v) for v in tValue.split(b'\r\n')])) leafs = field.getLeafFields(1) if len(leafs) > 0 and leafs[0] != field: tNode.children = self.getSubTree(leafs) tNodes.append(tNode) else: tNode = node(wType='V') leafs = field.getLeafFields(1) if len(leafs) > 0 and leafs[0] != field: tNode.children = self.getSubTree(leafs) tNodes.append(tNode) return tNodes
def formatInfer(self): #msgs = self.dataTuning.textReadDatasTemp('') msgs = self.dataTuning.readDatasByType('textPro') message_parser = TextParseLogic() srcmessages = message_parser.ConvertDataToMessage(msgs, b'\r\n', h=2) # future #textCls = TextClassifyLogic(srcmessages, 0.05, 0.2, 0.2, 3) textCls = TextClassifyLogic(srcmessages, 0.1, 0.2, 0.2, 3) formats = textCls.formatInfer(srcmessages) nodeRoot = node(wType='root') textSymTree = TextSympolToTree() for f in formats: nodeT = textSymTree.subSymbolToTree(f) nodeRoot.children.append(nodeT) return nodeRoot.transToDictTree()
def transLineToNodes(self, words, h=10): nodes = [] for word in words: wType = self.wTInfer.cVertNumToName(word[1]) sNode = '' if wType == 'Payload': sNode = sNode + wType + ',' + '-1' else: sNode = sNode + wType + ',' + str(word[0][1] - word[0][0]) tNode = node() tNode.value.append(sNode) nodes.append(tNode) t_len = min(len(words), h) i = t_len - 2 while(i >= 0): nodes[i].children.append(nodes[i+1]) i = i - 1 return nodes[0], nodes[t_len-1]
def getsubTreeTwo(self, fields): tNodes = [] for field in fields: if field.domain.currentValue != None: tValue = field.domain.currentValue.tobytes() if tValue.find(b'\r\n' != -1): splitDatas = tValue.split(b'\r\n') tLen = len(splitDatas) i = 0 while i < tLen - 2: tNode = node(wType='C') tNode.value.append(splitDatas[i]) tNodes.append(tNode) tNode = node(wType='C') tNode.value.append('CRLF') tNodes.append(tNode) i = i + 1 tNode = node(wType='C') tNode.value.append(splitDatas[i]) tNodes.append(tNode) if tValue[-2:] == b'\r\n': tNode = node(wType='C') tNode.value.append('CRLF') tNodes.append(tNode) else: tNode = node(wType='C') tNode.value.append(tValue) tNodes.append(tNode) leafs = field.getLeafFields(1) if len(leafs) > 0 and leafs[0] != field: tNode.children = self.getSubTree(leafs) #tNodes.append(tNode) else: tNode = node(wType='V') leafs = field.getLeafFields(1) if len(leafs) > 0 and leafs[0] != field: tNode.children = self.getSubTree(leafs) tNodes.append(tNode) return tNodes
def __init__(self): self.Node = node()
def symbolToTree(self, symbolOne): nodeRoot = node(wType='root') nodeRoot.children = self.getSubTree(symbolOne.fields) return nodeRoot