cdlib.readwrite.write_lifecycle_json¶
- cdlib.readwrite.write_lifecycle_json(lifecycle: LifeCycle, path: str, compress: bool = False)¶
将生命周期结构保存到JSON文件。
- Parameters:
lifecycle – 一个 LifeCycle 对象
path – 输出文件名
compress – 是否压缩JSON,默认为False
- Returns:
表示对象的JSON格式字符串
- Example:
>>> from cdlib import LifeCycle, TemporalClustering >>> from cdlib import algorithms >>> from networkx.generators.community import LFR_benchmark_graph >>> from cdlib.readwrite import write_lifecycle_json, read_lifecycle_json >>> tc = TemporalClustering() >>> for t in range(0, 10): >>> g = LFR_benchmark_graph( >>> n=250, >>> tau1=3, >>> tau2=1.5, >>> mu=0.1, >>> average_degree=5, >>> min_community=20, >>> seed=10, >>> ) >>> coms = algorithms.louvain(g) # here any CDlib algorithm can be applied >>> tc.add_clustering(coms, t) >>> >>> events = LifeCycle(tc) >>> events.compute_events("facets") >>> write_lifecycle_json(events, "lifecycle.json")