Optimized "end-of-corpus" handling (fixing issue #38) (#70)

* Better handling of end-of-corpus detection.

* Adjusted docstring.
pull/71/head
Thorsten Müller 2021-10-27 06:34:29 +02:00 committed by GitHub
parent ce0b7217b0
commit 35d030a24e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -120,6 +120,7 @@ class PromptsFS:
def get(self, prompt_number: int) -> response:
"""Get text from corpus by prompt number.
If end of corpus file is reached then '___CORPUS_END___' is returned as phrase.
Args:
prompt_number (int): Number of requested prompt from corpus.
@ -132,8 +133,9 @@ class PromptsFS:
"prompt": self.data[prompt_number],
"total_prompt": len(self.data)
}
return response(True, data=d)
except IndexError as e:
# TODO: loggin
print(e)
return None
d = {
"prompt": "___CORPUS_END___",
"total_prompt": 0
}
return response(True, data=d)

View File

@ -131,11 +131,18 @@ class Record extends Component {
getPrompt(uuid)
.then(res => res.json())
.then(res => {
if (res.success) {
this.setState({
prompt: res.data.prompt,
totalPrompt: res.data.total_prompt
});
if (res.data.prompt === "___CORPUS_END___") {
this.setState({
shouldRecord: false,
prompt: "*no more phrases in corpus to record*",
totalPrompt: res.data.total_prompt
})
}
if (res.success && res.data.prompt !== "___CORPUS_END___") {
this.setState({
prompt: res.data.prompt,
totalPrompt: res.data.total_prompt
});
}
});
};