문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top