Creating a justification plug-in for numeric literals

Note
Before you begin working through this article, please ensure you have:

Purpose

To create a justification plug-in that checks whether a concept literal contains a number.

Theory

Justification plug-ins are executed within the Erudine Behaviour Engine during the justification process, which is when behaviour is created. Unary justifications are based upon a single concept, whereas binary ones compare two concepts. See page 16 for details on how to create a binary justification plug-in. Although, the Erudine Behaviour Engine already contains some built-in justification plug-ins, you may want to create your own. When you create behaviour, as described in the Introduction to the Erudine Behaviour Engine Training Guide , these built in justification plug-ins are used. Justification plug-ins are loaded when starting the Erudine Behaviour Engine and should be stateless, so that they can be called using multiple threads. In this exercise, you will create a unary justification plug-in, called IsNumber that determines whether concept literals are numbers, rather than alphabetic characters. You will then unit test it to ensure it works correctly and then integrate it into the Erudine Behaviour Engine, by deploying it and use it to justify a conclusion in the Erudine Behaviour Engine.

Actions

Creating a justification plug-in

To create a unary justification plug-in:

  1. Open Eclipse.
  2. Create a Java class with the following details:
    • Class Name IsNumberJustificationPlugIn
    • Package Name exercise.justificationPlugIn.isNumber
    • Interface IUnaryJustificationPlugIn
  3. Collapse the src/java folder and expand the resources folder.
  4. Open the IsNumberJustificationPlugIn_IsSatisfied.java file.
  5. Copy the following text from the file into the isSatisfied method of the IsNumberJustificationPlugIn class:
    String literal = concept.getLiteral();
    try {
    Double.parseDouble( literal );
    } catch ( NumberFormatException e ) {
    return false;
    }
    return true;

    The isSatisifed method is used by the application to determine whether a given situation satisfies the justification. With a unary justification plug-in, a single argument is provided to the isSatisfied method: the concept to which the plug-in is attached. In this case, the concept will satisfy the justification if its literal is numeric.

  6. Open the IsNumberJustificationPlugIn_IsApplicableToConcept.java file.
  7. Type return true; into the isApplicableToConcept method of the IsNumberJustificationPlugIn class:
    The isApplicableToConcept method is used by the application to determine whether the justification plug-in can be applied to a particular concept. In this case, the plug-in is applicable to all concepts.
  8. Open the IsNumberJustificationPlugIn_GetDescription.java file.
  9. Copy the following text from the file into the getDescription method of the class:
    JustificationPlugInParameterDescription parameterDescription = 
    new JustificationPlugInParameterDescription( "Value", 
    "The value which will be tested for numericity." );
    return new UnaryJustificationPlugInDescription( "Is A Number", 
    "Numeric", "IsNumberJustificationPlugIn demonstrates the "
    + "use of a simple justificaton plug-in", parameterDescription, 
    "Is A Number", "Is Not A Number" );

    This text will create the following details for the new justification plug-in:

    • Name Name of the justification plug-in, which will appear whenever the plug-in can be selected from a list or menu.
    • Grouping A category for the view plug-ins, so that similar plug-ins can be grouped together on lists or menus.
    • Description A textual description of what the plug-in does, which may include HTML tags that format the text when it is displayed to the user. An example of using HTML is given in the completed version of this exercise.
    • Required Parameters Description of required parameters.
    • Standard Name Name that appears when you right click within the Conclusion & Justification screen of the Erudine Behaviour Engine to select the justification plug-in.
    • Negated Name Name that appears when you right click within the Conclusion & Justification screen of the Erudine Behaviour Engine to select the negative equivalent of the justification plug-in.
  10. Press Ctrl + Shift + O to organise the imports.
  11. Save the IsNumberJustificationPlugIn class.
    You will now test the justification plug-in to check it works correctly.

Unit testing a justification plug-in

To unit test the IsNumberJustificationPlugIn:

  1. Whilst still in Eclipse, collapse the resources folder and expand the src/unit folder.
  2. Expand the exercise.justificationPlugIn.isNumber package.
  3. Open the IsNumberJustificationPlugInTest java class to display its contents.
  4. Ensure all code is uncommented, by removing '//' from the beginning of any lines of code where it appears.
  5. Press Ctrl + Shift + O to organise the imports.
  6. Right click over the Java code and select Run As > JUnit Test from the context menu.
    This runs the tests contained in IsNumberJustificationPlugInTest class against the IsNumberJustificationPlugIn class that has been created in this exercise.
    If the tests are successful, the JUnit bar in the top left of the screen will change to green.
    This confirms that the justification plug-in has been correctly implemented,
  7. If you understand Java code, then examine the following methods:
    • testIsSatisfied method, which checks that it will return true for arguments that are numeric and false for arguments that are not numeric.
    • testIsApplicableForConcept methods, which will return true for any concept regardless of whether it contains a number or not.
  8. You will now preview the effects of running the justification plug-in.

Integrating a justification plug-in

Once the justification plug-in has been unit tested, the next step is to deploy it into the Erudine Behaviour Engine and then run the plug-in from within the Erudine Behaviour Engine.
To deploy and run the Is Number justification plug-in:

  1. Whilst still in Eclipse, deploy the Is Number justification plug-in by using the information here: Deploying extensions.
  2. Open the Erudine Behaviour Engine and you are ready to create a new knowledge model.
  3. Right click in the blank area on the Knowledge Model screen and select Property > Conceptual Graph Property from the context menu.
  4. Type Node1 in the box and click OK .
    A new node named Node1 is displayed.
  5. Right click on the new node and select Properties... from the context menu.
    The Properties screen is displayed.
  6. Find the com.erudine.inbox.data property.
  7. Click once in the right hand column of the com.erudine.inbox.data property.
    The row for that property will now display an ellipsis (...) to the right of the column.
  8. Click on the ellipsis ( ... ) to display a box for this property.
  9. Click the Remove Item button to remove the default situation
  10. In the right hand pane, type [Number: 23].
  11. Click Add Item button and type [Number: 'Twenty Three'] in the right hand pane.
  12. Click Add Item button again and type [Number: 7] in the right hand pane.
  13. Click the OK button to save these items and close the box.
  14. In the Properties screen, click the Apply button to save the changes and return to the Knowledge Model screen.
  15. Double click on the Node1 node to display the Conclusion and Justification screen.
  16. Select situation 0 from the Situation List on the left.
  17. Right click on a blank space in the Conclusion tab and select Add [int:Entity] from the context menu.
  18. Type Test as the Type and click OK .
  19. Right click on the Number concept and select Open Justification Dialog from the context menu.
    The Justifications dialog box is displayed.
  20. From the Numeric folder, select the Is A Number justification option and click OK .
  21. Click the OK button at the bottom of the screen.
  22. Select Id 0 from the Situation List and notice that because the Number concept has a numeric value, a conclusion is added.
  23. Select Id 1 from the Situation List and notice that because the Number concept does not contain a numeric value, a conclusion is not added.
  24. Close the Erudine Behaviour Engine.
  25. Close Eclipse.

Platform: all
EBE Version: 2.4
Category: Development Training Guide
Author: Patrick Peisker


Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Activity
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

 

Other Features

Add Content