Skip to content

Commit

Permalink
feat(caseclassificationconfiguration): add new endpoints for document… (
Browse files Browse the repository at this point in the history
#821)

feat(caseclassificationconfiguration): add new endpoint for valueCount and documentCount'
  • Loading branch information
lprovost-coveo committed May 14, 2024
1 parent d13726c commit 238d542
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import {
CaseClassificationContentFieldsParams,
CaseClassificationDocumentGroupPreview,
CaseClassificationDocumentGroupPreviewParams,
CaseClassificationFieldCountParams,
FieldDocumentCount,
FieldValueCount,
} from './CaseClassificationConfigurationInterfaces.js';

export default class CaseClassificationConfiguration extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/machinelearning/configuration/caseclassif`;
static modelUrl = `${CaseClassificationConfiguration.baseUrl}/model`;
static fieldsUrl = `${CaseClassificationConfiguration.baseUrl}/fields`;
static fieldDocumentCountUrl = `${CaseClassificationConfiguration.baseUrl}/fields/{fieldName}/documentCount`;
static fieldValueCountUrl = `${CaseClassificationConfiguration.baseUrl}/fields/{fieldName}/valueCount`;

static previewUrl = `${CaseClassificationConfiguration.baseUrl}/preview`;

/**
Expand Down Expand Up @@ -61,4 +67,12 @@ export default class CaseClassificationConfiguration extends Resource {
params,
);
}

documentCount(params: CaseClassificationFieldCountParams) {
return this.api.post<FieldDocumentCount>(CaseClassificationConfiguration.fieldDocumentCountUrl, params);
}

valueCount(params: CaseClassificationFieldCountParams) {
return this.api.post<FieldValueCount>(CaseClassificationConfiguration.fieldValueCountUrl, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface CaseClassificationConfigurationModel {
*/
modelDisplayName: string;
/**
* The names of the sources containing the cases to use for model building.
* The names of the sources that contain the cases that the model will use.
*/
sources: string[];
/**
Expand All @@ -62,8 +62,7 @@ export interface CaseClassificationConfigurationModel {
*/
caseIdField: string;
/**
* The time period for which to extract cases for model building.
* Must contain an export period or a start time and end time.
* The case creation date range for the cases the model will use.
*/
caseExtractionPeriod?: ExtractionPeriod;
/**
Expand All @@ -77,7 +76,7 @@ export interface CaseClassificationConfigurationModel {
*/
fieldsToPredict: string[];
/**
* The field value to use as language.
* The name of the field that contains the value to use as the language.
*/
languageField?: string;
}
Expand All @@ -93,11 +92,11 @@ export interface CaseClassificationDocumentGroupPreviewParams {
*/
caseFilterConditions: FilterConditions[];
/**
* The field value to use as language.
* The name of the field that contains the value to use as the language.
*/
languageField: string;
/**
* The names of the sources containing the cases to use for model building.
* The names of the sources that contain the cases that the model will use.
*/
sources: string[];
}
Expand Down Expand Up @@ -131,8 +130,7 @@ export interface CaseClassificationDocumentGroupPreview {

export interface CaseClassificationContentFieldsParams {
/**
* The time period for which to extract cases for model building.
* Must contain an export period or a start time and end time.
* The case creation date range for the cases the model will use.
*/
caseExtractionPeriod: ExtractionPeriod;
/**
Expand All @@ -144,7 +142,7 @@ export interface CaseClassificationContentFieldsParams {
*/
languageField: string;
/**
* The names of the sources containing the cases to use for model building.
* The names of the sources that contain the cases that the model will use.
*/
sources: string[];
}
Expand All @@ -157,3 +155,71 @@ export interface CaseClassificationContentFields {
fields: CaseClassificationContentField[];
query: string;
}

interface CaseClassificationFieldCountAdvancedMode {
/**
* The query to use when building the model.
*/
advancedQuery: string;
/**
* The names of the sources that contain the cases that the model will use.
*/
sources?: never;
/**
* An array of filtering conditions.
*/
filterConditions?: never;
/**
* The name of the field that contains the value to use as the language.
*/
languageField?: never;
/**
* The case creation date range for the cases the model will use.
*/
caseExtractionPeriod?: never;
}

interface CaseClassificationFieldCountStandardMode {
/**
* The names of the sources that contain the cases that the model will use.
*/
sources: string[];
/**
* An array of filtering conditions.
*/
filterConditions?: FilterConditions[];
/**
* The name of the field that contains the value to use as the language.
*/
languageField: string;
/**
* The case creation date range for the cases the model will use.
*/
caseExtractionPeriod: ExtractionPeriod;
/**
* The query to use when building the model.
*/
advancedQuery?: never;
}

export type CaseClassificationFieldCountParams =
| CaseClassificationFieldCountAdvancedMode
| CaseClassificationFieldCountStandardMode;

export interface FieldValueCount {
/**
* The count of values matching a field.
*/
valueCount: number;
/**
* Indicates the presence of more values than the one returned in the count.
*/
areMoreValuesAvailable: boolean;
}

export interface FieldDocumentCount {
/**
* The count of items matching a field.
*/
documentCount: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,68 @@ describe('CaseClassificationConfiguration', () => {
expect(api.post).toHaveBeenCalledWith(CaseClassificationConfiguration.previewUrl, params);
});
});

describe('documentCount', () => {
modelConfigs.forEach(() => {
it('should make a POST call to the specific Case Classification Configuration url with an advancedQuery', () => {
const params = {advancedQuery: "@source='some source'"};

ccConfig.documentCount(params);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(
`${CaseClassificationConfiguration.baseUrl}/fields/{fieldName}/documentCount`,
params,
);
});

it('should make a POST call to the specific Case Classification Configuration url with standard params', () => {
const params = {
sources: ['some source'],
languageField: 'language',
caseExtractionPeriod: {exportPeriod: 'P6M', dateField: 'date'},
};

ccConfig.documentCount(params);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(
`${CaseClassificationConfiguration.baseUrl}/fields/{fieldName}/documentCount`,
params,
);
});
});
});

describe('valueCount', () => {
modelConfigs.forEach(() => {
it('should make a POST call to the specific Case Classification Configuration url with an advancedQuery', () => {
const params = {advancedQuery: "@source='some source'"};

ccConfig.valueCount(params);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(
`${CaseClassificationConfiguration.baseUrl}/fields/{fieldName}/valueCount`,
params,
);
});

it('should make a POST call to the specific Case Classification Configuration url with standard params', () => {
const params = {
sources: ['some source'],
languageField: 'language',
caseExtractionPeriod: {exportPeriod: 'P6M', dateField: 'date'},
};

ccConfig.valueCount(params);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(
`${CaseClassificationConfiguration.baseUrl}/fields/{fieldName}/valueCount`,
params,
);
});
});
});
});

0 comments on commit 238d542

Please sign in to comment.