Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Translations
annotation_www
Commits
6ec043cd
Commit
6ec043cd
authored
Jan 03, 2014
by
Martin Gregor
Browse files
uprava ukladania slov,
parent
1a830e6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/presenters/HomepagePresenter.php
View file @
6ec043cd
...
...
@@ -43,14 +43,7 @@ class HomepagePresenter extends BasePresenter
$this
->
words
=
explode
(
' '
,
$sentence
->
sentence
);
// lematizacia skolskou sluzbou
// $curl = new Curl();
//
// $curl->headers = [
// 'Content-Type' => 'text/plain'
// ];
// $result = $curl->post('http://text.fiit.stuba.sk:8080/lematizer/services/lemmatizer/lemmatize/fast','test');
//
// $words = explode(' ',$result->body);
// $this->lematize($sentence);
// preklad kazdeho slova z vety
foreach
(
$this
->
words
as
$word
)
...
...
@@ -88,7 +81,7 @@ class HomepagePresenter extends BasePresenter
$sentence
=
implode
(
' '
,
$words
);
if
(
!
isset
(
$this
->
sentences
[
$sentence
]))
{
$s_words
[]
=
$this
->
en_words
[
$position
]
->
word
;
$s_words
[
$position
]
=
$this
->
en_words
[
$position
]
->
word
;
$this
->
sentences
[
$sentence
]
=
$s_words
;
}
}
...
...
@@ -105,8 +98,6 @@ class HomepagePresenter extends BasePresenter
if
(
count
(
$this
->
sentences
)
>=
$this
->
limit
)
{
// shuffle($this->sentences);
// $this->sentences = array_slice($this->sentences,0,$this->limit);
$sentences
=
array_rand
(
$this
->
sentences
,
$this
->
limit
);
}
...
...
@@ -119,21 +110,56 @@ class HomepagePresenter extends BasePresenter
{
foreach
(
$sentences
as
$sentence
)
{
$translation_id
=
$this
->
db
->
table
(
'translation'
)
->
where
([
'sentence_id'
=>
$this
->
sentence_id
,
'translation'
=>
$sentence
])
->
select
(
'id'
)
->
fetch
();
$translation_id
=
$this
->
db
->
table
(
'translation
s
'
)
->
where
([
'sentence_id'
=>
$this
->
sentence_id
,
'translation'
=>
$sentence
])
->
select
(
'id'
)
->
fetch
();
if
(
$translation_id
)
{
$this
->
db
->
table
(
'translations'
)
->
update
([
'view_count = view_count + 1'
,
'updated_at'
=>
date
(
'Y-m-d H:i:s'
,
time
())]);
$this
->
updateWords
(
$this
->
sentences
[
$sentence
],
$translation_id
);
$this
->
storeWords
(
$this
->
sentences
[
$sentence
],
$translation_id
);
}
else
{
$this
->
db
->
table
(
'translations'
)
->
insert
([
'sentence_id'
=>
$this
->
sentence_id
,
'translation'
=>
$sentence
,
'correct_count'
=>
0
,
'incorrect_count'
=>
0
,
'view_count'
=>
1
,
'translated_word_count'
=>
count
(
$this
->
sentences
[
$sentence
])]);
$this
->
storeWords
(
$this
->
sentences
[
$sentence
],
$t
ranslation_id
);
$this
->
storeWords
(
$this
->
sentences
[
$sentence
],
$t
his
->
db
->
lastInsertId
()
);
}
}
}
private
function
storeWords
(
$words
,
$translation_id
)
{
foreach
(
$words
as
$position
=>
$word
)
{
$word_en_id
=
$this
->
db
->
table
(
'word_en'
)
->
where
([
'word_en'
=>
$word
])
->
select
(
'id'
)
->
fetch
();
$word_sk_id
=
$this
->
db
->
table
(
'word_sk'
)
->
where
([
'word_sk'
=>
$this
->
words
[
$position
]])
->
select
(
'id'
)
->
fetch
();
if
(
$word_en_id
)
{
$exists
=
$this
->
db
->
table
(
'word_translation'
)
->
where
([
'word_en_id'
=>
$word_en_id
,
'word_sk_id'
=>
$word_sk_id
,
'translation_id'
=>
$translation_id
])
->
count
(
'*'
);
if
(
!
$exists
)
{
$this
->
db
->
table
(
'word_translation'
)
->
insert
([
'word_en_id'
=>
$word_en_id
,
'word_sk_id'
=>
$word_sk_id
,
'translation_id'
=>
$translation_id
,
'word_position'
=>
$position
]);
}
}
else
{
$word_sk
=
$this
->
db
->
table
(
'word_sk'
)
->
insert
([
'word_sk'
=>
$this
->
words
[
$position
]]);
$word_en
=
$this
->
db
->
table
(
'word_en'
)
->
insert
([
'word_en'
=>
$word
]);
$this
->
db
->
table
(
'word_translation'
)
->
insert
([
'word_en_id'
=>
$word_en
->
id
,
'word_sk_id'
=>
$word_sk
->
id
,
'translation_id'
=>
$translation_id
,
'word_position'
=>
$position
]);
}
}
}
private
function
lematize
(
$sentence
)
{
$curl
=
new
Curl
();
$curl
->
headers
=
[
'Content-Type'
=>
'text/plain'
];
$result
=
$curl
->
post
(
'http://text.fiit.stuba.sk:8080/lematizer/services/lemmatizer/lemmatize/fast'
,
$sentence
);
$this
->
words
=
explode
(
' '
,
$result
->
body
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment