我每次编译时都会得到一个随机的有序字典,即使使用有序字典也是如此。我使用字典来表示树,因此尊重节点的顺序很重要。我曾尝试使用python 3.6和3.7
var x = r * cos(angle)
var y = r * sin(angle)
point(x, y);
预期结果:
class NP: #NounPhrase
def __init__(self, anchor = None, number = None):
self.anchor = anchor
self.number = number
class VP: #VerbPhrase
def __init__(self, anchor = None , person = None, tense = None):
self.person = person
self.tense = tense
self.anchor = anchor
class Tree:
def __init__(self, tree, sust = None, insert = None, anchor = None, terminal = None):
self.tree = tree
self.sust = sust
self.insert = insert
self.root = self.getRoot()
def getRoot(self):
return list(self.tree.keys())[0]
class TreeForest:
def makeIntransitiveVerb(text):
vp = VP(text)
return Tree( OrderedDict({ VP:{ NP , vp }}) )
verb = TreeForest.makeIntransitiveVerb("showed up")
print(verb.tree)
实际结果:
{< class '__main__.VP' > : { < class '__main__.NP' > , < __main__.VP object at 0x7f4b81fd8b90>}}
或
{< class '__main__.VP' >: {< __main__.VP object at 0x7f4b81fd8b90 >, < class '__main__.NP' >}})