Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: NLP module strict null checks issues #544

Merged

Conversation

yassinedorbozgithub
Copy link
Collaborator

@yassinedorbozgithub yassinedorbozgithub commented Jan 9, 2025

Motivation

The motivation of this PR is to resolve NLP Module null checks issues

Fixes #540

image

Checklist:

  • I have performed a self-review of my own code
  • New and existing unit tests pass locally with my changes

api/src/nlp/controllers/nlp-sample.controller.ts Outdated Show resolved Hide resolved
api/src/nlp/controllers/nlp-sample.controller.ts Outdated Show resolved Hide resolved
api/src/nlp/controllers/nlp-sample.controller.ts Outdated Show resolved Hide resolved
@yassinedorbozgithub yassinedorbozgithub force-pushed the 540-issue-nlp-module-strictnullchecks-issues branch from dbf80b0 to 542a02a Compare January 10, 2025 14:08
@@ -151,7 +151,7 @@ export default abstract class BaseNlpHelper<
})
.concat({
entity: 'language',
value: s.language.code,
value: s.language!.code,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't language supposed to be mandatory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yassinedorbozgithub @MohamedAliBouhaouala Can we open a Issue to force the user to set the language for each sample ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created ✅ #561

@yassinedorbozgithub yassinedorbozgithub marked this pull request as draft January 12, 2025 09:22
@yassinedorbozgithub yassinedorbozgithub marked this pull request as ready for review January 13, 2025 14:14
@@ -151,7 +151,7 @@ export default abstract class BaseNlpHelper<
})
.concat({
entity: 'language',
value: s.language.code,
value: s.language!.code,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yassinedorbozgithub @MohamedAliBouhaouala Can we open a Issue to force the user to set the language for each sample ?

@@ -117,11 +121,11 @@ describe('NlpSampleService', () => {

describe('findOneAndPopulate', () => {
it('should return a nlp Sample with populate', async () => {
const result = await nlpSampleService.findOneAndPopulate(noNlpSample.id);
const result = await nlpSampleService.findOneAndPopulate(noNlpSample!.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May encounter the risk of passing 'undefined' as a queried value.

@@ -167,7 +172,7 @@ describe('NlpSampleService', () => {

describe('The deleteCascadeOne function', () => {
it('should delete a nlp Sample', async () => {
const result = await nlpSampleService.deleteOne(noNlpSample.id);
const result = await nlpSampleService.deleteOne(noNlpSample!.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same remark as above

@@ -128,15 +128,15 @@ export class NlpValueService extends BaseService<
if ('start' in e && 'end' in e) {
const word = sampleText.slice(e.start, e.end);
return (
word !== e.value && vMap[e.value].expressions.indexOf(word) === -1
word !== e.value && vMap[e.value].expressions?.indexOf(word) === -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may encounter the risk of indexing an undefined object

);
}
return false;
})
.map((e) => {
return this.updateOne(vMap[e.value].id, {
...vMap[e.value],
expressions: vMap[e.value].expressions.concat([
expressions: vMap[e.value].expressions?.concat([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may encounter the risk of concatenating undefined objects

@yassinedorbozgithub
Copy link
Collaborator Author

Hi @MohamedAliBouhaouala, i have used the ! symbol as an optimistic strategy inside the .spec.ts files

@yassinedorbozgithub yassinedorbozgithub merged commit 7be2da3 into main Jan 13, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🤔 [ISSUE] - NLP Module strictNullChecks issues
3 participants