Reading a pajek file with partitions

186 views Asked by At

I would need to read data from a pajek file consisting of partitions (files .clu). Looking for more information on how reading a pajek format, I've found the following question: Reading a Pajek Dataset into Networkx

The answer refers to partitions of the vertex set. I've tried to open a file as follows example = nx.read_pajek('path/file.paj') or, alternatively,

with open('path/file.paj') as txtfile:
    comments = []
    data = []
    part = []
    for line in txtfile:
        if line.startswith('*'):
            comment = line
            comments.append(comment)
            if part:
                data.append(part)
                part = []
        else:
            if comment.startswith('*Vertices') and len(line.split()) > 1:
                sublist = line.split('"')
                sublist = sublist[:2] + sublist[-1].split()
                part.append(sublist)
            elif not line.isspace():
                part.append(line.split())
    data.append(part)

but the file cannot be read correctly as it returns [[]].

I guess that the above method cannot be applied in case of partitions.

Can I ask you how to access a .paj having partitions in it? Happy to provide an example of dataset (you might found some example on the link provided above).

Examples of files with partitions might be that one mentioned on the question at the above link (e.g. http://vlado.fmf.uni-lj.si/pub/networks/data/esna/SanJuanSur.htm) or other files in the repository http://vlado.fmf.uni-lj.si/pub/networks/data (e.g. http://vlado.fmf.uni-lj.si/pub/networks/data/2mode/Sandi/Sandi.htm or http://vlado.fmf.uni-lj.si/pub/networks/data/2mode/DutchElite.htm)

1

There are 1 answers

5
MelchiorIm3Tal On

Executing your code, I could read the downloaded SanJuanSur2.paj very well.

What make you think that you have a partition problem?