The extension method of Jess function function based on Java

Source: Internet
Author: User
Tags sin

Jess is the acronym for the Java Expert System shell, a rule engine on the Java platform, a superset of the clips programming language, and a language for developing expert systems in full use of the Java language. For rule-based reasoning, especially for logical conditions, Jess is the fastest in the known rule engine. It is based on the enhanced Rete algorithm, supports forward reasoning, supports back inference, has direct inference to the Java object, and supports query access to the Working storage area [1-2].

[2] The Jess language itself provides many powerful functions for expert system developers to invoke, but these functions cannot encompass all functions and operations, and it is not easy to build an expert system that is expanding and increasing in size and complexity by simply jess the functions of the language itself. In addition, the extensibility of software development language is also one of the important features of excellent programming language, programmers use the software language itself, or other languages, write custom function functions, in order to achieve the purpose of extending and enhancing the function of software, in this regard Jess is no exception. In this paper, from the Jess language to provide user-defined function interface Userfunction [3-4], to analyze the implementation of Useffunction interface specific details, This paper analyzes the intrinsic relation between the call parameter of the Jess function calling statement and the Useffunction interface method, extracts the parameters of the transformation Jess function into the Java environment and handles the corresponding function requirements, and finally transforms the processing result into Jess. This procedure implements the purpose of extending the Jess language function function with the Java language. This method is applied to the research and development of the maintenance strategy of the compressor based on RCM, and realizes the decision of grading maintenance strategy.

1 Userfunction interface and its implementation

Userfunction is an interface provided by Jess, Jess all of the built-in functions are created by implementing this interface. If the user or programmer wants to extend the function of Jess, you can also create a custom function function by implementing this interface, and the different implementations correspond to different function functions. Jess is written in the Java language, so using Java classes to implement this interface is a natural choice, different implementations of the function of different functions, once loaded into the Jess, Jess as if calling their own built-in functions to invoke these custom extension functions.

From the point of view of data processing, the implementation of the Userfunction interface using Java classes is a process of data type conversion, processing, and re-conversion: First Java extracts the Jess type data and translates it into a data type that Java can manipulate. Then Java to the data according to the functional requirements of a certain operation processing, the Java type Data processing results, and finally the Java type of processing results converted to Jess type data and returned to Jess. As shown in procedure 1 above.

  

1.1 Userfunction Interface Prototype

The Userfunetion interface contains only two abstract Java methods: GetName and call. The interface prototypes are:

public interface userfunction{string GetName (); Value Call (Valuevector vv,context Context) throws jessexception;}

The implementation of the Userfunction interface is the implementation of both methods.

Implementation of 1.2 GetName method

The implementation of the GetName method is simple and returns the function name directly in the form of a string. The fixed form of implementation is:

String GetName () {return ' function name ';}

Where the function name in the return statement is the function name of the function to be called in Jess, the function name is not related to the class name of the class that implements the interface. Jess is used to manage its functions using a hash table, which is a one by one correspondence between the function name and the key value in the Hashtable, so the function name cannot be a string variable, only a string constant. For the name of the function names, as long as the function name naming specification requirements can be.

Implementation of 1.3 call method

The implementation of the abstract method call is the key to the implementation of the interface userfunction. The implementation of this method can be divided into 3 steps: ①java the Jess function parameter extraction and data type conversion, ②java according to the function requirements of the processing of data, 3③java the conversion of the result data type and return the result to Jess.

1) Java for Jess function parameter extraction and data type conversion

In Jess, the general format of a function call is: (parameter 1 parameter 2 ...), where the function name, each parameter is separated by a space. The function name and each parameter are considered as a whole, in Jess it is regarded as an ordered sequence (the sequence is a data type of Jess), and all the information of that sequence is passed to the parameters Valuevector and context of the method call, so in Java, Each parameter of the Jess function can be extracted from the parameter Valuevector and context of the method call.

Valuevector is the class used internally by Jess to represent the sequence, and when a function is called, the ordered sequence, including the function name and individual parameters, is actually an object of the Valuevector class. The Valuevector class is very similar to the container class in Java, and you can use the Get () method to get each element of the collection (sequence), such as Get (0), which is the function name of the Jess function, and get (1) is the parameter 1 of the Jess function.

However, the return value of the Get () method is the value object. Value is a collection of wrapper classes in Jess, which contains 11 wrapper classes, the class name of each wrapper class, the meaning, and the method to get the corresponding object value, as shown in table 1. To get the value of an object from a value object and convert the data type to a data type in which Java can recognize the operation, you need to Jess the wrapper class to get the corresponding object value, and the method call's parameter context. The parameter context of the call is the contextual information class at the time of execution of a function in Jess, whose instance object contains contextual information when the function is called, and also contains a pointer to the Rete object. In order to avoid parsing and extracting the object value of a class of value object, the context class object usually gets the parameter of the corresponding object value method as the value class object.

  

For example, a function call in Jess (Uadd 3 "Chx"), if VV is an object of the Valuevector class, and the context is an object of the context class, you can use Vv.get (1). Intvalue (context) The Jess method obtains the integer parameter value of the function 3,vv.get (2). The StringValue (context) method obtains the string parameter value "Chx" of the Jess function.

2) Java processing of data according to functional requirements

After the various parameters of the Jess function have been extracted and converted to the Java type data, the next step is to use the Java data processing function according to function function, and get the result of processing the data.

3) Java transforms the result data type and returns the conversion result to Jess

Java's data processing results are still Java type data, and the return value type of method call is Jess's value class type (see table 1), so you need to convert the Java type data to the Jess type again, and return the converted Jess type data to Jess. The only way to do this is to return the created value instance object, whose general format is: return new Value (returns the object name, RU.) xxxx), where xxxx is the value class name of Jess. For example retum new Value (Str,ru. string), which returns the object Str to Jess as a string type.

Because many objects and methods of the Jess class are used in the implementation of the Userfunction interface, the Jess package is imported in the class file that implements the Userfunction interface, and before the Java class is compiled, To add an external jar package Jess.jar and Jsr94.jar to the compilation library file. Thus, the Userfunction interface implements the class file completion.

2 loading functions that implement the Userfunction interface into Jess

In the eclipse environment where the Jess tab module is loaded, the class source files that implement the interface userfunction are compiled, Build the. class file, copy the. class file to the bin directory where the Jess software is installed, and then, at the Jess prompt, run the Load-function function, and implement the class file name of the interface useffunction as an argument to the Load-function function, after executing the command, If Jess displays true, the load is successful.

In the. clp file in the Eclipse environment, if you want to invoke the extended custom function function, you add the path to the compiled library file that contains the generated. class file, and then execute the Load-function function statement, and finally you can call the extension's custom function function directly.

3 Jess Decision on the maintenance strategy of RCM grading status

3.1 RCM overhaul strategy [5]

The RCM (Reliability centered maintenance), a reliability-centric service, is based on the design features, operational functions, failure models and consequences of the equipment, and is maintained for the purpose of maximizing the reliability of the equipment [5-6]. RCM overhaul strategy can synthesize equipment status and equipment in the system of importance, balance the state of equipment and equipment reliability, reasonable arrangement of equipment maintenance level and maintenance strategy.

The decision of RCM grading status maintenance strategy is the comprehensive performance evaluation index of the equipment p according to table 2, in which p is determined by the comprehensive index of equipment health status (health status) and equipment importance comprehensive index ruler (abbreviation importance), and the weight allocation factor Q which affects the overhaul strategy. As shown in the formula (1):

  

  

D can indicate the urgency of the equipment needs to be repaired, the greater the D the more urgent the requirements of the equipment needs to be repaired; The greater the R value, the higher the importance of the device; The higher the H value means the better the health of the device; q=45° indicates that the importance of the device is equal to the device's health status day when the equipment overhaul policy decision is taken.

If the equipment is h=0.2,r=0.4, the p=0.6 can be calculated, the maintenance decision is the plan priority; If the equipment h=0.65,r=0.75, the p=0.55 can be calculated, the maintenance decision is planned or postponed; if the device is h=0.8,r=0.4, it can be calculated p= 0.3, the overhaul decision is deferred mode.

There are relatively few numerical functions in Jess, the calculation of P-value in formula (1), and the decision of grading maintenance strategy based on table 2 and P-value, can extend Jess function function in this aspect by implementing interface Userfunction by Java.

3.2 Java class Chxcalp implementation interface Userfunction program source code [5]

Import jess.*;

public class Chxcalp implements userfunction{

Public String GetName ()

{

Return "Chxcalp";

}

Public Value Call (Valuevector vv,context c) throws Jessexception

{

Double H=vv.get (1). Floatvalue (c);

Double R=vv.get (2). Floatvalue (c);

Double Sita=vv.get (3). Floatvalue (c);

sita=sita*math.pi/180;

Double T1=math.sqrt ((1-h) * (1-h) +r*r);

Double T2=math.sin (Math.atan ((1-h)/R) +sita);

Double D=t1*math.abs (T2);

Float p=double.valueof (d/(Math.sin (SITA) +math.cos (Sita)). Floatvalue ();

String str= "":

if (p>=0.0&&p<0.3)

Str= "Delayed Maintenance";

else if (p>=0.3&&p<0.55)

str= "Planned Maintenance";

else if (p>=0.55&&p<0.75)

Str= "plan priority Maintenance";

else if (p>=0.75&&p<0.85)

Str= "recent overhaul";

else if (p>=0.85&&p<1)

Str= "immediate overhaul";

return new Value (Str,ru. STRING);

}

}

3.3 Jess Call function Chxcalp The decision of realizing RCM grading maintenance strategy

The class name that implements the interface Userfunction is the function name of the chxcalp.class,jess call is Chxcalp, whose parameters are: function name, h value, R value, q value (q unit is angle). The Jess prompt loads and runs as shown in result 2. The test data are: Equipment h=0.2,r=0.4,q=45°, the decision result of grading maintenance strategy is plan priority Maintenance mode. As shown in load and run results 3 on the Eclipse platform, the test data is: Equipment h=0.8,r=0.4,q=45°, the decision result of the grading maintenance strategy is the Plan maintenance mode.

  

  

Conclusion

4

Through the Java language implementation of the Jess Userfunction interface, you can extend the Jess language function functions, which provides developers with an effective way to extend the functionality of Jess. This paper illustrates the effectiveness of this method based on the implementation of the decision function of the hierarchical maintenance strategy of RCM. Of course, Userfunction interface can be implemented more, Userfunction interface is no exception, different implementations correspond to different function functions, so that can greatly extend the function function of Jess, at this time, to load these functions to Jess, You can implement the Userpackage interface provided by Jess, and use the Engine.adduserfunction method in a Java class file to load multiple extended function functions into Jess at once.

published on Demand http://www.biyinjishi.com/products/a30-b3070/
Advertising show http://www.biyinjishi.com/products/a35/
Outdoor Inkjet http://www.biyinjishi.com/products/a35-b3510/
LED Display http://www.biyinjishi.com/products/a35-b3515/
Door Head http://www.biyinjishi.com/products/a35-b3515/
Lightbox http://www.biyinjishi.com/products/a35-b3515/
logo Wall http://www.biyinjishi.com/products/a35-b3520/
AD Word http://www.biyinjishi.com/products/a35-b3520/
signage http://www.biyinjishi.com/products/a35-b3530/
logo http://www.biyinjishi.com/products/a35-b3530/
Exhibition Package http://www.biyinjishi.com/products/a35-b3535/
Conference http://www.biyinjishi.com/products/a35-b3535/
Exhibition Frame Leasing http://www.biyinjishi.com/products/a35-b3550/
Exhibition Fixture http://www.biyinjishi.com/products/a35-b3550/
Banner http://www.biyinjishi.com/products/a35-b3560/
Bunting http://www.biyinjishi.com/products/a35-b3560/
Banner http://www.biyinjishi.com/products/a35-b3560/
Wall Sticker http://www.biyinjishi.com/products/a35-b3570/

The extension method of Jess function function based on Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.