I would like to delete all hyphens in the text document which I analyze in Rapidminer. For that I use operator "Process documents from files" to analyze large PDF-files. Each file contains a lot of hyphens which I would like to delete before I'll tokenize the text into pieces (non letters). I've used operator "Replace token". With it I can replace hyphens with other symbols, but I cannot replace them with nothing or empty string(" "). I've tried also to use my own customized dictionary of stopwords(non-letters, -). This operator does no work at all. I've saved my dictionary containing the chars and words I want to delete as a text file (each in the new line). Can anybody help on this issue?
You can use Replace Tokens
with the following parameters.
replace what
()[-]
replace by
$1
It's a bit of a hack but it works because the first capturing group between the brackets will always be empty and the whole regular expression will match a single hyphen. The $1
is the result of the first capture group and it's always empty.
Here's an example process that shows this working.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="7.0.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.0.000" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="text:create_document" compatibility="7.0.000" expanded="true" height="68" name="Create Document" width="90" x="246" y="187">
<parameter key="text" value="some text with some-text-with-hyphens-in hyphens in "/>
</operator>
<operator activated="true" class="text:replace_tokens" compatibility="7.0.000" expanded="true" height="68" name="Replace Tokens" width="90" x="447" y="187">
<list key="replace_dictionary">
<parameter key="()[-]" value="$1"/>
</list>
</operator>
<operator activated="true" class="text:process_documents" compatibility="7.0.000" expanded="true" height="103" name="Process Documents" width="90" x="648" y="187">
<parameter key="vector_creation" value="Term Occurrences"/>
<process expanded="true">
<operator activated="true" class="text:tokenize" compatibility="7.0.000" expanded="true" height="68" name="Tokenize" width="90" x="179" y="85"/>
<connect from_port="document" to_op="Tokenize" to_port="document"/>
<connect from_op="Tokenize" from_port="document" to_port="document 1"/>
<portSpacing port="source_document" spacing="0"/>
<portSpacing port="sink_document 1" spacing="0"/>
<portSpacing port="sink_document 2" spacing="0"/>
</process>
</operator>
<connect from_op="Create Document" from_port="output" to_op="Replace Tokens" to_port="document"/>
<connect from_op="Replace Tokens" from_port="document" to_op="Process Documents" to_port="documents 1"/>
<connect from_op="Process Documents" from_port="example 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>
Hope that helps as a basis.