URLのリストで繰り返し発生するディレクトリパターンを検出するアルゴリズムを理解するのに問題があります。誰かがこの方法を提案できますか?再帰呼び出しである必要があると確信していますが、考えられる各パターンのレコードを保持する方法を決定することはできません。
注:これはPHPです。
レスはあなたがいくつかのURLを持っていると言います:
1. http://www.goodfood.com/recipes/special_occasion/desserts/pie/chocolate-pie.html
2. http://www.goodfood.com/recipes/special_occasion/desserts/pie/cherry-pie.html
3. http://www.goodfood.com/recipes/special_occasion/apps/chex-mix.html
4. http://www.goodfood.com/recipes/special_occasion/soup/tomato.html
5. http://www.goodfood.com/special/special_occasion/soup/beef-stew.html
6. http://www.goodfood.com/special/special_occasion/soup/vegetable.html
複数のURLが持つ可能性のあるすべてのディレクトリパターンを特定する方法を見つけたいと思います。したがって、結果は次のようになります。
'recipes/special_occasion' is found in urls 1, 2, 3 and 4.
'recipes/special_occasion/desserts' is found in urls 1, and 2.
'recipes/special_occasion/desserts/pie' is found in urls 1, and 2.
'special_occasion/desserts/pie' is found in urls 1, and 2.
'desserts/pie' is found in urls 1, and 2.
'special_occasion/desserts' is found in urls 1, and 2.
'special_occasion/desserts/pie' is found in urls 1, and 2.
'special/special_occasion' is found in urls 5, and 6.
'special/special_occasion/soup' is found in urls 5, and 6.
'special_occasion/soup' is found in urls 5, and 6.
私の考えは、各URLを調べて、考えられるすべての新しいパターンを引き出し、配列に格納することです。これまでのところ、次のようになっています。$ commonDomains = array();
foreach($query AS $row) {
$urlPath = parse_url($row['href'], PHP_URL_PATH);
echo "$urlPath<br/>";
$urlChunks = explode('/', $urlPath);
//var_dump($urlChunks);
foreach($urlChunks AS $domain) {
if(strlen($domain) > 0) {
$thisDomain = $domain.'/';
$commonDomains[$thisDomain][] = $row['id'];
}
}
var_dump($commonDomains);
}
誰かがこれに遭遇したことがありますか?それは私にパターンを叫びますが、私はまだオンラインで答えを見つけることができません。私が考えるすべては非常に速く非常に複雑になります。助けてください、ありがとう。
私が取り組んでいることの例があります:http://phpfiddle.org/main/code/kn4-zyh
これまでの私の結果はここにあります
/recipes/special_occasion/desserts/pie/grandmas-chocolate-pie.html
array(5) { [0]=> string(7) "recipes" [1]=> string(16) "special_occasion" [2]=> string(8) "desserts" [3]=> string(3) "pie" [4]=> string(27) "grandmas-chocolate-pie.html" }
0 : 4 : recipes/special_occasion/desserts/pie/grandmas-chocolate-pie.html
0 : 3 : recipes/special_occasion/desserts/pie
0 : 2 : recipes/special_occasion/desserts
0 : 1 : recipes/special_occasion
1 : 4 : special_occasion/desserts/pie/grandmas-chocolate-pie.html
2 : 4 : desserts/pie/grandmas-chocolate-pie.html
3 : 4 : pie/grandmas-chocolate-pie.html
0 : 4 : recipes/special_occasion/desserts/pie/grandmas-chocolate-pie.html
1 : 3 : special_occasion/desserts/pie
**Im missing:
2 : 3 : special_occasion/desserts
1 : 2 : recipes/special_occasion
**