Evaluation functions and Ontology edits(评估函数与本体编辑)¶
When an evaluation suite is run, the Logic function for each test case is executed. For functions that involve Ontology edits (such as creating, editing, or deleting objects), each test case is executed in an Ontology simulation. This ensures that the actual Ontology remains unchanged during testing and evaluation.
Custom evaluation functions for Ontology edits¶
For AIP Logic functions that result in Ontology edits, users must configure custom evaluation functions in TypeScript or use intermediate parameters. Custom evaluation functions must return either Boolean or numeric types. One evaluation function may also return multiple metrics by returning a struct consisting of Boolean or numeric types.
When adding evaluation functions in the Evaluations application, you will be prompted to either author a function in Code Repositories or select an existing published function. With the guide provided below, explore various kinds of Ontology edits and learn how to effectively use TypeScript functions for their evaluation.
Created objects¶
In the case of Ontology edits that involve creating objects, the created object only exists in the simulated Ontology. As such, these created objects cannot be configured as a test case parameter for passing in directly. Instead, search for it using an identifiable property and check its properties.
@Function()
public async checkTicketWasCreated(
expectedRequester: string,
expectedDate: LocalDate,
expectedClassification: string,
): Promise<boolean> {
const matches = Objects.search().supportTicket()
.filter(ticket => ticket.ticketRequester.exactMatch(expectedRequester))
.filter(ticket => ticket.ticketCreationDate.exactMatch(expectedDate))
.all();
if (matches.length !== 1) {
return false;
}
return matches[0].classification === expectedClassification;
}
Edited objects¶
For object edit output types, the edited object already exists in the real Ontology. In the simulated Ontology, you can pass it directly into the function and check its properties, as illustrated below:
@Function()
public checkTicketClassification(
ticket: SupportTicket,
expectedClassification: string,
): boolean {
return ticket.classification === expectedClassification;
}
Deleted objects¶
In the case of Ontology edits that involve deleting objects, the object is expected to be deleted in the simulated Ontology, so it cannot be passed into the evaluation function. To verify that the object was actually deleted, pass an identifiable property of the object and search for it to ensure that there are no results.
@Function()
public async checkTicketWasDeleted(ticketId: string): Promise<boolean> {
const count = await Objects.search().supportTicket()
.filter(ticket => ticket.ticketId.exactMatch(ticketId))
.count();
return count === 0;
}
中文翻译¶
评估函数与本体编辑¶
运行评估套件时,每个测试用例的逻辑函数(Logic function)都会被执行。对于涉及本体编辑(Ontology edits)的函数(如创建、编辑或删除对象),每个测试用例将在本体模拟(Ontology simulation)环境中执行。这确保了实际本体在测试和评估过程中保持不变。
本体编辑的自定义评估函数¶
对于会产生本体编辑的 AIP 逻辑函数(AIP Logic functions),用户必须在 TypeScript 中配置自定义评估函数,或使用中间参数。自定义评估函数必须返回布尔型或数值型。一个评估函数也可以通过返回由布尔型或数值型组成的结构体(struct)来返回多个指标。
在评估应用(Evaluations application)中添加评估函数时,系统会提示您在代码仓库(Code Repositories)中编写函数,或选择已有的已发布函数。借助以下指南,探索各种本体编辑类型,并学习如何有效使用 TypeScript 函数进行评估。
已创建的对象¶
对于涉及创建对象的本体编辑,创建的对象仅存在于模拟本体中。因此,这些创建的对象无法直接配置为测试用例参数传入。相反,应使用可识别的属性进行搜索并检查其属性。
@Function()
public async checkTicketWasCreated(
expectedRequester: string,
expectedDate: LocalDate,
expectedClassification: string,
): Promise<boolean> {
const matches = Objects.search().supportTicket()
.filter(ticket => ticket.ticketRequester.exactMatch(expectedRequester))
.filter(ticket => ticket.ticketCreationDate.exactMatch(expectedDate))
.all();
if (matches.length !== 1) {
return false;
}
return matches[0].classification === expectedClassification;
}
已编辑的对象¶
对于对象编辑输出类型,编辑的对象已存在于实际本体中。在模拟本体中,您可以直接将其传入函数并检查其属性,如下所示:
@Function()
public checkTicketClassification(
ticket: SupportTicket,
expectedClassification: string,
): boolean {
return ticket.classification === expectedClassification;
}
已删除的对象¶
对于涉及删除对象的本体编辑,该对象预计会在模拟本体中被删除,因此无法传入评估函数。要验证对象是否确实被删除,请传入对象的可识别属性并进行搜索,确保没有返回结果。
@Function()
public async checkTicketWasDeleted(ticketId: string): Promise<boolean> {
const count = await Objects.search().supportTicket()
.filter(ticket => ticket.ticketId.exactMatch(ticketId))
.count();
return count === 0;
}