• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python networkx.write_multiline_adjlist函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: save_results

    def save_results(self, image_name, *results):
        """
        Create a directory of the following format: current pipeline + fname.
        Save and put the results of algorithm processing in the directory.

        Args:
            | *image_name* (str): image name
            | *results* (list): a list of arguments to save

        """
        # saving the processed image
        try:
            cv2.imwrite(os.path.join(self.out_dir, image_name), results[0])
        except (IOError, cv2.error):
            print('ERROR! Could not write an image file, make sure there is ' +
                  'enough free space on disk')
            sys.exit(1)
        if not self.isui:
            print('Success!', image_name, 'saved in', self.out_dir)
        # exporting graph object
        if results[1]:
            image_name = os.path.splitext(image_name)[0] + '.txt'
            nx.write_multiline_adjlist(results[1], os.path.join(self.out_dir,
                                                                image_name),
                                       delimiter='|')
            print('Success!', image_name, 'saved in', self.out_dir)
开发者ID:andreasfirczynski,项目名称:NetworkExtractionFromImages,代码行数:26,代码来源:pipeline.py


示例2: shortest_path

def shortest_path(src, dst, names, cost):
    G = nx.DiGraph()
    G.add_nodes_from(names)

    indices = {}
    for i in range(len(names)):
        indices[names[i]] = i

    # Add edges from src to stations before it
    for i in range(indices[src]):
        G.add_edge(src, names[i],
                   weight=cost(src, names[i]))
    # Add edges from stations after dst to dst
    for i in range(indices[dst] + 1, len(names)):
        G.add_edge(names[i], dst, weight=cost(names[i], dst))
    # Add reverse edges from every station after src back
    for i in range(indices[src] + 1, len(names)):
        for j in range(indices[src] + 1, i):
            G.add_edge(names[i], names[j], weight=cost(names[i], names[j]))
    # Add edges from every station before dst to
    # every station after src
    for i in range(len(names)):
        for j in range(i + 1, len(names)):
            if i >= indices[dst] or j <= indices[src]:
                continue
            G.add_edge(names[i], names[j],
                       weight=cost(names[i], names[j]))
    nx.write_multiline_adjlist(G, "test.adjlist")
    return nx.shortest_path(G, src, dst, weight='weight')
开发者ID:hargup,项目名称:chai,代码行数:29,代码来源:chai.py


示例3: test_multiline_adjlist_delimiter

 def test_multiline_adjlist_delimiter(self):
     fh = io.BytesIO()
     G = nx.path_graph(3)
     nx.write_multiline_adjlist(G, fh, delimiter=':')
     fh.seek(0)
     H = nx.read_multiline_adjlist(fh, nodetype=int, delimiter=':')
     assert_nodes_equal(list(H), list(G))
     assert_edges_equal(list(H.edges()), list(G.edges()))
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:8,代码来源:test_adjlist.py


示例4: test_multiline_adjlist_integers

 def test_multiline_adjlist_integers(self):
     (fd, fname) = tempfile.mkstemp()
     G = nx.convert_node_labels_to_integers(self.G)
     nx.write_multiline_adjlist(G, fname)
     H = nx.read_multiline_adjlist(fname, nodetype=int)
     H2 = nx.read_multiline_adjlist(fname, nodetype=int)
     assert_nodes_equal(list(H), list(G))
     assert_edges_equal(list(H.edges()), list(G.edges()))
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:10,代码来源:test_adjlist.py


示例5: test_multiline_adjlist_digraph

 def test_multiline_adjlist_digraph(self):
     G = self.DG
     (fd, fname) = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname)
     H = nx.read_multiline_adjlist(fname, create_using=nx.DiGraph())
     H2 = nx.read_multiline_adjlist(fname, create_using=nx.DiGraph())
     assert_not_equal(H, H2)  # they should be different graphs
     assert_nodes_equal(list(H), list(G))
     assert_edges_equal(list(H.edges()), list(G.edges()))
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:11,代码来源:test_adjlist.py


示例6: test_multiline_adjlist_graph

 def test_multiline_adjlist_graph(self):
     G=self.G
     (fd,fname)=tempfile.mkstemp()
     nx.write_multiline_adjlist(G,fname)  
     H=nx.read_multiline_adjlist(fname)
     H2=nx.read_multiline_adjlist(fname)
     assert_not_equal(H,H2) # they should be different graphs
     assert_equal(sorted(H.nodes()),sorted(G.nodes()))
     assert_equal(sorted(H.edges()),sorted(G.edges()))
     os.close(fd)
     os.unlink(fname)
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:11,代码来源:test_adjlist.py


示例7: test_unicode

 def test_unicode(self):
     G = nx.Graph()
     try:  # Python 3.x
         name1 = chr(2344) + chr(123) + chr(6543)
         name2 = chr(5543) + chr(1543) + chr(324)
     except ValueError:  # Python 2.6+
         name1 = unichr(2344) + unichr(123) + unichr(6543)
         name2 = unichr(5543) + unichr(1543) + unichr(324)
     G.add_edge(name1, 'Radiohead', **{name2: 3})
     fd, fname = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname)
     H = nx.read_multiline_adjlist(fname)
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:15,代码来源:test_adjlist.py


示例8: test_latin1

 def test_latin1(self):
     G = nx.Graph()
     try:  # Python 3.x
         blurb = chr(1245)  # just to trigger the exception
         name1 = 'Bj' + chr(246) + 'rk'
         name2 = chr(220) + 'ber'
     except ValueError:  # Python 2.6+
         name1 = 'Bj' + unichr(246) + 'rk'
         name2 = unichr(220) + 'ber'
     G.add_edge(name1, 'Radiohead', **{name2: 3})
     fd, fname = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname, encoding='latin-1')
     H = nx.read_multiline_adjlist(fname, encoding='latin-1')
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:yamaguchiyuto,项目名称:networkx,代码行数:16,代码来源:test_adjlist.py


示例9: test_latin1

 def test_latin1(self):
     G = nx.Graph()
     try:  # Python 3.x
         blurb = chr(1245)  # just to trigger the exception
         name1 = "Bj" + chr(246) + "rk"
         name2 = chr(220) + "ber"
     except ValueError:  # Python 2.6+
         name1 = "Bj" + unichr(246) + "rk"
         name2 = unichr(220) + "ber"
     G.add_edge(name1, "Radiohead", {name2: 3})
     fd, fname = tempfile.mkstemp()
     nx.write_multiline_adjlist(G, fname, encoding="latin-1")
     H = nx.read_multiline_adjlist(fname, encoding="latin-1")
     assert_graphs_equal(G, H)
     os.close(fd)
     os.unlink(fname)
开发者ID:nishnik,项目名称:networkx,代码行数:16,代码来源:test_adjlist.py


示例10: main

def main(rdfLocation, outputType):
    """Main function which parses the rdf graph then sends it to be queried.
    It uses the result from the queryAll function to call the required file parser.
    If multiple files are detected it will parse them all.
    Returns: Final Network output to file in a variety of common network file formats. 
    """
    files = []
    # Parse The RDF Graph Object by first checking if it is a file location or the file itself.
    if os.path.isfile(rdfLocation):
        g.parse(location=rdfLocation)
    else:
        g.parse(data=rdfLocation)
    
    # Specify Output File Type For graph Object
    outputFileType = outputType
    
    # Create NetworkX Graph object
    G = nx.MultiDiGraph()
    
    # Extract the file types from the rdf as this will be used to call a custom query for a certain filetype
    fileInfo = g.query("""SELECT ?name ?filetype WHERE { ?s network:fileType ?filetype .
                                                          ?s network:fileName ?name . }""")
                                                          
    # Loop through files contained within the dataset and issue relavent queries
    for element in fileInfo:
        # Extract the FileType and Name from the query result
        fileName = str(element[0])
        fileType = str(element[1])
        
        # Call XML functions
        if fileType == "xml":
            print "Found XML File"
            xmlData = queryAll(fileName,fileType)
            for f in xmlData:
                G = FP.parseXML(f,G)
            
        elif fileType == "json":
            print "Found JSON file"
            jsonData = queryAll(fileName,fileType)
            for f in jsonData:
                G = FP.parseJSON(f,G)
            
        elif fileType == "csv":
            print "Found CSV file"
            csvData = queryAll(fileName,fileType)
            for f in csvData:
                print f
                G = FP.parseCSV(f,G)

        elif fileType == "excel":
            print "Found Excel File"
            excelData = queryAll(fileName,fileType)
            for f in excelData:
                G = FP.parseEXCEL(f,G)
            
        else:
            print "Currently Not a Supported File"    
            
        print "Finished processing file"
        
    # Write out the graph object to file -------------------------------------------------------------------------------------
    if outputFileType == "gml":
        nx.write_gml(G,'output.gml')
        
    elif outputFileType == "adj":
        nx.write_adjlist(G,"output.adj")

    elif outputFileType == "mladj":
        nx.write_multiline_adjlist(G,"output.adjlist")
    
    elif outputFileType == "graphml":
        nx.write_graphml(G, "output.graphml")   
        
    elif outputFileType == "pajek":
        nx.write_pajek(G, "output.net")

    elif outputFileType == "neo4j":
        # Update to address of the Neo4j server
        results = neonx.write_to_neo("http://localhost:7474/db/data/", G, 'LINKS_TO')
开发者ID:sbonner0,项目名称:SemNetCon,代码行数:79,代码来源:Network_Constructor.py


示例11: write_graph

def write_graph(gr, from_user, to_user):
    with get_file(edgelist_fname(**locals()), 'w') as fd:
        NX.write_multiline_adjlist(gr, fd, delimiter='\t')
开发者ID:kwargs,项目名称:ya-foaf,代码行数:3,代码来源:get_paths.py


示例12: chr

    dt = 'Deatht' + chr(246) + 'ngue'

G = nx.Graph()
G.add_edge(hd, mh)
G.add_edge(mc, st)
G.add_edge(boc, mc)
G.add_edge(boc, dt)
G.add_edge(st, dt)
G.add_edge(q, st)
G.add_edge(dt, mh)
G.add_edge(st, mh)

# write in UTF-8 encoding
fh = open('edgelist.utf-8', 'wb')
fh.write('# -*- coding: utf-8 -*-\n'.encode('utf-8'))  # encoding hint for emacs
nx.write_multiline_adjlist(G, fh, delimiter='\t', encoding='utf-8')

# read and store in UTF-8
fh = open('edgelist.utf-8', 'rb')
H = nx.read_multiline_adjlist(fh, delimiter='\t', encoding='utf-8')

for n in G.nodes():
    if n not in H:
        print(False)

print(list(G.nodes()))

pos = nx.spring_layout(G)
nx.draw(G, pos, font_size=16, with_labels=False)
for p in pos:  # raise text positions
    pos[p][1] += 0.07
开发者ID:aparamon,项目名称:networkx,代码行数:31,代码来源:plot_heavy_metal_umlaut.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python networkx.write_pajek函数代码示例发布时间:2022-05-27
下一篇:
Python networkx.write_graphml函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap