-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyword-length-distribution.php
More file actions
28 lines (20 loc) · 863 Bytes
/
keyword-length-distribution.php
File metadata and controls
28 lines (20 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
require 'vendor/autoload.php';
$url = 'https://en.wikipedia.org/wiki/Online_advertising';
// Instantiate the library
$web = new \spekulatius\phpscraper();
// Navigate to the test page.
$web->go($url);
// check the number of keywords.
$keywords = $web->contentKeywordsWithScores;
echo "This page contains around " . count($keywords) . " keywords/phrases.\nBelow are some selected keyword extractions.";
echo "\n\nLength Distribution of Keywords:\n\n";
$length_distribution = [];
foreach ($keywords as $keyword => $score) {
$length_distribution[strlen($keyword)] = isset($length_distribution[strlen($keyword)]) ?
$length_distribution[strlen($keyword)] + 1 : 1;
}
ksort($length_distribution);
print_r($length_distribution);
echo join(',', array_keys($length_distribution))."\n\n";
echo join(',', array_values($length_distribution))."\n\n";