Skip to content
Snippets Groups Projects
Commit c764f7e8 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Sprachfilter angepasst, sodass alle Ergebnisse mit einem Prozess ausgewertet werden

parent 000fd311
No related branches found
No related tags found
2 merge requests!499Sprachfilter angepasst, sodass alle Ergebnisse mit einem Prozess ausgewertet werden,!475Development
......@@ -157,6 +157,10 @@ class MetaGer
// combine
$combinedResults = $this->combineResults($engines);
# Wir bestimmen die Sprache eines jeden Suchergebnisses
$this->results = $this->addLangCodes($this->results);
// sort
//$sortedResults = $this->sortResults($engines);
// filter
......@@ -260,6 +264,47 @@ class MetaGer
}
private function addLangCodes($results)
{
# Bei der Spracheinstellung "all" wird nicht gefiltert
if ($this->getLang() === "all") {
return $results;
} else {
# Ansonsten müssen wir jedem Result einen Sprachcode hinzufügen
$id = 0;
$langStrings = [];
foreach ($results as $result) {
# Wir geben jedem Ergebnis eine ID um später die Sprachcodes zuordnen zu können
$result->id = $id;
$langStrings["result_" . $id] = utf8_encode($result->getLangString());
$id++;
}
# Wir schreiben die Strings in eine temporäre JSON-Datei,
# Da das Array unter umständen zu groß ist für eine direkte Übergabe an das Skript
$filename = "/tmp/" . getmypid();
file_put_contents($filename, json_encode($langStrings));
$langDetectorPath = app_path() . "/Models/lang.pl";
$lang = exec("echo '$filename' | $langDetectorPath");
$lang = json_decode($lang, true);
# Wir haben nun die Sprachcodes der einzelnen Ergebnisse.
# Diese müssen wir nur noch korrekt zuordnen, dann sind wir fertig.
foreach ($lang as $key => $langCode) {
# Prefix vom Key entfernen:
$id = intval(str_replace("result_", "", $key));
foreach ($this->results as $result) {
if ($result->id === $id) {
$result->langCode = $langCode;
break;
}
}
}
return $results;
}
}
public function combineResults($engines)
{
foreach ($engines as $engine) {
......
......@@ -189,12 +189,8 @@ class Result
}
# Eventueller Sprachfilter
if ($metager->getLang() !== "all") {
$text = $this->titel . " " . $this->descr;
$path = app_path() . "/Models/lang.pl";
$lang = exec("echo '$text' | $path");
if ($metager->getLang() !== $lang) {
if ($metager->getLang() !== "all" && isset($this->langCode)) {
if ($metager->getLang() !== $this->langCode) {
return false;
}
......@@ -310,4 +306,14 @@ class Result
{
return $this->rank;
}
public function getLangString()
{
$string = "";
$string .= $this->titel;
$string .= $this->descr;
return $string;
}
}
#!/usr/bin/perl
use Lingua::Identify qw(:language_identification);
use JSON;
use warnings;
use strict;
binmode STDOUT, ":utf8";
binmode STDIN, ":utf8";
use utf8;
$text = <STDIN>;
chomp(my $filename = <STDIN>);
$a = langof($text);
# Lets open the given file:
open(my $fh, "<", $filename)
or die "Can't open < $filename: $!";
my $json = <$fh>;
close $fh;
print $a;
# Decode the JSON String
my $data = decode_json($json);
# Wir durchlaufen den Hash:
foreach my $key (keys %{$data}){
$data->{$key} = langof($data->{$key});
}
$data = encode_json($data);
# Nur noch die temporäre Datei löschen:
unlink($filename);
print $data;
......@@ -13,7 +13,9 @@
* php7.0-zip
* sqlite3
* redis-server
* Das Perl-Paket: Lingua::Identify (http://search.cpan.org/~ambs/Lingua-Identify-0.56/lib/Lingua/Identify.pm)
* Die Perl-Pakete
* Lingua::Identify (http://search.cpan.org/~ambs/Lingua-Identify-0.56/lib/Lingua/Identify.pm)
* JSON (http://search.cpan.org/~makamaka/JSON-2.90/lib/JSON.pm)
## Offizielle Dokumentation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment