<?php
// use function Google\Cloud\Samples\PubSub\publish_message;
include "tools/simple_html_dom.php";
include "DatabaseHandler.php";
include 'MiniCurl.php';
class PluralDatabase extends DatabaseHandler{
public $url;
function __construct(){
parent::__construct("conjuct");
}
public function getPlural($noun){
$this->url = "https://dict.leo.org/dictQuery/m-vocab/ende/query.xml?lang=de&search=$noun&side=both&order=advanced§LenMax=16";
$pattern ='/<t n="forms_pl_form">Pl\.:<\/t><\/m><\/i> die[\s\S](.*?)<\/small>/';
$subject = file_get_contents($this->url);
preg_match($pattern, $subject, $matches);
return trim($matches[1]);
}
public function fillPluralNouns(){
$i=0;
$nouns = $this->getNounsFromDatabse();
foreach ($nouns as $noun){
if(!empty($noun)){
$i++;
$pluralForm = $this->getPlural($noun['word']);
$this->fillPluralInDb($noun['word'], $pluralForm);
echo $i."-".$noun['word'].":".$pluralForm.PHP_EOL;
}
}
}
public function getNounsFromDatabse(){
$sql = 'SELECT word FROM `dictionary` WHERE translationrate = 0 AND artikel != "-" GROUP BY word limit 40';
$this->connection->query ( "SET NAMES utf8" );
$result = $this->connection->query ( $sql ) or die ( $this->connection->error );
while ($wordArrayResult[] = mysqli_fetch_assoc($result));
return $wordArrayResult;
}
public function fillPluralInDb($noun, $pluralForm){
$sql = "UPDATE `".DatabaseHandler::$databaseName."`.`dictionary` SET translationrate = 1, plural = '$pluralForm' where word like '$noun'";
$this->connection->query ( "SET NAMES utf8" );
$result = $this->connection->query ( $sql ) or die( $this->connection->error );
return 1;
}
}
//$pluralWorker = new PluralWorker("buch");
//$pluralWorker->getPlural();
$pluralDb = new PluralDatabase();
$pluralDb->fillPluralNouns();
?>