1

I have a little puzzle.

I use scrapy for parsing supplier website.

I want to do some trick. I want to recreate catalogue from breadcrumbs.

Does anyone know the algorithm to do this?

Dimitry
  • 359
  • 4
  • 13

1 Answers1

0

Here's pseudocode based on some PHP code I wrote to convert breadcrumbs into a Closure Table.

while ($breadcrumbs = fetch()) {
  $chain = explode("/", $breadcrumbs); -- assume "/" is the breadcrumbs separator
  $pathlength = count($chain) - 1;
  $child = $chain[$pathlength];
  foreach ($chain as $ancestor) {
    print $ancestor, $child, $pathlength;
    $pathlength--;
  }
}

The output is the transitive closure of the categories in the catalog.

Community
  • 1
  • 1
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828