0

Currently, I am implementing a program in Java that uses a classifier to collect data. This done right now through the following lines of code:

SVMClassifier svm = new SVMClassifier(installDir, XAxisName);

double[] p = svm.predict(sent);

In the previous I specified the classifier that I am using. however, I want to implement this into some kind of abstract method so that the program will allow users to specify the classifier they want to use so they can run my program using any classifier.

I have a text file that the user specify the classifier they want to use and this is read into the program when it is ran and stores the name of the classifier into a variable called "classifier". what I am confused about is how I use a variable and use the contents of that as SVMClassifier from the previous example.

Any information or links to a way of being able to do this will be appreciated!

  • If there is only `predict()` method, then look into `FunctionalInterface`s. – M. Prokhorov Apr 05 '17 at 11:54
  • @M.Prokhorov I tried googling FunctionalInterfaces and can't really find any examples, would you be able to suggest some web pages for me to look at to understand this? – Rhys Copperthwaite Apr 07 '17 at 14:44
  • Functional interface is basically a normal Java interface which has only one abstract method. This concept in Java is sort of the extreme end of a Strategy pattern (which is what you are trying to do). Here's a [pretty good answer](http://stackoverflow.com/a/36882003/7470253) on this very site. Advantage of approach with functional interfaces is that if classifier can be expressed on one line of code, then your users will implement it using lambda notation. – M. Prokhorov Apr 07 '17 at 15:56

0 Answers0