GSPoperastor - Java

student
student New Altair Community Member
edited November 5 in Community Q&A
Hello,

I would like to call gsp algorithm in java. I know, How this works in the rapidminer-gui.
Can you tell me how I can use the GSPOperator in java? I have a xml file like this passed through java to the gsp analysis. I seek a suitable example.


mfg

[on german:

ich möchte die gsp analyse in java aufrufen. in der rapidminer gui geht dies bereits. gibt es irgendwo ein beispiel, dass mir zeigt, wie ich eine xml oder csv datei in java einlesen und passend an die gsp analyse übergeben kann?]

Answers

  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    please have a look at this sticky: here. I suggest building the process in RapidMiner and then programatically change input and parameters.

    Regards,
    Marco
  • student
    student New Altair Community Member
    Hello,

    thanks for the answer.

    This is my code:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.2.008">
     <context>
       <input/>
       <output/>
       <macros/>
     </context>
     <operator activated="true" class="process" compatibility="5.2.008" expanded="true" name="Process">
       <process expanded="true" height="-20" width="-50">
         <operator activated="true" class="read_excel" compatibility="5.2.008" expanded="true" height="60" name="Read Excel" width="90" x="42" y="49">
           <parameter key="excel_file" value="C:\Users\name\Desktop\testF.xls"/>
           <list key="annotations"/>
           <list key="data_set_meta_data_information"/>
         </operator>
         <operator activated="true" class="numerical_to_binominal" compatibility="5.2.008" expanded="true" height="76" name="Numerical to Binominal" width="90" x="94" y="207">
           <parameter key="attribute_filter_type" value="subset"/>
           <parameter key="attributes" value="id|prod.A|prod.B|prod.C|"/>
         </operator>
         <operator activated="true" class="generalized_sequential_patterns" compatibility="5.2.008" expanded="true" height="76" name="GSP" width="90" x="313" y="82">
           <parameter key="customer_id" value="id"/>
           <parameter key="time_attribute" value="time"/>
           <parameter key="window_size" value="12.0"/>
           <parameter key="max_gap" value="3.0"/>
           <parameter key="min_gap" value="1.0"/>
           <parameter key="positive_value" value="true"/>
         </operator>
         <connect from_op="Read Excel" from_port="output" to_op="Numerical to Binominal" to_port="example set input"/>
         <connect from_op="Numerical to Binominal" from_port="example set output" to_op="GSP" to_port="example set"/>
         <connect from_op="GSP" from_port="patterns" to_port="result 1"/>
         <portSpacing port="source_input 1" spacing="0"/>
         <portSpacing port="sink_result 1" spacing="0"/>
         <portSpacing port="sink_result 2" spacing="0"/>
       </process>
     </operator>
    </process>


    How I can put this code in java? Rapidminer is already involved with me in eclipse.

    On German:
    [Wie kann diese diesen Code in Java, als Klasse, umsetzen? Ich habe dazu keine passenden Beispiele gefunden (die Beispiele die es gibt, funktionieren nicht, weil mir immer etwas fehlt - z.b. testfiles etc.). rapidminer habe ich bereits in eclipse eingebunden.]
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    everything should be explained in the link I provided, have  a close look at items 1) 4) 5) and 6).
    Just add RapidMiner as a library to your own project and go from there.

    Regards,
    Marco
  • student
    student New Altair Community Member
    Hi,

    mein Code:

    public static void main(String args[]) throws Exception { 
        RapidMiner.setExecutionMode(com.rapidminer.RapidMiner.ExecutionMode.COMMAND_LINE);
        RapidMiner.init();
        RepositoryLocation pLoc = new RepositoryLocation("C:/Users/VMuser/.RapidMiner5/repositories/Local Repository/processes/SequenzAna");
        ProcessEntry pEntry = (ProcessEntry) pLoc.locateEntry();
        String processXML = pEntry.retrieveXML();
        Process myProcess = new Process(processXML);
       
        RepositoryLocation loc = new RepositoryLocation("C:/Users/VMuser/Desktop/Mappe1.xlsx");
        IOObjectEntry entry = (IOObjectEntry) loc.locateEntry();
        IOObject myIOObject = entry.retrieveData(null);
       
        // execute the process and get the resulting objects
        IOContainer ioInput = new IOContainer(new IOObject[] {myIOObject});
        // just use myProcess.run() if you don't use the input ports for your process
        IOContainer ioResult = myProcess.run(ioInput);

        // use the result(s) as needed, for example if your process just returns one ExampleSet, use this:
        if (ioResult.getElementAt(0) instanceof ExampleSet) {
            ExampleSet resultSet = (ExampleSet)ioResult.getElementAt(0);
        }
        }



    My Ecxeption:


    Apr 15, 2013 4:05:24 PM com.rapid_i.Launcher ensureRapidMinerHomeSet
    INFO: Property rapidminer.home is not set. Guessing.
    Apr 15, 2013 4:05:24 PM com.rapid_i.Launcher ensureRapidMinerHomeSet
    INFO: Trying base directory of classes (build) 'C:\Users\VMuser\workspace\RapidMiner_Vega'...gotcha!
    Apr 15, 2013 4:05:24 PM com.rapidminer.tools.ParameterService init
    INFO: Reading configuration resource com/rapidminer/resources/rapidminerrc.
    Apr 15, 2013 4:05:24 PM com.rapidminer.tools.plugin.Plugin registerAllPluginDescriptions
    WARNING: Cannot register operators from 'Weka': Dependencies not fulfilled! This plugin needs a RapidMiner version 5.2 and the following plugins:
    []
    Apr 15, 2013 4:05:26 PM com.rapidminer.parameter.ParameterTypePassword decryptPassword
    WARNING: Password in XML file looks like unencrypted plain text.
    Apr 15, 2013 4:05:26 PM com.rapidminer.tools.jdbc.JDBCProperties <init>
    WARNING: Missing database driver class name for 'ODBC Bridge (e.g. Access)'
    Apr 15, 2013 4:05:26 PM com.rapidminer.tools.jdbc.JDBCProperties registerDrivers
    INFO: JDBC driver ca.ingres.jdbc.IngresDriver not found. Probably the driver is not installed.
    Apr 15, 2013 4:05:26 PM com.rapidminer.tools.jdbc.JDBCProperties registerDrivers
    INFO: JDBC driver oracle.jdbc.driver.OracleDriver not found. Probably the driver is not installed.
    Apr 15, 2013 4:05:27 PM com.rapidminer.repository.local.LocalRepository <init>
    WARNING: Failed to create repository directory: com.rapidminer.repository.RepositoryException: Cannot create repository folder at 'C:\Users\fujitsu\.RapidMiner5\repositories\Local Repository'.
    com.rapidminer.repository.RepositoryException: Cannot create repository folder at 'C:\Users\fujitsu\.RapidMiner5\repositories\Local Repository'.
    at com.rapidminer.repository.local.SimpleFolder.mkdir(SimpleFolder.java:67)
    at com.rapidminer.repository.local.LocalRepository.<init>(LocalRepository.java:64)
    at com.rapidminer.repository.local.LocalRepository.fromXML(LocalRepository.java:170)
    at com.rapidminer.repository.RepositoryManager.load(RepositoryManager.java:229)
    at com.rapidminer.repository.RepositoryManager.<init>(RepositoryManager.java:131)
    at com.rapidminer.repository.RepositoryManager.init(RepositoryManager.java:136)
    at com.rapidminer.RapidMiner.init(RapidMiner.java:477)
    at rapid.main(rapid.java:47)

    Apr 15, 2013 4:05:27 PM com.rapidminer.repository.local.LocalRepository <init>
    WARNING: Failed to create repository directory: com.rapidminer.repository.RepositoryException: Cannot create repository folder at 'C:\Users\fujitsu\.RapidMiner5\repositories\Local Repository'.
    com.rapidminer.repository.RepositoryException: Cannot create repository folder at 'C:\Users\fujitsu\.RapidMiner5\repositories\Local Repository'.
    at com.rapidminer.repository.local.SimpleFolder.mkdir(SimpleFolder.java:67)
    at com.rapidminer.repository.local.LocalRepository.<init>(LocalRepository.java:64)
    at com.rapidminer.repository.local.LocalRepository.fromXML(LocalRepository.java:170)
    at com.rapidminer.repository.RepositoryManager.load(RepositoryManager.java:229)
    at com.rapidminer.repository.RepositoryManager.<init>(RepositoryManager.java:131)
    at com.rapidminer.repository.RepositoryManager.init(RepositoryManager.java:136)
    at com.rapidminer.RapidMiner.init(RapidMiner.java:477)
    at rapid.main(rapid.java:47)

    Exception in thread "main" com.rapidminer.repository.MalformedRepositoryLocationException: No absolute path: C:/Users/VMuser/.RapidMiner5/repositories/Local Repository/processes/SequenzAna
    at com.rapidminer.repository.RepositoryLocation.initializeAbsolutePath(RepositoryLocation.java:116)
    at com.rapidminer.repository.RepositoryLocation.<init>(RepositoryLocation.java:55)
    at rapid.main(rapid.java:48)


    ??? ??? ???
  • student
    student New Altair Community Member
    Can you tell me where my mistake is?

    (ich wei´garnicht wo "C:\Users\fujitsu\.RapidMiner5\repositories\Local Repository" herkommt... "fujitsu" habe ich definitiv nie eingegeben, irgendwie besteht mein Problem darin, dass ich nicht weiß, wie ich meine Daten in Java übergebe, das Modell scheint ja soweit geladen zu werden)
  • student
    student New Altair Community Member
    RapidMiner.setExecutionMode(com.rapidminer.RapidMiner.ExecutionMode.COMMAND_LINE);
        RapidMiner.init();
       
       
        Process myProcess = new Process(new File("resources/SequenzAna.rmp"));
       
        RepositoryLocation loc = new RepositoryLocation("resources/Mappe1.xlsx");


    =>
    Exception in thread "main" com.rapidminer.repository.MalformedRepositoryLocationException: No absolute path: resources/Mappe1.xlsx
    at com.rapidminer.repository.RepositoryLocation.initializeAbsolutePath(RepositoryLocation.java:116)
    at com.rapidminer.repository.RepositoryLocation.<init>(RepositoryLocation.java:55)
    at rapid.main(rapid.java:56)


    what is wrong?
  • student
    student New Altair Community Member
    RapidMiner.setExecutionMode(com.rapidminer.RapidMiner.ExecutionMode.COMMAND_LINE);
        RapidMiner.init();
        Process myProcess = new Process(new File("resources/SequenzAna.rmp"));
        myProcess.run();


    exception:

    Exception in thread "main" com.rapidminer.operator.UserError: Could not read file 'C:\Users\VMuser\Desktop\Mappe1.xlsx': Unable to recognize OLE stream.
    at com.rapidminer.operator.nio.model.ExcelResultSet.<init>(ExcelResultSet.java:99)
    at com.rapidminer.operator.nio.model.ExcelResultSetConfiguration.makeDataResultSet(ExcelResultSetConfiguration.java:217)
    at com.rapidminer.operator.nio.model.AbstractDataResultSetReader.createExampleSet(AbstractDataResultSetReader.java:124)
    at com.rapidminer.operator.io.AbstractExampleSource.read(AbstractExampleSource.java:52)
    at com.rapidminer.operator.io.AbstractExampleSource.read(AbstractExampleSource.java:1)
    at com.rapidminer.operator.io.AbstractReader.doWork(AbstractReader.java:123)
    at com.rapidminer.operator.Operator.execute(Operator.java:833)
    at com.rapidminer.operator.execution.SimpleUnitExecutor.execute(SimpleUnitExecutor.java:51)
    at com.rapidminer.operator.ExecutionUnit.execute(ExecutionUnit.java:709)
    at com.rapidminer.operator.OperatorChain.doWork(OperatorChain.java:379)
    at com.rapidminer.operator.Operator.execute(Operator.java:833)
    at com.rapidminer.Process.run(Process.java:925)
    at com.rapidminer.Process.run(Process.java:848)
    at com.rapidminer.Process.run(Process.java:807)
    at com.rapidminer.Process.run(Process.java:802)
    at com.rapidminer.Process.run(Process.java:792)
    at rapid.main(rapid.java:56)



    What is a OLE stream?


  • student
    student New Altair Community Member
    it works with csv  :)

    "IOContainer (1 objects):
    Set of generalized sequential patterns
    Set contains 4 patterns.
    (created by GSP)"

    how can I print the pattern?


    i have:

    IOContainer ioResult= myProcess.run();
        System.out.println(ioResult.toString());
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    please post everything in english so everyone else can understand your questions and the possible answers :)

    1) RepositoryLocation is a location in a repository like you work on in RapidMiner GUI. You can't just pass a filesystem or a resources file into a RepositoryLocation, it won't work as you have noticed. However you can load your process like this

    Process myProcess = new Process(new File("C:\\path\\to\\your\\file\\processName.rmp"));
    Most operators which load data however do work on the filesystem, e.g. Read Excel

    2) You are trying to load an .xlsx (Excel 2007+) with the .xls (Excel before 2007) engine. However the line numbers in the error are way off to what I have here so I think you are not using the latest version of the source files - see here for the current SVN location. I can't help you with an outdated version of the source files I'm afraid.

    3) You can take the n-th (the port where the pattern output of the GSP operator is going to; probably first in your case) IOObject from the IOContainer, cast it to GSPSet and call #toResultString() on it.

    Regards,
    Marco
  • student
    student New Altair Community Member
    Thanks, its works!