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


Python model.Node类代码示例

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


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

示例1: get

 def get(self, nodeid):
     n_obj = Node.get_by_id(int(nodeid))
     if not n_obj:
         self.error(404)
         self.echo('error.html', {
             'page': '404',
             'title': "Can't find out this URL",
             'h2': 'Oh, my god!',
             'msg': 'Something seems to be lost...'
         })
         return
     
     from_id = int(self.request.get('id', '0'))
     if from_id<=0 and n_obj.count:
         from_id = n_obj.count
     
     to_id = from_id - EACH_PAGE_POST_NUM
     if to_id<0:
         to_id = 0
     
     newest_node = Node.get_newest()
     self.echo('nodedetail.html', {
         'title': n_obj.name,
         'n_obj': n_obj,
         'from_id': from_id,
         'to_id': to_id,
         'topic_objs': Node.get_page_topic(nodeid, from_id, to_id),
         'newest_node': newest_node,
         'recent_node': Node.get_recent_node(),
         'hot_node': Node.get_hot_node(),
         'recent_topic_objs': KeyStrValue.get_topic_key_title('recent-topic-home'),
         'reply_topic_objs': KeyStrValue.get_topic_key_title('recent-reply-topic'),            
     }, layout='_layout.html')
     if len(newest_node)==10:
         KeyStrValue.add_node_key(nodeid)
开发者ID:QiaoHaiZhong,项目名称:rebang,代码行数:35,代码来源:view.py

示例2: test_classify_success

    def test_classify_success(self):
        tree = Node("Gender",
                ("Female", Node("Bush Approval",
                        ("Approve", Label("McCain")),
                        ("Disapprove", Label("Obama")))),
                ("Male", Node("Ideology",
                        ("Liberal", Label("Obama")),
                        ("Moderate", Label("Obama")),
                        ("Conservative", Label("McCain")))))

        c = tree.classify(['Female', 'Approve', None],
                          ['Gender', 'Bush Approval', 'Ideology'])
        self.assertEqual(c, 'McCain')
        # same but dif order of features
        c = tree.classify(['Approve', 'Female', None],
                          ['Bush Approval', 'Gender', 'Ideology'])
        self.assertEqual(c, 'McCain')
        # dif last node
        c = tree.classify(['Disapprove', 'Female', None],
                          ['Bush Approval', 'Gender', 'Ideology'])
        self.assertEqual(c, 'Obama')
        # dif first node
        c = tree.classify([None, 'Male', 'Liberal'],
                          ['Bush Approval', 'Gender', 'Ideology'])
        self.assertEqual(c, 'Obama')
开发者ID:joshterrell805-historic,项目名称:CPE466-KDD,代码行数:25,代码来源:test_model.py

示例3: get

 def get(self):
     n_id = str(self.get_argument('id',''))
     self.echo('addnode.html', {
         'title': "添加分类",
         'n_obj':Node.get_by_id_for_edit(n_id),
         'newest_node': Node.get_newest(),
     }, layout='_layout.html')
开发者ID:QiaoHaiZhong,项目名称:rebang,代码行数:7,代码来源:view.py

示例4: Cruncher

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,代码行数:25,代码来源:cruncher.py

示例5: _parse

    def _parse(self, entries, skip_self):
        nodes = entries['Node']
        if not skip_self:
            nodes += entries['Self']

        for node in nodes:
            n = Node(node.hostname, node.latlon)
            n.add_ip(node.ip)
            self._nodes[node.hostname] = n
            self._ips[node.ip] = n

        mids_unknown = []
        for mid in entries['Mid']:
            try:
                node = self._ips[mid.ip]
                node.add_ip(mid.alias)
                self._ips[mid.alias] = node
            except KeyError:
                mids_unknown.append(mid)

        links = entries['Link'] + entries['PLink']
        links_unknown = []
        for link in links:
            try:
                if skip_self:
                    link_ips = [link.src_ip, link.dst_ip]
                    if any(s.ip in link_ips  for s in entries['Self']):
                        continue

                node = self._ips[link.src_ip]
                l = Link(self._ips[link.dst_ip], link.lq)
                node.add_link(l)
            except KeyError:
                links_unknown.append(link)
开发者ID:cholin,项目名称:olsr-export,代码行数:34,代码来源:parser.py

示例6: MongoLoader

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,代码行数:54,代码来源:cruncher.py

示例7: test_classify_invalid_value_for_column

    def test_classify_invalid_value_for_column(self):
        tree = Node("Gender",
                ("Female", Node("Bush Approval",
                        ("Approve", Label("McCain")),
                        ("Disapprove", Label("Obama")))),
                ("Male", Node("Ideology",
                        ("Liberal", Label("Obama")),
                        ("Moderate", Label("Obama")),
                        ("Conservative", Label("McCain")))))

        result = tree.classify(['Male', -1, -1], ['Gender', 'Ideology', 'c'])
        self.assertIsNone(result)
开发者ID:joshterrell805-historic,项目名称:CPE466-KDD,代码行数:12,代码来源:test_model.py

示例8: start

 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"])
开发者ID:msqui,项目名称:osm_xml_cruncher,代码行数:7,代码来源:cruncher.py

示例9: create_node

 def create_node(self, drip_campaign_id, title, start_time, template_id, subject, from_email, from_name, initial,
                 description=None):
     """
     create a single drip campaign node, save to mongo
     return object id
     """
     new_content = Content(template_id=template_id, subject=subject, from_email=from_email, from_name=from_name)
     new_node = Node(
         drip_campaign_id=drip_campaign_id,
         title=title,
         start_time=start_time,
         description=description,
         content=new_content,
         initial=initial,
         done=False,
     )
     new_node.save()
     return new_node.id
开发者ID:Dripitio,项目名称:drip,代码行数:18,代码来源:data_captain.py

示例10: MongoLoader

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,代码行数:44,代码来源:mongoloader.py

示例11: JSONLoader

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,代码行数:41,代码来源:tojson.py

示例12: post

 def post(self):
     n_id = str(self.get_argument('id',''))
     name = self.get_argument('name','')
     imgurl = self.get_argument('imgurl','')
     about = self.get_argument('about','')
     
     if name:
         n_n_id = Node.set_node(n_id, name, imgurl, about)
         if n_n_id:
             self.redirect('/add-node?id=%s'%n_n_id)
             return
     
     self.redirect('/add-node?id=%s'%n_id)
开发者ID:QiaoHaiZhong,项目名称:rebang,代码行数:13,代码来源:view.py

示例13: addNodes

def addNodes(nodes):
    added = []
    for id in nodes:
        node,revision,tags = getNode(id)
        
        node['version'] = node['vid']
        node['user'] = node['uid']
        node['id'] = node['nid']
        revision['user'] = revision['uid']
        revision['id'] = revision['vid']
        revision['node'] = revision['nid']
        del(node['status'])
        del(node['uid'])
        del(node['nid'])
        del(node['vid'])
        del(revision['uid'])
        del(revision['nid'])
        del(revision['vid'])
        # add the nodes
        try:
            dbnode = Node.get(node['id']) 
            del(node['id'])
            dbnode.set(**node)
        except SQLObjectNotFound:
            dbnode = Node(**node)

        try:
            dbnoder = NodeRevision.get(revision['id'])
            del(revision['id'])
            dbnoder.set(**revision)
        except SQLObjectNotFound:
            dbnoder = NodeRevision(**revision)
        # add the termnodes
        for tag in tags:
            tag['node'] = tag['nid']
            tag['term'] = tag['tid']
            del(tag['nid'])
            del(tag['tid'])
            try:
                dbtag = Term.get(tag['term'])
            except SQLObjectNotFound:
                dbtag = addTags([tag['term']])[0]
            terms = list(TermNode.selectBy(node=dbnode,term=dbtag))
            if not terms:
                term = TermNode(**tag)
            else:
                term = terms[0]

        print "Node %d made!" % id
        added.append(id)
    return added
开发者ID:haxel,项目名称:spaceplace,代码行数:51,代码来源:sync.py


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