当前位置: 首页>>代码示例>>Python>>正文


Python Node.add_tag方法代码示例

本文整理汇总了Python中model.Node.add_tag方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_tag方法的具体用法?Python Node.add_tag怎么用?Python Node.add_tag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Node的用法示例。


在下文中一共展示了Node.add_tag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Cruncher

# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import add_tag [as 别名]
class Cruncher(object):
    """XML Cruncher!!!"""
    
    current_node = None
    nodes = []
    
    def start(self, tag, attrib):
        """parser enters tag"""
        
        if tag == "node":
            self.current_node = Node(attrib["id"], attrib["lat"], attrib["lon"])
        elif tag == "tag" and self.current_node:
            self.current_node.add_tag(attrib["k"], attrib["v"])
    
    def end(self, tag):
        """parses end tags"""
        if tag == "node" and self.current_node:
            if self.current_node.tags.has_key("name"):
                self.nodes.append(self.current_node)
            self.current_node = None
    
    def close(self):
        """parser closes"""
        nodes, self.nodes = self.nodes, []
        return nodes
开发者ID:msqui,项目名称:osm_xml_cruncher,代码行数:27,代码来源:cruncher.py

示例2: MongoLoader

# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import add_tag [as 别名]
class MongoLoader(object):
    """Parses xml nodes and inserts appropriate ones to db"""

    def __init__(self, collection_name, named_only, tag_names):
        """C'tor sets tag wich we'll count"""
        self._named_only = named_only
        
        if isinstance(tag_names, list):
            self._tag_names = set(tag_names)
        else:
            self._tag_names = set([tag_names])
        
        self._current_node = None
        self._count = 0
        
        conn = Connection('localhost', 27017)
        db = conn['openstreet']
        self._ca = db[collection_name]
    
    def start(self, tag, attrib):
        """parser enters tag"""
        
        if tag == "node":
            # Start node writing
            self._current_node = Node(  float(attrib["lat"]),
                                        float(attrib["lon"]),
                                        id = int(attrib["id"])  )
        elif tag == "tag" and self._current_node:
            # Add tag to node
            self._current_node.add_tag(attrib["k"], attrib["v"])
    
    def end(self, tag):
        """parser reached end of tag"""
        if tag == "node" and self._current_node:
            
            # tags_set = set(self._current_node.tags)
            # if not self._named_only or "name" in tags_set:
            #     if len(tags_set & self._tag_names):
            #         self._save_node()
            
            if "name" in self._current_node.tags:
                self._save_node()
                
            self._current_node = None
    
    def close(self):
        """parser closes"""
        count, self._count = self._count, 0
        return count
    
    def _save_node(self):
        """Save current_node to list"""
        self._ca.insert(self._current_node)
        self._count += 1
开发者ID:msqui,项目名称:osm_xml_cruncher,代码行数:56,代码来源:cruncher.py

示例3: MongoLoader

# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import add_tag [as 别名]
class MongoLoader(object):
    """Parses xml nodes and inserts appropriate ones to db"""
    
    def __init__(self, collection_name):
        """C'tor sets tag wich we'll count"""
        
        from pymongo import Connection
        
        conn = Connection('localhost', 27017)
        db = conn['openstreetmaps']
        self._ca = db[collection_name]
        
        self._current_node = None
        self._count = 0
    
    def start(self, tag, attrib):
        """parser enters tag"""
        
        from model import Node
        
        if tag == "node":
            # Start node writing
            self._current_node = Node(  float(attrib["lat"]),
                                        float(attrib["lon"]),
                                        id = int(attrib["id"])  )
        elif tag == "tag" and self._current_node:
            # Add tag to node
            self._current_node.add_tag(attrib["k"], attrib["v"])
    
    def end(self, tag):
        """parser reached end of tag"""
        if tag == "node" and self._current_node:
            self.__save_node()
            self._current_node = None
    
    def close(self):
        """parser closes"""
        count, self._count = self._count, 0
        return count
    
    def __save_node(self):
        """Save current_node to list"""
        self._ca.insert(self._current_node)
        self._count += 1
开发者ID:msqui,项目名称:osm_xml_cruncher,代码行数:46,代码来源:mongoloader.py

示例4: JSONLoader

# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import add_tag [as 别名]
class JSONLoader(object):
    """Parses xml nodes and inserts appropriate ones to db"""
    
    def __init__(self):
        """C'tor sets tag wich we'll count"""
        
        from json import JSONEncoder
        self._encoder = JSONEncoder()
        
        self._current_node = None
        self._count = 0
    
    def start(self, tag, attrib):
        """parser enters tag"""
        
        from model import Node
        
        if tag == "node":
            # Start node writing
            self._current_node = Node(  float(attrib["lat"]),
                                        float(attrib["lon"]),
                                        id = int(attrib["id"])  )
        elif tag == "tag" and self._current_node:
            # Add tag to node
            self._current_node.add_tag(attrib["k"], attrib["v"])
    
    def end(self, tag):
        """parser reached end of tag"""
        if tag == "node" and self._current_node:
            self.__save_node()
            self._current_node = None
    
    def close(self):
        """parser closes"""
        count, self._count = self._count, 0
        return count
    
    def __save_node(self):
        """Save current_node to list"""
        print(self._encoder.encode(self._current_node))
        self._count += 1
开发者ID:msqui,项目名称:osm_xml_cruncher,代码行数:43,代码来源:tojson.py


注:本文中的model.Node.add_tag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。