1. Home
  2. Sample Projects
  3. Student pass-fail state

Student pass-fail state

Print Friendly, PDF & Email

◷ Reading Time: 4 minutes

Using Natural Language, validate the input and ultimately decide the pass-fail state of a student. This will create the JavaScript code for the Natural Language code and can be tested in the JavaScript Testbed.

Scenario

In this tutorial, we are going to write a list of rules in Natural Language to validate the input and determine the pass-fail state of a student:

  • If the total score is greater than or equal to 50, state pass, otherwise fail

Video Description

Process Steps

These are the procedural steps for this project.

1. Create a Fact concept to define the inputs: ‘Concept.xml’ 

There is one object named ‘Person’ and its attributes are Name, Birth year, Test results, Pass state, and Last year results. This will make it easier to manage the variables.

2. Add a Business Glossary to define the expressions: ‘BusinessGlossary.xml’ 

Using business glossary, you can define expressions such as ‘(Person.LastYearTestResults) + (Person.TestResults)’ with a term ‘Total’. Therefore, you can use the term ‘Total’ in your code instead of using the long expression.

  • Total: (Person.LastYearTestResults) + (Person.TestResults)
  • Name: Person.Name
  • BirthYear: Person.BirthYear

3. Add a Natural Language file and write validation rules in Natural Language: ‘PersonValidation.xml’

Name and BirthYear are defined in the Business Glossary.

when Validate name
  Name is ""
then
	error = "Name cannot be empty"
	and isValid = false
otherwise
	Validate BirthYear
end
 
when Validate BirthYear
  BirthYear is null
then
	error = "Birth Year cannot be empty"
	and isValid = false
end

4. Add a flow file: ‘Flow.xml’ 

Add the created Natural Language file to the flow.

5. Add another Natural Language file: ‘TestResultState.xml’ 

Write the rules to state the pass-fail grading of a student. Here we can use the term ‘Total’ which is defined in the Business Glossary.

when 
  isValid 
then
  DefinePassState
end
 
when DefinePassState
	Total > 50
then
	Person.Pass = true
otherwise
	Person.Pass = false
end

6. Add the Natural Language file to the flow 

The flow will show the direction and run all of the files by connecting the two Natural Language files.

Run in JavaScript Testbed

Once the code is running without errors in FlexRule Designer, you can test the code in JS Testbed.

1. Open the Natural Language file

2. Click on the ‘JS Test Bed’ icon

3. JS Testbed will open in the web browser

4. Select ‘Code’ to insert the Input Parameters

5. Copy the Input Parameters.

6. Click on ‘Run Logic’

7. Output is displayed in Result section

Download the project

The project (NaturalLanguageSample.zip) can be downloaded from the attachment at the end of the page.

Updated on July 2, 2019

Article Attachments

Was this article helpful?

Related Articles