本文整理汇总了Python中Node.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: initFunction
def initFunction(self, fnNode, functionIndex, statements, functionType):
fnNode.itsFunctionType = functionType
fnNode.addChildToBack(statements)
functionCount = fnNode.getFunctionCount()
if (functionCount != 0):
fnNode.itsNeedsActivation = True
## for-while
i = 0
while (i != functionCount):
fn = fnNode.getFunctionNode(i)
if (fn.getFunctionType() == FunctionNode.FUNCTION_EXPRESSION_STATEMENT):
name = fn.getFunctionName()
if name is not None and (len(name) != 0):
fnNode.removeParamOrVar(name)
i += 1
if (functionType == FunctionNode.FUNCTION_EXPRESSION):
name = fnNode.getFunctionName()
if (name is not None) and \
len(name) != 0 \
and (not fnNode.hasParamOrVar(name)):
if (fnNode.addVar(name) == ScriptOrFnNode.DUPLICATE_CONST):
self.parser.addError("msg.const.redecl", name)
setFn = Node(Token.EXPR_VOID, Node(Token.SETNAME, Node.newString(Token.BINDNAME, name), Node(Token.THISFN)))
statements.addChildrenToFront(setFn)
lastStmt = statements.getLastChild()
if lastStmt is None or (lastStmt.getType() != Token.RETURN):
statements.addChildToBack(Node(Token.RETURN))
result = Node.newString(Token.FUNCTION, fnNode.getFunctionName())
result.putIntProp(Node.FUNCTION_PROP, functionIndex)
return result
开发者ID:Mitame,项目名称:pynoceros,代码行数:31,代码来源:IRFactory.py
示例2: check_availablespace
def check_availablespace(self, maxinputsize, files):
"""
Verify that enough local space is available to stage in and run the job
"""
if not self.shouldVerifyStageIn():
return
totalsize = reduce(lambda x, y: x + y.filesize, files, 0)
# verify total filesize
if maxinputsize and totalsize > maxinputsize:
error = "Too many/too large input files (%s). Total file size=%s B > maxinputsize=%s B" % (len(files), totalsize, maxinputsize)
raise PilotException(error, code=PilotErrors.ERR_SIZETOOLARGE)
self.log("Total input file size=%s B within allowed limit=%s B (zero value means unlimited)" % (totalsize, maxinputsize))
# get available space
wn = Node()
wn.collectWNInfo(self.workDir)
available_space = int(wn.disk)*1024**2 # convert from MB to B
self.log("Locally available space: %d B" % available_space)
# are we wihin the limit?
if totalsize > available_space:
error = "Not enough local space for staging input files and run the job (need %d B, but only have %d B)" % (totalsize, available_space)
raise PilotException(error, code=PilotErrors.ERR_NOLOCALSPACE)
开发者ID:complynx,项目名称:pilot,代码行数:29,代码来源:base.py
示例3: __init__
def __init__(self, logp, doc, name, parents, cache_depth=2, plot=None, verbose=None, logp_partial_gradients = {}):
self.ParentDict = ParentDict
# This function gets used to evaluate self's value.
self._logp_fun = logp
self._logp_partial_gradients_functions = logp_partial_gradients
self.errmsg = "Potential %s forbids its parents' current values"%name
Node.__init__( self,
doc=doc,
name=name,
parents=parents,
cache_depth = cache_depth,
verbose=verbose)
self._plot = plot
# self._logp.force_compute()
# Check initial value
if not isinstance(self.logp, float):
raise ValueError, "Potential " + self.__name__ + "'s initial log-probability is %s, should be a float." %self.logp.__repr__()
开发者ID:jbwhit,项目名称:pymc,代码行数:27,代码来源:PyMCObjects.py
示例4: push
def push(self, value):
"""
Add value to top of Stack
"""
new_node = Node(value)
new_node.next = self.head
self.head = new_node
开发者ID:bfortuner,项目名称:boring-stuff,代码行数:7,代码来源:Stack.py
示例5: __init__
def __init__(self, LexNode):
Node.__init__(self, LexNode)
self.text = self.tokens.get('STRING', "")
self.type = self.tokens.get('TYPE', "boolean")
self.ID = self.tokens.get('ID', uuid.uuid4())
self.function = self.tokens.get('function', None)
开发者ID:guyromb,项目名称:many-ql,代码行数:7,代码来源:Question.py
示例6: test_delete
def test_delete():
bs_tree = BinarySearchTree()
keys = [5, 2, -4, 3, 12, 9 ,21, 19, 25]
for key in keys:
node = Node()
node.key = key
bs_tree.insert(node)
# delete leaf
bs_tree.delete(bs_tree.search(-4))
assert(bs_tree.search(-4) is None)
assert(bs_tree.search(2).left is None)
# delete node with one child
bs_tree.delete(bs_tree.search(2))
assert(bs_tree.search(2) is None)
assert(bs_tree.root.left.key == 3)
# delete node with two children
bs_tree.delete(bs_tree.search(12))
assert(bs_tree.root.right.key == 19)
assert(bs_tree.search(19).left.key == 9)
assert(bs_tree.search(19).right.key == 21)
# delete root
bs_tree.delete(bs_tree.root)
assert(bs_tree.root.key == 9)
assert(bs_tree.root.left.key == 3)
assert(bs_tree.root.right.key == 19)
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:31,代码来源:BinarySearchTree_test.py
示例7: push
def push(self, value):
new_node = Node(value, None, None)
new_node.previous = self.end.previous
new_node.next = self.end
self.end.previous.next = new_node
self.end.previous = new_node
self.size += 1
开发者ID:xym4,项目名称:PracticeDS,代码行数:7,代码来源:Stack.py
示例8: WaveletTree
class WaveletTree(object):
def __init__(self, data=None):
if data == None:
print "Please give correct parameters"
return
self.__root = Node(data) #Create the parent node
"""
Query Functions
"""
def rank_query(self,character=None, position=None):
if character==None or position==None or position <= 0:
print "Please give correct parameters"
return -1
return self.__root.get_rank_query(position,character)
def select_query(self,character=None, position=None):
if character==None or position==None or position <= 0:
print "Please give correct parameters"
return -1
return self.__root.get_select_query(position, character)
def track_symbol(self,position=None):
if position==None or position <= 0:
print "Please give correct parameters"
return -1
return self.__root.get_track_symbol(position)
"""
开发者ID:nectarios-ef,项目名称:Wavelet-Tree,代码行数:29,代码来源:WaveletTree.py
示例9: ID3
def ID3(X, Y, attrs, currentDepth, maxDepth=7):
currentDepth += 1
# If all examples are positive, Return the single-node tree Root, with label = +.
# If all examples are negative, Return the single-node tree Root, with label = -.
if len(set(Y)) == 1:
return Leaf(Y[0])
# If the number of predicting attributes is empty, then return a single node tree with
# Label = most common value of the target attribute in the examples
if len(attrs) == 0 or currentDepth == maxDepth:
return Leaf(majorityElement(Y))
# A = The Attribute that best classifies examples.
A = findBestFeatureIndex(X, Y, attrs)
newAttrs = [attr for attr in attrs if attr != A]
# Decision Tree attribute for Root = A.
root = Node(A)
# For each possible value, vi, of A
for possible_value in [0, 1]:
# Let Examples(vi) be the subset of examples that have the value vi for A
X_s, Y_s = splitData(X, Y, A, possible_value)
if len(X_s) == 0 or len(Y_s) == 0:
# Then below this new branch add a leaf node with label = most common target value in the examples
root.addChild(possible_value, Leaf(majorityElement(Y)))
else:
# Else below this node add a subtree ID3(Examples_vi, TargetAttr, Attrs - {A})
root.addChild(possible_value, ID3(X_s, Y_s, newAttrs, currentDepth, maxDepth))
return root
开发者ID:worldofnick,项目名称:Machine-Learning,代码行数:32,代码来源:main.py
示例10: main
def main():
#Test case 1
root = Node("Max", 23)
john = root.setLeft(Node("John", 18))
mark = john.setRight(Node("Ann", 22)).setRight(Node("Mark", 2))
rob = john.setLeft(Node("Rob", 12))
rob.setRight(Node("Bob", 4)).setLeft(Node("Mie", 6))
rob.setLeft(Node("Steven", 3)).setRight(Node("Sarah", 2))
annie = mark.setLeft(Node("Annie", 9))
annie.setRight(Node("Barnie", 42))
annie.setLeft(Node("Malcolm", 7)).setRight(Node("Susan", 5)).setRight(Node("Terry", 4))
assert root.left.right.right.left.right.name == "Barnie"
assert root.left.left.left.name == "Steven"
assert root.left.right.name == "Ann"
assert root.left.right.left == None
assert root.left.left.right.left.name == "Mie"
maxRating, invitedPeople = FindMaxRating(root)
assert maxRating == 109
assert [n.name for n in invitedPeople] == ['Steven', 'Sarah', 'Mie', 'John', 'Ann', 'Malcolm', 'Susan', 'Terry', 'Barnie']
print "Max rating for people {" + ", ".join(root.allChildren()) + "}: \n" + str(maxRating)
print "People invited: "
print [n.name for n in invitedPeople]
开发者ID:yurippe,项目名称:School,代码行数:27,代码来源:TestCase1.py
示例11: __init__
def __init__(self, function_name, given_type):
Node.__init__(self, function_name)
self.number_of_params = 0
self.return_type = None
self.type = given_type
# We only want to allow parameters to be added to each green node one time.
self.param_flag = False
开发者ID:tommygun101,项目名称:Code-ButternutSquash,代码行数:7,代码来源:GreenNode.py
示例12: harvest
def harvest(self, vf):
if not Harvester.harvest(self, vf):
return
mvf = vf.getMeta()
# determine grouping
groupTag = self.opts['group']
if groupTag == None:
# no grouping - stuff into root node
target = self.root
else:
# get the grouping value
if groupTag not in mvf:
grp = OTHER
else:
grp = mvf[groupTag]
if type(grp) is list:
raise ConfigError("Configuration Error - grouping item must not be a list")
if grp in self.nodeMap:
# if we've seen this group, then just reuse the
# same node
target = self.nodeMap[grp]
else:
# Otherwise create a new node and link it in
path=os.path.join(self.hpath, Legalize(grp))
target = Node(grp, self.opts, path=path, title = "%s: %s" %(metaTranslate(groupTag), grp))
self.pathMap[os.path.join(self.name, grp)] = path
self.nodeMap[grp] = target
self.root.addDir(target)
self.gcount += 1
target.addVideo(vf)
self.count += 1
开发者ID:jbernardis,项目名称:pytivo-video-mgr2,代码行数:34,代码来源:Meta.py
示例13: simulate
def simulate(self):
currentNode = Node(Sudoku(self.m_sudokuProblem, self.m_fixedNodes))
currentNode.m_sudoku.populate()
found = False
while not found:
self.m_temperature = self.scheduleTemp()
if currentNode.getValue() <= 0 and currentNode.m_sudoku.validateSudoku():
found = True
return currentNode
if self.m_temperature < 0.00027:
currentNode = self.reheat()
print "REHEAT"
nextNode = currentNode.getRandomSucessor()
deltaE = currentNode.getValue() - nextNode.getValue()
print nextNode.getValue()
probability = self.getProbability(deltaE)
if random.random() < probability:
currentNode = nextNode
开发者ID:provenchez,项目名称:AI,代码行数:25,代码来源:recuit_simule.py
示例14: r
def r():
root = Node("Max", 10000)
john = root.setLeft(Node("John", 1))
annie = john.setLeft(Node("Annie", 1))
jens = annie.setLeft(Node("Jens", 10000))
FindMaxRating(root)
开发者ID:yurippe,项目名称:School,代码行数:7,代码来源:TestCase3.py
示例15: construct
def construct(self, slice):
Node.construct(self, slice)
self.parent_index=self.parents_1[0]
assert(len(self.parents_0)==0)
assert(len(self.parents_1)==1)
parent_size=self.parents_1_sizes[0]
assert(self.node_size==parent_size)
self.mus_shape=(self.node_size,1)
self.kappas_shape=(self.node_size),
# Check or construct means
rnd_mus, rnd_kappas=self._make_rnd_kms(self.node_size)
# If the user has specified some values these are used
if not self.user_mus is None:
self.mus=self.user_mus
for i in range(0, self.node_size):
# Make sure we have angles in [0,2pi[
self.mus[i]=mod2pi(self.mus[i])
assert(self.mus.shape==self.mus_shape)
del self.user_mus
else:
# Otherwise the means are set to random values
self.mus=rnd_mus
# Check or construct kappa values
if not self.user_kappas is None:
self.kappas=self.user_kappas
assert(self.kappas.shape==self.kappas_shape)
del self.user_kappas
else:
self.kappas=rnd_kappas
self.vm_list, self.samplers=self._make_vm_list(self.mus, self.kappas, self.node_size)
开发者ID:andersx,项目名称:fragbuilder,代码行数:32,代码来源:VMNode.py
示例16: build
def build(self, array):
if len(array) > 0:
# counting the median, which is the key
median = IntervalTree.get_median_point(self, array)
# current Node
n = Node(median)
left = []
right = []
overlap = []
for i in range(0, len(array)):
if array[i].begin <= median <= array[i].end:
overlap.append(array[i])
elif array[i].end < median:
left.append(array[i])
elif array[i].begin > median:
right.append(array[i])
n.overlap_begin_sort = sorted(overlap, key=operator.attrgetter("begin"))
n.overlap_end_sort = sorted(overlap, key=operator.attrgetter("end"), reverse=True)
if self.root is None:
self.root = n
n.left = self.build(left)
n.right = self.build(right)
return n
else:
return None
开发者ID:LordPatriot,项目名称:itree,代码行数:30,代码来源:IntervalTree.py
示例17: __init__
def __init__(self, nodeType):
Node.__init__(self, nodeType)
self.itsVariableNames = ObjToIntMap(11)
self.itsVariables = []
self.itsConst = []
self.functions = []
self.regexps = []
开发者ID:Mitame,项目名称:pynoceros,代码行数:7,代码来源:ScriptOrFnNode.py
示例18: main
def main():
new_tree = Tree()
new_node = Node(url='ma suka', score=33, matchings={}, tree=new_tree)
node_id = new_tree.add_node(new_node)
new_node.set_node_id(node_id)
new_node.add_parent(parent_id=0)
开发者ID:paolinux79,项目名称:SimpleScraper,代码行数:7,代码来源:Tree.py
示例19: initializeNodesFromJson
def initializeNodesFromJson(self, nodesJsonStr):
nodesObj= json.loads(nodesJsonStr)
if nodesObj is None:
Utils.Print("ERROR: Invalid Json string.")
return False
if "keys" in nodesObj:
keysMap=nodesObj["keys"]
if "defproduceraPrivateKey" in keysMap:
defproduceraPrivateKey=keysMap["defproduceraPrivateKey"]
self.defproduceraAccount.ownerPrivateKey=defproduceraPrivateKey
if "defproducerbPrivateKey" in keysMap:
defproducerbPrivateKey=keysMap["defproducerbPrivateKey"]
self.defproducerbAccount.ownerPrivateKey=defproducerbPrivateKey
nArr=nodesObj["nodes"]
nodes=[]
for n in nArr:
port=n["port"]
host=n["host"]
node=Node(host, port)
node.setWalletEndpointArgs(self.walletEndpointArgs)
if Utils.Debug: Utils.Print("Node:", node)
node.checkPulse()
nodes.append(node)
self.nodes=nodes
return True
开发者ID:milk57618,项目名称:eos,代码行数:31,代码来源:Cluster.py
示例20: addAtIndex
def addAtIndex(self, index, data):
# Continue if index is valid
if index >= 0 and index <= self.__numberNodes:
if index == 0: # Push element to front of list if index is 0
self.push(data)
elif index == self.__numberNodes: # Add element to end of list if index is last element
self.add(data)
else:
# Continue if list is not empty
if self.__head is not None and self.__tail is not None:
addNode = Node(data)
currentNode = self.__head.getNext()
previousNode = self.__head
count = 1
while currentNode is not None: # Traverse list to find element at index
# Insert element when index is found
if count == index:
previousNode.setNext(addNode)
addNode.setNext(currentNode)
self.__numberNodes = self.__numberNodes + 1
break
# Prepare for next iteration
previousNode = currentNode
currentNode = currentNode.getNext()
count = count + 1
开发者ID:bpred754,项目名称:AlgorithmsAndDataStructures,代码行数:26,代码来源:LinkedList.py
注:本文中的Node.Node类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论