找回密码
 注册
查看: 643|回复: 0

R语言 XML包 xmlFlatListTree()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-10-2 00:00:57 | 显示全部楼层 |阅读模式
xmlFlatListTree(XML)
xmlFlatListTree()所属R语言包:XML

                                        Constructors for trees stored as flat list of nodes with
                                         为树的构造函数存储为平面的节点列表

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

These (and related internal) functions allow us to represent trees as a simple, non-hierarchical collection of nodes along with corresponding tables that identify the parent and child relationships. This is different from representing a tree as a list of lists of lists ...  in which each node has a list of its own children. In a functional language like R, it is not possible then for the children to be able to identify their parents.
这些(以及相关的内部)功能允许我们代表树的节点,伴随着相应的表格,查明父母与子女的关系作为一个简单的,非分层集合。这是不同的,从树的列表,列表的列表...其中每个节点有自己的孩子。在函数式语言如R,它是不可能再为孩子们能够确定他们的父母。

We use an environment to represent these flat trees.  Since these are mutable without requiring the change to be reassigned, we can modify a part of the tree locally without having to reassign the top-level object.
我们使用的环境来表示这些平板的树木。由于这些都是可变的,而不需要重新分配的变化,我们可以在本地修改树的一部分,而无需重新分配的顶层对象。

We can use either a list (with names) to store the nodes or a hash table/associative array that uses names. There is a non-trivial performance difference.
我们可以使用一个列表(名字)存储的节点或一个哈希表/关联数组使用名称。有一个不平凡的性能差异。


用法----------Usage----------


xmlHashTree(nodes = list(), parents = character(), children = list(),
             env = new.env(TRUE, parent = emptyenv()))
xmlFlatListTree(nodes = list(), parents = character(), children = list(), env = new.env(), n = 200)



参数----------Arguments----------

参数:nodes
a collection of existing nodes that are to be added to the tree. These are used to initialize the tree. If this is specified, you must also specify children and parents.  
是要添加到树中的现有节点的集合。这些被用来初始化树。如果这是指定的,还必须指定children和parents。


参数:parents
the parent relationships for the nodes given by nodes.
父母关系的节点的nodes。


参数:children
the children relationships for the nodes given by nodes.
亲子关系的节点的nodes。


参数:env
an environment in which the information for the tree  will be stored. This is essentially the tree object as it allows us to modify parts of the tree without having to reassign the top-level object.    Unlike most R data types, environments are mutable.  
树中的信息将被存储在其中的环境。本质上来说,这是树的对象,因为它允许我们修改的树,而无需重新分配的顶层对象。与大多数R的数据类型,环境是可变的。


参数:n
for xmlFlatListTree, this is used as the default size to allocate for the list containing the nodes
xmlFlatListTree,这是默认的大小作为分配的列表,其中包含的节点


值----------Value----------

An object of class XMLFlatTree which is specialized to XMLFlatListTree by the xmlFlatListTree function and XMLHashTree by the xmlHashTree function. Both objects are simply the environment which contains information about the tree elements and functions to access this information.
是一家专业类XMLFlatTree对象XMLFlatListTree的xmlFlatListTree函数和XMLHashTreexmlHashTree功能。这两个对象是简单的环境,包括信息树中的元素和功能来访问这些信息。

An xmlHashTree object has an accessor method via $ for accessing individual  nodes within the tree. One can use the node name/identifier in an expression such as tt$myNode to obtain the element. The name of a node is either its XML node name or if that is already present in the tree, a machine generated name.
对象访问在树中的单个节点的访问器方法通过xmlHashTree$。可以使用节点名称/标识符在tt$myNode的表达,如获取元素。一个节点的名称是它的XML节点名称,如果是已经存在的树中,一台机器生成的名称。

One can find the names of all the nodes using the objects function since these trees are regular environments in R. Using the all = TRUE argument, one can also find the “hidden” elements that make define the tree's structure. These are .children and .parents. The former is an (hashed) environment. Each element is identified by the node in the tree by the node's identifier (corresponding to the name of the node in the tree's environment). The value of that element is simply a character vector giving the identifiers of all of the children of that node.
人们可以找到的所有节点使用objects的功能,因为这些树是定期的环境中R. all = TRUE使用参数的名称,还可以找到“隐藏”的定义树的元素,使结构。这是.children和.parents。前者是一种(散列)环境。每个元件所确定的树中的节点的节点的标识符(对应于在树的环境中的节点名称)。该元素的值是一个简单的字符向量,给所有的子节点的标识符。

The .parents element is also an environemnt. Each element in this gives the pair of node and parent identifiers with the parent identifier being the value of the variable in the environment. In other words, we look up the parent of a node named 'kid' by retrieving the value of the variable 'kid' in the .parents environment of this hash tree.
.parents元素也是一个environemnt。与父标识符,即在环境中的变量的值,在此给出的每一个元素的对节点和父标识符。换句话说,我们期待的父节点名为孩子的的变量孩子,在.parents环境的散列树检索值。

The function .addNode is used to insert a new node into the tree.
函数.addNode到树中插入一个新的节点。

The structure of this tree allows one to easily travers all nodes, navigate up the tree from a node via its parent.  Certain tasks are more complex as the hierarchy is not implicit within a node.
这种树的结构可以让人们轻易地Travers的所有节点,向上通过其父节点的树。的某些任务是更复杂的层次结构内的节点不隐式。


(作者)----------Author(s)----------


Duncan Temple Lang



参考文献----------References----------

<h3>See Also</h3>   <code>xmlTreeParse</code> <code>xmlTree</code> <code>xmlOutputBuffer</code> <code>xmlOutputDOM</code>   

实例----------Examples----------


f = system.file("exampleData", "dataframe.xml", package = "XML")
tr  = xmlHashTree()
xmlTreeParse(f, handlers = list(.startElement = tr[[".addNode"]]))

tr # print the tree on the screen[打印在屏幕上的树]

  # Get the two child nodes of the dataframe node.[获取的数据框节点的两个子节点。]
xmlChildren(tr$dataframe)

  # Find the names of all the nodes.[查找的所有节点的名称。]
objects(tr)
  # Which nodes have children[哪些节点有孩子]
objects(tr$.children)

  # Which nodes are leaves, i.e. do not have children[哪些节点是叶子,即没有孩子]
setdiff(objects(tr), objects(tr$.children))

  # find the class of each of these leaf nodes.[找到这些叶节点中的每一个类。]
sapply(setdiff(objects(tr), objects(tr$.children)),
         function(id) class(tr[[id]]))

  # distribution of number of children[儿童数量分布]
sapply(tr$.children, length)


  # Get the first A node[获取第一个节点]
tr$A

  # Get is parent node.[得到的是父节点。]
xmlParent(tr$A)


f = system.file("exampleData", "allNodeTypes.xml", package = "XML")

   # Convert the document[将文档转换]
r = xmlInternalTreeParse(f, xinclude = TRUE)
ht = as(r, "XMLHashTree")
ht

  # work on the root node, or any node actually[根节点上的工作,或实际上任何节点]
as(xmlRoot(r), "XMLHashTree")

  # Example of making copies of an XMLHashTreeNode object to create a separate tree.[副本的XMLHashTreeNode对象创建一个单独的树的例子。]
f = system.file("exampleData", "simple.xml", package = "XML")
tt = as(xmlParse(f), "XMLHashTree")

xmlRoot(tt)[[1]]
xmlRoot(tt)[[1, copy = TRUE]]

table(unlist(eapply(tt, xmlName)))
# if any of the nodes had any attributes[如果有任何属性中的任何节点]
# table(unlist(eapply(tt, xmlAttrs)))[表(不公开(eapply(TT,xmlAttrs)))]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-24 17:17 , Processed in 0.019461 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表