Menu

Installation and Building

Robin Hillyard

Installation, Building and Demonstration

In theory, building FuzzyJ via maven should be quite straightforward. Of course, things never quite work out that easily.

There are four modules enclosed within the "fuzzyj-project" maven project. These are:

  • fuzzyj-core
  • fuzzyj-arithmetic
  • fuzzyj-arithmetic-core
  • fuzzyj-number
  • fuzzyj-javaparser
  • fuzzyj-jep

The first four of these should build quite easily. Fuzzyj-core includes the core classes for FuzzyJ. Fuzzyj-arithmetic-core defines an interface for arithmetic operations used by the parser and number modules. Fuzzyj-arithmetic provides some numeric classes which are not absolutely required for the the project as a whole. See [Generic types] for more information about these types.

Fuzzyj-number builds upon the core classes, but limiting the bounds of the generic type for Fuzzy<x></x> to extenders of Number. The Fuzzyj-number module contains the bulk of the code. Fuzzyj-javaparser is really just an example expression parser that will parse expressions, creating fuzzy objects for each result. Don't look for any great degree of sophistication here -- it's really just a toy at present.

There is a Demo class containing a main program which will exercise the expression parser from a file in the resources directory (see the source code for details).

The third module, fuzzyj-jep uses a much more solid and sophisticated expression parser, JEP, from Singular systems. However, JEP is not open-source-licensed. If you want to use it, then acquire a license (http://www.singularsys.com/jep/) and follow the steps outlined in the lib/README.txt file. Otherwise, take the fuzzy-jep module out of the parent POM and just build without it.

Note that you will need Java 1.8 because FuzzyJ is essentially a functionally-oriented framework.

If you are only interested in using Double or BigDecimal for the generic type, you won't need to build or reference fuzzyj-arithmetic although fuzzy-arithmetic-core is required.

Running the Demo program

There is a demonstration program provided as part of the fuzzyj-javaparser module (there's a slightly different one for the JEP module too). The name of the main class is:

net.sf.fuzzyj.javaparser.Demo

This takes zero, one or two command-line arguments:

  • arg1 (if present): the name of a text file (from the resource tree, in the same package as the main program) which defaults to "test.txt"
  • arg2 (if both present): the class name of the expression parser to be used and which defaults to: "net.sf.fuzzyj.javaparser.ExpressionParser_JavaParser_Double"

If you run the demo with no arguments, you should see the following output:

1+1: 2.0000000000000000(100)
3.14*2: 6.280(10)
r = 3: null
r^2: 9.00000000000000(45)
pi*r * r: 28.2743338823081(11)
pi*(r^2): 28.2743338823081(20)

If you run it with the first argument set to test1.txt, you should see the following output:

sin(pi): ~0
cos(pi): -1.00000000000000(10)
tan(pi/4): 1.00000000000000(41)
exp(1): 2.71828182845905(27)
sqrt(16): 4.00000000000000(20)
pow(10,5): 100000.0000000000(50)

Setting the second argument to specify the FuzzyGeneric form of the expression parser (i.e. net.sf.fuzzyj.javaparser.ExpressionParser_JavaParser_Generic) we get the following output (the same except for the last two):

sqrt(16): 4
pow(10,5): 100000

Similarly, if you run the generic parser on the default test file, the first and fourth results will be exact numbers rather than inexact (2 and 9 respectively).


Related

Wiki: Generic types
Wiki: Home