webpage_quality_analyzer 1.0.2

High-performance webpage quality analyzer with 115 comprehensive metrics - Rust library with WASM, C++, and Python bindings
Documentation
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
use webpage_quality_analyzer::analyze;

#[cfg(test)]
mod paragraph_counting_tests {
    use super::*;

    #[tokio::test]
    async fn test_paragraph_counting_fix() {
        println!("๐Ÿงช Testing paragraph counting fix...");

        // Test Case 1: Simple page with clear paragraph structure
        let simple_html = r#"
        <!DOCTYPE html>
        <html>
        <head><title>Simple Test Page</title></head>
        <body>
            <nav>
                <ul>
                    <li>Home</li>
                    <li>About</li>
                    <li>Contact</li>
                    <li>Services</li>
                    <li>Products</li>
                    <li>Blog</li>
                    <li>FAQ</li>
                </ul>
            </nav>
            <main>
                <h1>Welcome to Our Site</h1>
                <p>This is the first paragraph of actual content with substantial text that provides value to readers.</p>
                <p>Here is a second paragraph with more meaningful content that continues the discussion.</p>
                <p>A third paragraph adds additional information and context to the topic at hand.</p>
                
                <h2>About Our Services</h2>
                <p>This paragraph describes our services in detail with comprehensive information.</p>
                <p>Another service paragraph that explains our offerings and capabilities thoroughly.</p>
                
                <h2>Contact Information</h2>
                <p>Final paragraph with contact details and concluding thoughts for our visitors.</p>
            </main>
            <footer>
                <p>Copyright 2025 - All rights reserved</p>
                <div>Footer link 1</div>
                <div>Footer link 2</div>
                <div>Footer link 3</div>
            </footer>
        </body>
        </html>
        "#;

        match analyze("https://test-simple.example.com", Some(simple_html)).await {
            Ok(report) => {
                println!("โœ… Simple page analysis completed!");
                let paragraph_count = report.metrics.html_analysis.structure.paragraph_count;
                let total_chunks = report.processed_document.content_chunks.len();

                println!("๐Ÿ“Š Simple Page Results:");
                println!("   Paragraph Count: {}", paragraph_count);
                println!("   Total Content Chunks: {}", total_chunks);
                println!("   Expected: ~6-7 paragraphs (actual <p> tags with content)");

                // Show what was counted as paragraphs
                let paragraph_chunks: Vec<_> = report
                    .processed_document
                    .content_chunks
                    .iter()
                    .filter(|c| {
                        matches!(
                            c.chunk_type,
                            webpage_quality_analyzer::models::models::ContentChunkType::Paragraph
                        )
                    })
                    .collect();

                println!(
                    "   Actual Paragraph Chunks Found: {}",
                    paragraph_chunks.len()
                );
                for (i, chunk) in paragraph_chunks.iter().enumerate() {
                    println!(
                        "     {}: '{}'",
                        i + 1,
                        chunk.text.chars().take(60).collect::<String>()
                    );
                }

                // Validation
                if paragraph_count >= 5 && paragraph_count <= 8 {
                    println!(
                        "โœ… PASS: Paragraph count is reasonable ({} paragraphs)",
                        paragraph_count
                    );
                } else {
                    println!(
                        "โŒ FAIL: Paragraph count is unreasonable ({} paragraphs, expected 5-8)",
                        paragraph_count
                    );
                }
            }
            Err(e) => {
                println!("โŒ Simple page analysis failed: {}", e);
            }
        }

        println!("\n{}", "=".repeat(60));

        // Test Case 2: Navigation-heavy page (like UTokyo)
        let navigation_heavy_html = r#"
        <!DOCTYPE html>
        <html>
        <head><title>University Navigation Test</title></head>
        <body>
            <header>
                <nav id="main-nav">
                    <ul>
                        <li>Office of the President</li>
                        <li>Administration Bureau Organizations</li>
                        <li>University of Tokyo Library System</li>
                        <li>The University of Tokyo Archives</li>
                        <li>Faculties and Graduate Schools</li>
                        <li>Institutes</li>
                        <li>University Joint Education</li>
                        <li>Research Institutes</li>
                        <li>Advanced Study Programs</li>
                        <li>Interdisciplinary Research</li>
                        <li>National Joint-Use Institutes</li>
                        <li>Collaborative Research Organizations</li>
                        <li>Other University Organizations</li>
                        <li>Committee for Presidential Initiatives</li>
                        <li>Education and Research Affairs</li>
                    </ul>
                </nav>
            </header>
            <main id="contents">
                <h1>University Social Media Accounts</h1>
                <p>This page features a list of the main social media accounts officially managed by the University.</p>
                
                <h2>Official Accounts</h2>
                <p>The university maintains several official social media presence across different platforms to engage with students, faculty, and the broader community.</p>
                <p>These accounts provide updates on university news, research achievements, and important announcements.</p>
                
                <div class="social-links">
                    <div>Facebook Official</div>
                    <div>Twitter/X Official</div>
                    <div>YouTube Channel</div>
                    <div>Instagram Account</div>
                    <div>LinkedIn Profile</div>
                </div>
            </main>
            <aside>
                <ul class="sidebar-menu">
                    <li>Quick Link 1</li>
                    <li>Quick Link 2</li>
                    <li>Quick Link 3</li>
                    <li>Quick Link 4</li>
                    <li>Quick Link 5</li>
                </ul>
            </aside>
            <footer>
                <div>Footer Navigation Item 1</div>
                <div>Footer Navigation Item 2</div>
                <div>Copyright Information</div>
            </footer>
        </body>
        </html>
        "#;

        match analyze(
            "https://test-navigation.example.com",
            Some(navigation_heavy_html),
        )
        .await
        {
            Ok(report) => {
                println!("โœ… Navigation-heavy page analysis completed!");
                let paragraph_count = report.metrics.html_analysis.structure.paragraph_count;
                let total_chunks = report.processed_document.content_chunks.len();

                println!("๐Ÿ“Š Navigation-Heavy Page Results:");
                println!("   Paragraph Count: {}", paragraph_count);
                println!("   Total Content Chunks: {}", total_chunks);
                println!("   Expected: ~3 paragraphs (only actual content paragraphs)");

                // Show what was counted as paragraphs
                let paragraph_chunks: Vec<_> = report
                    .processed_document
                    .content_chunks
                    .iter()
                    .filter(|c| {
                        matches!(
                            c.chunk_type,
                            webpage_quality_analyzer::models::models::ContentChunkType::Paragraph
                        )
                    })
                    .collect();

                println!(
                    "   Actual Paragraph Chunks Found: {}",
                    paragraph_chunks.len()
                );
                for (i, chunk) in paragraph_chunks.iter().enumerate() {
                    println!(
                        "     {}: '{}'",
                        i + 1,
                        chunk.text.chars().take(80).collect::<String>()
                    );
                }

                // Show non-paragraph chunks for comparison
                let non_paragraph_chunks: Vec<_> = report
                    .processed_document
                    .content_chunks
                    .iter()
                    .filter(|c| {
                        !matches!(
                            c.chunk_type,
                            webpage_quality_analyzer::models::models::ContentChunkType::Paragraph
                        )
                    })
                    .collect();

                println!(
                    "   Non-Paragraph Chunks (navigation, etc.): {}",
                    non_paragraph_chunks.len()
                );
                for (i, chunk) in non_paragraph_chunks.iter().take(5).enumerate() {
                    println!(
                        "     {}: {:?} - '{}'",
                        i + 1,
                        chunk.chunk_type,
                        chunk.text.chars().take(50).collect::<String>()
                    );
                }

                // Validation - should NOT count navigation as paragraphs
                if paragraph_count >= 2 && paragraph_count <= 5 {
                    println!(
                        "โœ… PASS: Paragraph count ignores navigation ({} paragraphs)",
                        paragraph_count
                    );
                } else if paragraph_count > 10 {
                    println!("โŒ FAIL: Still counting navigation as paragraphs ({} paragraphs, expected 2-5)", paragraph_count);
                    println!("   This suggests the fix may not be working properly.");
                } else {
                    println!(
                        "โš ๏ธ  MARGINAL: Paragraph count is low but acceptable ({} paragraphs)",
                        paragraph_count
                    );
                }
            }
            Err(e) => {
                println!("โŒ Navigation-heavy page analysis failed: {}", e);
            }
        }

        println!("\n{}", "=".repeat(60));

        // Test Case 3: List-heavy content
        let list_heavy_html = r#"
        <!DOCTYPE html>
        <html>
        <head><title>List Heavy Test</title></head>
        <body>
            <main>
                <h1>Product Features</h1>
                <p>Our product offers numerous features and benefits for users across different industries.</p>
                
                <h2>Main Features</h2>
                <ul>
                    <li>Feature 1: Advanced analytics</li>
                    <li>Feature 2: Real-time processing</li>
                    <li>Feature 3: Cloud integration</li>
                    <li>Feature 4: Mobile compatibility</li>
                    <li>Feature 5: Security protocols</li>
                    <li>Feature 6: API access</li>
                    <li>Feature 7: Custom dashboards</li>
                    <li>Feature 8: Automated reporting</li>
                    <li>Feature 9: Multi-user support</li>
                    <li>Feature 10: 24/7 monitoring</li>
                </ul>
                
                <p>These features combine to provide a comprehensive solution for modern business needs.</p>
                
                <h2>Benefits</h2>
                <ol>
                    <li>Increased productivity</li>
                    <li>Cost reduction</li>
                    <li>Better decision making</li>
                    <li>Improved customer satisfaction</li>
                    <li>Enhanced security</li>
                </ol>
                
                <p>Contact us today to learn more about how these features can benefit your organization.</p>
            </main>
        </body>
        </html>
        "#;

        match analyze("https://test-lists.example.com", Some(list_heavy_html)).await {
            Ok(report) => {
                println!("โœ… List-heavy page analysis completed!");
                let paragraph_count = report.metrics.html_analysis.structure.paragraph_count;

                println!("๐Ÿ“Š List-Heavy Page Results:");
                println!("   Paragraph Count: {}", paragraph_count);
                println!("   Expected: ~3 paragraphs (should NOT count list items)");

                // Show what was counted as paragraphs
                let paragraph_chunks: Vec<_> = report
                    .processed_document
                    .content_chunks
                    .iter()
                    .filter(|c| {
                        matches!(
                            c.chunk_type,
                            webpage_quality_analyzer::models::models::ContentChunkType::Paragraph
                        )
                    })
                    .collect();

                println!(
                    "   Actual Paragraph Chunks Found: {}",
                    paragraph_chunks.len()
                );
                for (i, chunk) in paragraph_chunks.iter().enumerate() {
                    println!(
                        "     {}: '{}'",
                        i + 1,
                        chunk.text.chars().take(80).collect::<String>()
                    );
                }

                // Validation - should NOT count list items as paragraphs
                if paragraph_count >= 2 && paragraph_count <= 4 {
                    println!(
                        "โœ… PASS: List items not counted as paragraphs ({} paragraphs)",
                        paragraph_count
                    );
                } else if paragraph_count > 8 {
                    println!("โŒ FAIL: Still counting list items as paragraphs ({} paragraphs, expected 2-4)", paragraph_count);
                } else {
                    println!(
                        "โš ๏ธ  MARGINAL: Paragraph count acceptable ({} paragraphs)",
                        paragraph_count
                    );
                }
            }
            Err(e) => {
                println!("โŒ List-heavy page analysis failed: {}", e);
            }
        }

        println!("\n๐ŸŽฏ Paragraph Counting Fix Test Summary:");
        println!("   - Simple content: Should count actual <p> tags");
        println!("   - Navigation menus: Should NOT inflate count");
        println!("   - List items: Should NOT be counted as paragraphs");
        println!("   - The fix uses ContentChunk classification instead of text line counting");
    }

    #[tokio::test]
    async fn test_utokyo_paragraph_count() {
        println!("๐Ÿงช Testing UTokyo page paragraph counting specifically...");

        // This test specifically validates the UTokyo page that was problematic
        match analyze("https://www.u-tokyo.ac.jp/sns_en.html", None).await {
            Ok(report) => {
                let paragraph_count = report.metrics.html_analysis.structure.paragraph_count;

                println!("๐Ÿ“Š UTokyo Page Results:");
                println!("   Paragraph Count: {}", paragraph_count);
                println!(
                    "   Word Count: {}",
                    report.metrics.html_analysis.content.word_count
                );
                println!(
                    "   Content Chunks: {}",
                    report.processed_document.content_chunks.len()
                );

                // Show paragraph chunks found
                let paragraph_chunks: Vec<_> = report
                    .processed_document
                    .content_chunks
                    .iter()
                    .filter(|c| {
                        matches!(
                            c.chunk_type,
                            webpage_quality_analyzer::models::models::ContentChunkType::Paragraph
                        )
                    })
                    .collect();

                println!("   Paragraph Chunks Found: {}", paragraph_chunks.len());
                for (i, chunk) in paragraph_chunks.iter().take(3).enumerate() {
                    println!(
                        "     {}: '{}'",
                        i + 1,
                        chunk.text.chars().take(100).collect::<String>()
                    );
                }

                // Validation for UTokyo specifically
                if paragraph_count <= 25 {
                    println!(
                        "โœ… MAJOR IMPROVEMENT: Down from 131 to {} paragraphs!",
                        paragraph_count
                    );
                } else if paragraph_count <= 50 {
                    println!(
                        "โœ… GOOD IMPROVEMENT: Down from 131 to {} paragraphs",
                        paragraph_count
                    );
                } else if paragraph_count <= 80 {
                    println!(
                        "โš ๏ธ  SOME IMPROVEMENT: Down from 131 to {} paragraphs (still high)",
                        paragraph_count
                    );
                } else {
                    println!(
                        "โŒ MINIMAL IMPROVEMENT: Still {} paragraphs (was 131)",
                        paragraph_count
                    );
                }
            }
            Err(e) => {
                println!(
                    "โš ๏ธ  UTokyo analysis failed (network timeout possible): {}",
                    e
                );
                println!("   This is acceptable for automated testing");
            }
        }
    }
}