File: community

package info (click to toggle)
python-louvain 0.0%2B20181013git3fc1f575-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 176 kB
  • sloc: python: 533; makefile: 86
file content (26 lines) | stat: -rwxr-xr-x 876 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin//python3

from __future__ import print_function
import sys
from community import best_partition, load_binary, modularity


def main():
    """Main function to mimic C++ version behavior"""
    try:
        filename = sys.argv[1]
        graph_file = load_binary(filename)
        partition = best_partition(graph_file)
        print(str(modularity(partition, graph_file)), file=sys.stderr)
        for elem, part in partition.items():
            print(str(elem) + " " + str(part))
    except (IndexError, IOError):
        print("Usage : ./community filename")
        print("find the communities in graph filename "
              "and display the dendrogram")
        print("Parameters:")
        print("filename is a binary file as generated by the ")
        print("convert utility distributed with the C implementation")

if __name__ == '__main__':
    main()