규칙 변수의 유형
규칙 변수는 상수, 표현식, 오브젝트 또는 오브젝트의 콜렉션을 표현할 수 있습니다.
이름 및 값을 지정하여 규칙 변수를 정의합니다. 사용자는 이름을 선택하고, 값은 텍스트, 숫자 또는 산술 연산식일 수 있습니다. 값은 엔티티 또는 이벤트의 속성일 수도 있습니다(예: the age of 'the customer' 또는 the customer of this purchase event). 변수를 설정하면 변수를 선언하는 규칙의 파트에서 이를 사용할 수 있습니다.
상수를 정의하는 규칙 변수
규칙 변수의 값은 상수일 수 있습니다. 예를 들어, 변수 maxAmount가 다음 규칙을 더 쉽게 이해하도록 하고 규칙의 if 및 then 파트가 동일한 값을 사용하는지 확인합니다.
definitions set maxAmount to 1000000; if the amount of 'the loan' is at least maxAmount then in 'the loan report', reject the data with the message "The loan cannot exceed " + maxAmount;
규칙 변수의 제한사항
where 연산자를 사용하여 규칙의 definitions 파트에서 변수를 추가로 제한할 수 있습니다.
다음 규칙에서, where는 loyal customer 변수를 골드 카테고리의 고객으로 제한합니다.
when a purchase event occurs, called 'the purchase' definitions set 'loyal customer' to the customer of 'the purchase' where the category of this customer is Gold; if the value of the shopping cart of 'loyal customer' is more than 200 then print "Apply super discount";
동일한 유형의 다중 오브젝트를 참조하는 규칙
상이한 항공편을 참조하도록 요구하는 규칙이 있는 경우에는 규칙의 definitions 파트에서 다른 발생을 정의해야 합니다. 예:
definitions
set 'flight1' to a flight in the flights of 'the customer';
set 'flight2' to a flight in the flights of 'the customer'
where the scheduled departure time of this flight is after the scheduled arrival time of 'flight1';
if the scheduled departure time of 'flight2' is before 1 hour after the scheduled arrival time of 'flight1'
then print "less than 1 hour of transit time";
참고: 규칙이 동일한 유형의 다중 오브젝트를 참조하는 경우에 규칙은 동일한 오브젝트의 다른 치환에 적용될 수 있습니다.
예에는 두 항공편이 있으므로 규칙은 2회 실행됩니다. 규칙이 세 명의 고객을 언급하면 규칙은 6번 실행됩니다.
지난 이벤트를 참조하는 규칙 변수
규칙 변수를 사용하면, 에이전트에 의해 처리되었으며 작업 메모리에 저장되어 있는 이벤트를 참조할 수 있습니다.
예를 들어, 이는 지속적으로 이벤트를 비교하는 데 유용할 수 있습니다.
when a return event occurs, called 'the return'
definitions
set 'the purchase' to a purchase event;
if 'the return' is in the same calendar week as 'the purchase'
then...
오브젝트의 모든 인스턴스를 검색하는 규칙 변수
all <...> 연산자를 사용하여 오브젝트의 모든 인스턴스의 목록을 검색하는 변수를 작성할 수 있습니다. 예:
definitions
set 'gold customers' to all customers in the boarded passengers of 'the flight'
where the category of each customer is Gold;
set 'junior gold customer' to a customer in 'gold customers'
where the age of this customer is at most 15;
set 'senior gold customer' to a customer in 'gold customers'
where the age of this customer is at least 65;
이 예제에서는 세 개의 변수를 작성합니다.
- gold customers: 골드 카테고리의 고객 목록입니다.
- junior gold customer: 골드 고객 목록 중 15세 이하의 고객입니다.
- senior gold customer: 골드 고객 목록 중 65세 이상인 고객입니다.