How to use TextInput operator

sasss52
sasss52 New Altair Community Member
edited November 5 in Community Q&A
Hi,
I am running some test and I want to use TextInput operaotr in my code so can I read a bunch of text files(which is in a specific location) in order to do the textclassifiction. Can some one please  show how to use the TextInput operator in my code so I can read some text files and get the classification (I am new in programming).

My test code:===================================
import java.io.File;
import java.io.IOException;

import com.rapidminer.RapidMiner;
import com.rapidminer.example.Example;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.Model;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorChain;
import com.rapidminer.operator.OperatorCreationException;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.tools.OperatorService;

public class tect {

private OperatorChain wvtoolOperator;
private Operator modelApplier;
private Model model;

public tect(File modelFile, File wordListFile)
throws IOException, OperatorCreationException, OperatorException {

String path="C:\\Program Files\\Rapid-I\\RapidMiner-4.3\\";
System.setProperty("rapidminer.home",path );

//String pluginDirString = new File("rapidminer.home","C:\\Documents and Settings\\ssubpol\\Desktop\\WorkFile\\rapidminertest\\lib").getAbsolutePath();
  //  System.setProperty(RapidMiner.PROPERTY_RAPIDMINER_INIT_PLUGINS_LOCATION, pluginDirString);     
//String pluginDirString=new File ();
RapidMiner.init(false, false, false, true);

// Create the text input operator and set the path to the word list you stored using Rapid Miner
// As there is only a single text, we use the SingleTextInput operator
wvtoolOperator = (OperatorChain) OperatorService
.createOperator("SingleTextInput");
wvtoolOperator.setParameter("input_word_list", wordListFile
.getAbsolutePath());

// Add additional processing steps.
// Note the setup must be same as the one you used when creating the classification model
wvtoolOperator.addOperator(OperatorService.createOperator("StringTokenizer"));
wvtoolOperator.addOperator(OperatorService.createOperator("EnglishStopwordFilter"));
wvtoolOperator.addOperator(OperatorService.createOperator("TokenLengthFilter"));
wvtoolOperator.addOperator(OperatorService.createOperator("PorterStemmer"));

// Create the model applier
modelApplier = OperatorService.createOperator("ModelApplier");

// Load the model into a field of the class
Operator modelLoader = OperatorService.createOperator("ModelLoader");
modelLoader.setParameter("model_file", modelFile.getAbsolutePath());
IOContainer container = modelLoader.apply(new IOContainer());
model = container.get(Model.class);

}

public String apply(String text) throws OperatorException {

// Set the text
wvtoolOperator.setParameter("text", text);

// Call the text input operator
IOContainer container = wvtoolOperator.apply(new IOContainer(model));

// Call the model applier (the model was added already before calling the text input)
container = modelApplier.apply(container);

// Obtain the example set from the io container. It contains only a single example with our text in it.
ExampleSet eset = container.get(ExampleSet.class);
Example e = eset.iterator().next();

// Compare the predicted label with the positive label
return eset.getAttributes().getPredictedLabel().getMapping().mapIndex((int) e.getPredictedLabel());

}

public static void main(String args[]) throws Exception {

// Create a text classifier 
//System.setProperty("rapidminer.home", "C:\\Documents and Settings\\ssaha\\Desktop\\Workstation2\\rapidminertest\\data\\");

tect tr = new tect(
new File(
"C:\\Documents and Settings\\ssaha\\Desktop\\Workstation2\\rapidminertest\\data\\mod2.mod"),
new File(
"C:\\Documents and Settings\\ssaha\\Desktop\\Workstation2\\rapidminertest\\data\\wordlist.list"));

// Call the classifier with texts
System.out.println("Test1:" + tr.apply("sdjklfjasd'jgma'sd jd'sjf'sjk"));
System.out.println("Test2:" + tr.apply("workstation intel switch"));
System.out.println("Test3:" + tr.apply("workstation exploit cinninati"));


}

}

Please help me out, I am stuck!!!!!! help....
 

Answers

  • sasss52
    sasss52 New Altair Community Member
    hay.....can any one help me out in this par asap...I am stuck here....please give me some direction...
  • steffen
    steffen New Altair Community Member
    Hello sasss52

    I do not know much about text mining, but there are some things mixed up in your code, so I suggest...
    • Read the tutorial.pdf (also available at rapidminer's page at sourceforge), especially "Extending RapidMiner" and "Integrating RapidMiner in your application"
    • Restructure your code
    • ask again if you still got problems
    good night and good luck

    Steffen



  • p_thiru2002
    p_thiru2002 New Altair Community Member
    Hi All

    Please help me how to use Cluster operator in rapidminer?


    Thanks,


    Palani Thirumal Valavan
  • IngoRM
    IngoRM New Altair Community Member
    Hi,

    your post has nothing to do with the original question. Please open a new thread for a new problem - and more important: in the correct forum.

    Cheers,
    Ingo