2016-10-20 22:40:27 +04:00
|
|
|
from pyFTS import *
|
|
|
|
from functools import reduce
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
class FLRGTreeNode:
|
2016-12-22 20:36:50 +04:00
|
|
|
def __init__(self, value):
|
|
|
|
self.isRoot = False
|
|
|
|
self.children = []
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def appendChild(self, child):
|
|
|
|
self.children.append(child)
|
|
|
|
|
|
|
|
def getChildren(self):
|
|
|
|
for child in self.children:
|
|
|
|
yield child
|
|
|
|
|
|
|
|
def paths(self, acc=[]):
|
|
|
|
if len(self.children) == 0:
|
|
|
|
yield [self.value] + acc
|
|
|
|
|
|
|
|
for child in self.children:
|
|
|
|
for leaf_path in child.paths([self.value] + acc): # these two
|
|
|
|
yield leaf_path
|
|
|
|
|
|
|
|
def getStr(self, k):
|
|
|
|
if self.isRoot:
|
|
|
|
tmp = str(self.value)
|
|
|
|
else:
|
|
|
|
tmp = "\\" + ("-" * k) + str(self.value)
|
|
|
|
for child in self.getChildren():
|
|
|
|
tmp = tmp + "\n" + child.getStr(k + 1)
|
|
|
|
return tmp
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.getStr(0)
|
|
|
|
|
2016-10-20 22:40:27 +04:00
|
|
|
|
|
|
|
class FLRGTree:
|
2017-05-05 22:33:27 +04:00
|
|
|
"""Represents a FLRG set with a tree structure"""
|
2016-12-22 20:36:50 +04:00
|
|
|
def __init__(self):
|
|
|
|
self.root = FLRGTreeNode(None)
|
|
|
|
|
2016-10-20 22:40:27 +04:00
|
|
|
|
|
|
|
def flat(dados):
|
2016-12-22 20:36:50 +04:00
|
|
|
for inst in dados:
|
|
|
|
if isinstance(inst, (list, tuple)):
|
|
|
|
x = flat(inst)
|
|
|
|
for k in x:
|
|
|
|
yield k
|
|
|
|
else:
|
|
|
|
yield inst
|