Search code examples
mysqlscrapybreadcrumbscatalog

Recreate catalogue from breadcrumbs


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?


Solution

  • 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.