You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Logic.md
+98-22Lines changed: 98 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,7 @@ The table below illustrates that:
45
45
46
46
47
47
48
-
## GenAI Natural Language Logic
48
+
## GenAI: Natural Language Logic
49
49
50
50
You can use Natural Language to create logic during project creation, or for existing projects. For example: `The Customer's balance is the sum of the Order amount_total where date_shipped is null`.
51
51
@@ -58,7 +58,7 @@ Think of Natural Language Logic as a translation process down onto underlying ru
58
58
59
59
60
60
61
-
## With Code Completion
61
+
## IDE: With Code Completion
62
62
63
63
You can also use your IDE with Code Completion to add rules, and their arguments.
64
64
@@ -81,7 +81,7 @@ Similarly, you can change rules without worrying about the order of execution.
81
81
82
82
Inside the larger process above, here is the best way to learn how to use rules:
83
83
84
-
1.**Rule Summary**: review the table above; there are a small number of rules, since their power lies in chaining
84
+
1.**Rule Summary**: review the Rule Types table above; there are a small number of rules, since their power lies in chaining
85
85
86
86
***Alert:** Logic consists of rules and Python. You will quickly learn to use logic events; focus on the *rules as the preferred* approach, using Python (events, etc) as a *fallback*.
87
87
@@ -95,9 +95,10 @@ Inside the larger process above, here is the best way to learn how to use rules:
95
95
96
96
97
97
98
-
99
98
## Rule Patterns
100
99
100
+
Rules support *chaining:* a rule may change a value that triggers other rules, including across tables. Mastering such ***multi-table logic*** is the key to using rules effectively. The most typical examples are described below.
101
+
101
102
| Pattern | Notes | Example
102
103
| :------------- | :-----| :---- |
103
104
|**Chain Up**| parent sums and counts mean that child row changes can ***adjust*** parents |[Derive Balance](Behave-Logic-Report.md/#scenario-good-order-custom-service){:target="_blank" rel="noopener"} |
@@ -109,26 +110,9 @@ Inside the larger process above, here is the best way to learn how to use rules:
109
110
|**Ready Flag**| Multi-session editing, then , when ready...<br>adjust related data / enforce constraints |[Make Order Ready](Behave-Logic-Report.md/#scenario-order-made-ready){:target="_blank" rel="noopener"} |
110
111
|**Events for Lib Access**| Events enable Python, use of standard libs (e.g., Kafka) |[Ship Order](Behave-Logic-Report.md#scenario-good-order-custom-service){:target="_blank" rel="noopener"} |
111
112
112
-
113
-
## Logic Patterns
114
-
115
-
WebGenAI was trained to understand the Natural Language Logic problems shown below. Please see [Natural Language Logic](WebGenAI-CLI.md#natural-language-logic){:target="_blank" rel="noopener"}.
116
-
117
-
| Example | Notes |
118
-
| :------------- | :------------- |
119
-
| Airport - at least 10 tables<br>A flight's passengers must be less than its Airplane's seating capacity |
120
-
| System for Departments and Employees.<br>Sum of employee salaries cannot exceed department budget |
121
-
| Create a system with Employees and their Skills.<br>More than One Employee can have the same Skill.<br>EmployeeSkill.rating = Skill.rating<br>An Employee's skill-rating is the sum of the Employee Skills rating, plus 2 * years of service. |
122
-
| Students have probations and sick days.<br>Signal an error if a Student's can-graduate is True, and there are more 2 probations, or more than 100 sick days.
123
-
| Applicant have felonies and bankruptcies.<br>Signal error if is-hirable is true and there are more than 3 bankruptcies, or 2 felonies.
124
-
| Students have Grades and belong to Clubs.<br>Copy the name from Club to Student Club<br>The student's service activity is the count of Student Clubs where name contains 'service'. <br>Signal error if student is eligible for the honor society == True, and their grade point average is under 3.5, or they have less than 2 service activities
125
-
| Products have Notices, with severity 0-5.<br>Raise and error if product is orderable == True and there are any severity 5 Notices, or more than 3 Notices.
126
-
| Create a system with customers, orders, items and products.<br>Include a notes field for orders.<br><br>Use Case: enforce the Check Credit for ready orders:<br>1. Customer.balance <= credit_limit<br>2. Customer.balance = Sum(Order.amount_total where date_shipped is null and ready is True)<br>3. Order.amount_total = Sum(Item.amount)<br>4. Item.amount = quantity * unit_price<br>5. Store the Item.unit_price as a copy from Product.unit_price<br><br>Use Case: Compute Products ordered<br>1. Item.ready = Order.ready<br>2. Product.total_ordered = sum(Item.quantity) where ready == True<br>3. Product.reorder_required = quantity_on_hand <= total_ordered<br><br>Use Case: No Empty Orders<br>1. Order.item_count = Count(Items)<br>2. When setting the date_shipped, item_count must be > 0. | Ready Flag
127
-
| Teachers, courses which have offerings, and students who have offerings.<br><br>Use Case: capacity<br>teachers cannot be assigned to more than 5 courses<br>students cannot have more enrollments than 6<br><br>Use Case: budget control<br>courses have a charge, which is copied to enrollments charge<br>a student's total enrollment charges cannot exceed their budget
128
-
129
113
130
114
131
-
## Case Study
115
+
## Rules Case Study
132
116
133
117
The best way to learn the rules is by a Case Study approach:
134
118
@@ -154,3 +138,95 @@ The best way to learn the rules is by a Case Study approach:
154
138
155
139
* Reveal the solution: open the disclosure box: "Tests - and their logic - are transparent.. click to see Logic"
156
140
141
+
142
+
143
+
144
+
# Learning Natural Language
145
+
146
+
As noted above, it is important to be clear on the rules generated for logic. Use the examples below to test your understanding.
147
+
148
+
WebGenAI provides the [Logic Editor](WebGenAI-logic-editor.md) so you can see/edit the translation:
| Formal vs Informal | You can: *Customer.balance = Sum(Order.amount_total where date_shipped is null)* | Or, more simply: *The Customer's balance is the sum of the Order amount_total where date_shipped is null*
156
+
| Integration Logic | Kafka | *Send the Order to Kafka topic 'order_shipping' if the date_shipped is not None*
157
+
| Multi-rule Logic | See Multi-rule Logic - Generatd Rules, below | *Sum of employee salaries cannot exceed department budget*
158
+
| Conditional Derivations | See Conditional Derivation - Generated Rules, below | Provide a 10% discount when buying more than 10 carbon neutral products<br>The Item carbon neutral is copied from the Product carbon neutral
159
+
| Cardinality Patterns<br>- *Qualified Any* | See Cardinality Patterns - Generated Rules, below | Products have Notices, with severity 0-5.<br>Raise and error if product is orderable == True and there are any severity 5 Notices, or more than 3 Notices.
# Ensure product is not orderable if conditions on notices are met.
204
+
Rule.constraint(validate=Product,
205
+
as_condition=lambdarow: not (row.orderable and (row.class_5_notice_count >0or row.notice_count >3)),
206
+
error_msg="Orderable product contains severity 5 or excessive notices.")
207
+
208
+
# End Logic from GenAI
209
+
```
210
+
</details>
211
+
212
+
213
+
214
+
## Natural Language Examples
215
+
216
+
WebGenAI was trained to understand the Natural Language Logic problems shown below. These automate many of the rule patters described above.
217
+
218
+
Please see [Natural Language Logic](WebGenAI-CLI.md#natural-language-logic){:target="_blank" rel="noopener"}.
219
+
220
+
| Example | Notes |
221
+
| :------------- | :------------- |
222
+
| Airport - at least 10 tables<br>A flight's passengers must be less than its Airplane's seating capacity |
223
+
| System for Departments and Employees.<br>Sum of employee salaries cannot exceed department budget |
224
+
| Create a system with Employees and their Skills.<br>More than One Employee can have the same Skill.<br>EmployeeSkill.rating = Skill.rating<br>An Employee's skill-rating is the sum of the Employee Skills rating, plus 2 * years of service. |
225
+
| Students have probations and sick days.<br>Signal an error if a Student's can-graduate is True, and there are more 2 probations, or more than 100 sick days.
226
+
| Applicant have felonies and bankruptcies.<br>Signal error if is-hirable is true and there are more than 3 bankruptcies, or 2 felonies.
227
+
| Students have Grades and belong to Clubs.<br>Copy the name from Club to Student Club<br>The student's service activity is the count of Student Clubs where name contains 'service'. <br>Signal error if student is eligible for the honor society == True, and their grade point average is under 3.5, or they have less than 2 service activities
228
+
| Products have Notices, with severity 0-5.<br>Raise and error if product is orderable == True and there are any severity 5 Notices, or more than 3 Notices.
229
+
| Create a system with customers, orders, items and products.<br>Include a notes field for orders.<br><br>Use Case: enforce the Check Credit for ready orders:<br>1. Customer.balance <= credit_limit<br>2. Customer.balance = Sum(Order.amount_total where date_shipped is null and ready is True)<br>3. Order.amount_total = Sum(Item.amount)<br>4. Item.amount = quantity * unit_price<br>5. Store the Item.unit_price as a copy from Product.unit_price<br><br>Use Case: Compute Products ordered<br>1. Item.ready = Order.ready<br>2. Product.total_ordered = sum(Item.quantity) where ready == True<br>3. Product.reorder_required = quantity_on_hand <= total_ordered<br><br>Use Case: No Empty Orders<br>1. Order.item_count = Count(Items)<br>2. When setting the date_shipped, item_count must be > 0. | Ready Flag
230
+
| Teachers, courses which have offerings, and students who have offerings.<br><br>Use Case: capacity<br>teachers cannot be assigned to more than 5 courses<br>students cannot have more enrollments than 6<br><br>Use Case: budget control<br>courses have a charge, which is copied to enrollments charge<br>a student's total enrollment charges cannot exceed their budget
0 commit comments