Exemple #1
0
 public static function crawl($source)
 {
     $crawler = new DomCrawler($source);
     Log::log("Generating tree..");
     $node_tree = Parser::parse($crawler, 0, "", false);
     Log::log("Calculating components..");
     $augmented_tree = Parser::augment($node_tree[0]);
     Log::log("Calculating path..");
     $marked_tree = Parser::identify_parent_path($augmented_tree);
     file_put_contents("a-tree", print_r($marked_tree, true));
     Log::log("Scanning the tree for a pattern..");
     Scanner::scan($marked_tree);
     // Test di funzionamento delle funzioni get_node_from_path e get_parent_from_path
     //Log::log( Tree::get_node_from_path( $marked_tree, "0,0" )[ 'tag' ] );
     //Log::log( Tree::get_parent_from_path( $marked_tree, "0,0" )[ 'tag' ] );
 }
Exemple #2
0
 public static function identify_parent_path($node, $path = "")
 {
     $node['path'] = $path;
     if (@(!$node['tag'])) {
         return $node;
     } else {
         if (@(!!$node['children'])) {
             $new_children = [];
             $count = 0;
             foreach ($node['children'] as $child) {
                 $new_path = $path . ($path == "" ? "" : ",") . $count;
                 $new_children[] = Parser::identify_parent_path($child, $new_path);
                 $count++;
             }
             unset($node['children']);
             $node['children'] = $new_children;
             return $node;
         } else {
             return $node;
         }
     }
 }