benedekrozemberczki / graph2vec

A parallel implementation of "graph2vec: Learning Distributed Representations of Graphs" (MLGWorkshop 2017).
https://karateclub.readthedocs.io/
GNU General Public License v3.0
901 stars 169 forks source link

Fix inconsistent and improper path resolution #38

Closed 5teven1in closed 3 years ago

5teven1in commented 3 years ago

What are the problems?

name = path.strip(".json").split("/")[-1]
...
identifier = f.split("/")[-1].strip(".json")

There are two different ways to generate a name from the path, and they are some issues.

  1. mismatch when the path is /jsonparser.json, and the outputs will be jsonparser and parser.
  2. collision when the path is /jjjsonparser.json, and the identifier also outputs parser.
graphs = glob.glob(args.input_path + "*.json")

This will assume that args.input_path always ends in a slash. Therefore, if the directory name is dataset, we must enter dataset/ or it will not work.

How do I solve them?

Use basename, splitext and join in os.path to deal with the path properly.

Also, I removed the type conversion of int(identifier) because we can't be sure it will always be an integer.

benedekrozemberczki commented 3 years ago

Thank you @ss8651twtw!