RapidMiner

RM Partner
RM Partner

Reading multiples text files from a folder and converting them to an exampleset ?

I have a folder that contains multiple text files. So how can we read the content of each file and use them as a row in the exampleset.

 

for ex : 

for a folder with 5 text files the exampleset will look like.

| Row |    TextContent    |

-------  | ---------------------

1        | contents of fille1

2        | contents of fille2

3        | contents of fille3

4        | contents of fille4

5        | contents of fille5

3 REPLIES
Highlighted
Guru
Guru

Re: Reading multiples text files from a folder and converting them to an exampleset ?

If you have the Text Processing extension you could do as follows :

 

Loop files operator -> inside the operator use fil -> read Document -> Documents to Data -> out  -> Append operator 

 

Something like this :

 

<?xml version="1.0" encoding="UTF-8"?><process version="7.5.001">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.5.001" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="concurrency:loop_files" compatibility="7.5.001" expanded="true" height="82" name="Loop Files" width="90" x="112" y="34">
<parameter key="directory" value="myDirectory"/>
<parameter key="recursive" value="true"/>
<parameter key="enable_parallel_execution" value="false"/>
<process expanded="true">
<operator activated="true" class="text:read_document" compatibility="7.5.000" expanded="true" height="68" name="Read Document" width="90" x="112" y="34"/>
<operator activated="true" class="text:documents_to_data" compatibility="7.5.000" expanded="true" height="82" name="Documents to Data" width="90" x="246" y="34">
<parameter key="text_attribute" value="mytext"/>
</operator>
<connect from_port="file object" to_op="Read Document" to_port="file"/>
<connect from_op="Read Document" from_port="output" to_op="Documents to Data" to_port="documents 1"/>
<connect from_op="Documents to Data" from_port="example set" to_port="output 1"/>
<portSpacing port="source_file object" spacing="0"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_output 1" spacing="0"/>
<portSpacing port="sink_output 2" spacing="0"/>
</process>
</operator>
<operator activated="true" class="append" compatibility="7.5.001" expanded="true" height="82" name="Append" width="90" x="246" y="34"/>
<connect from_op="Loop Files" from_port="output 1" to_op="Append" to_port="example set 1"/>
<connect from_op="Append" from_port="merged set" 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>

 

RM Partner
RM Partner

Re: Reading multiples text files from a folder and converting them to an exampleset ?

This technique works but it picks up the first line of all documents instead of the complete content.

RM Certified Expert
RM Certified Expert

Re: Reading multiples text files from a folder and converting them to an exampleset ?

You would use the Loop Files operator with a Read CSV (set to read any file) and Store operator inside. 

Polls
How can RapidMiner increase participation in our new competitions?
Twitter Feed