Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MetaGer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer
Commits
c764f7e8
Commit
c764f7e8
authored
8 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
Sprachfilter angepasst, sodass alle Ergebnisse mit einem Prozess ausgewertet werden
parent
000fd311
No related branches found
Branches containing commit
No related tags found
2 merge requests
!499
Sprachfilter angepasst, sodass alle Ergebnisse mit einem Prozess ausgewertet werden
,
!475
Development
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/MetaGer.php
+45
-0
45 additions, 0 deletions
app/MetaGer.php
app/Models/Result.php
+12
-6
12 additions, 6 deletions
app/Models/Result.php
app/Models/lang.pl
+25
-3
25 additions, 3 deletions
app/Models/lang.pl
readme.md
+3
-1
3 additions, 1 deletion
readme.md
with
85 additions
and
10 deletions
app/MetaGer.php
+
45
−
0
View file @
c764f7e8
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
app/Models/Result.php
+
12
−
6
View file @
c764f7e8
...
...
@@ -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
;
}
}
This diff is collapsed.
Click to expand it.
app/Models/lang.pl
+
25
−
3
View file @
c764f7e8
#!/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
;
This diff is collapsed.
Click to expand it.
readme.md
+
3
−
1
View file @
c764f7e8
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment