72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Article;
|
|
|
|
use App\Models\Article;
|
|
|
|
class ValidationService
|
|
{
|
|
public static function validate(Article $article): Article
|
|
{
|
|
logger('Checking keywords for article: ' . $article->id);
|
|
|
|
$articleData = ArticleFetcher::fetchArticleData($article);
|
|
|
|
// Update article with fetched metadata (title, description)
|
|
$updateData = [
|
|
'validated_at' => now(),
|
|
];
|
|
|
|
if (!empty($articleData)) {
|
|
$updateData['title'] = $articleData['title'] ?? null;
|
|
$updateData['description'] = $articleData['description'] ?? null;
|
|
}
|
|
|
|
if (!isset($articleData['full_article']) || empty($articleData['full_article'])) {
|
|
logger()->warning('Article data missing full_article content', [
|
|
'article_id' => $article->id,
|
|
'url' => $article->url
|
|
]);
|
|
|
|
$updateData['is_valid'] = false;
|
|
$article->update($updateData);
|
|
|
|
return $article->refresh();
|
|
}
|
|
|
|
// Validate using extracted content (not stored)
|
|
$validationResult = self::validateByKeywords($articleData['full_article']);
|
|
$updateData['is_valid'] = $validationResult;
|
|
|
|
$article->update($updateData);
|
|
|
|
return $article->refresh();
|
|
}
|
|
|
|
private static function validateByKeywords(string $full_article): bool
|
|
{
|
|
// Belgian news content keywords - broader set for Belgian news relevance
|
|
$keywords = [
|
|
// Political parties and leaders
|
|
'N-VA', 'Bart De Wever', 'Frank Vandenbroucke', 'Alexander De Croo',
|
|
'Vooruit', 'Open Vld', 'CD&V', 'Vlaams Belang', 'PTB', 'PVDA',
|
|
|
|
// Belgian locations and institutions
|
|
'Belgium', 'Belgian', 'Flanders', 'Flemish', 'Wallonia', 'Brussels',
|
|
'Antwerp', 'Ghent', 'Bruges', 'Leuven', 'Mechelen', 'Namur', 'Liège', 'Charleroi',
|
|
'parliament', 'government', 'minister', 'policy', 'law', 'legislation',
|
|
|
|
// Common Belgian news topics
|
|
'economy', 'economic', 'education', 'healthcare', 'transport', 'climate', 'energy',
|
|
'European', 'EU', 'migration', 'security', 'justice', 'culture', 'police'
|
|
];
|
|
|
|
foreach ($keywords as $keyword) {
|
|
if (stripos($full_article, $keyword) !== false) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|