Question

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?

Était-ce utile?

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top