當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。