How to flatten a collection of ducument into a data file

subhasisdasgupt
subhasisdasgupt New Altair Community Member
edited November 5 in Community Q&A
I wanted to extract only a portion of documents using keep document part operator. Since this operator takes a single document at a time and then do the operation, I had to first filter the documents which contain the word "Battery" and then keep a portion of that document which is related mainly to battery inside the Loop Collection operator. I want the output to be a flat file (an excel or .csv) which contains only the output from Loop Collection operator and I am not in a position to do that. Document to data operator is also not solving the problem. I simply gives output in line with filter document operator. I am attaching the xml below. Any suggestion in solving this problem will be highly regarded.

Thanks in advance

Subhasis

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.015">
 <context>
   <input/>
   <output/>
   <macros/>
 </context>
 <operator activated="true" class="process" compatibility="5.3.015" expanded="true" name="Process">
   <process expanded="true">
     <operator activated="true" class="text:create_document" compatibility="5.3.002" expanded="true" height="60" name="Create Document" width="90" x="45" y="30">
       <parameter key="text" value="AFTER USING APPLE FOR MORE THAN 2 YEARS, I WAS HESISTANT TO SWITCH TO ANDROID, NO PHONE IN THE MARKET COULD TEMPT ME EXCEPT THIS ONE .&#10;"/>
     </operator>
     <operator activated="true" class="text:create_document" compatibility="5.3.002" expanded="true" height="60" name="Create Document (3)" width="90" x="45" y="120">
       <parameter key="text" value="DISPLAY IS FANTASTIC, CAMERA PERFORMANCE IS CLASS APART, MOTION SENSORS ARE AMAZING AND SMART ENOUGH, BATTERY LIFE IS REALLY REALLY GOOD .&#10;"/>
     </operator>
     <operator activated="true" class="text:create_document" compatibility="5.3.002" expanded="true" height="60" name="Create Document (4)" width="90" x="45" y="210">
       <parameter key="text" value="STYLISH.WITH FLIP COVER AND GOOD BATTERY BACKUP THEN THIS IS THE BEST PHONE .&#10;&#10;"/>
     </operator>
     <operator activated="true" class="collect" compatibility="5.3.015" expanded="true" height="112" name="Collect" width="90" x="313" y="30"/>
     <operator activated="true" class="flatten_collection" compatibility="5.3.015" expanded="true" height="60" name="Flatten Collection" width="90" x="447" y="30"/>
     <operator activated="true" class="text:filter_documents_by_content" compatibility="5.3.002" expanded="true" height="76" name="Filter Documents (by Content)" width="90" x="581" y="30">
       <parameter key="string" value="battery"/>
     </operator>
     <operator activated="true" class="loop_collection" compatibility="5.3.015" expanded="true" height="76" name="Loop Collection" width="90" x="715" y="30">
       <process expanded="true">
         <operator activated="true" class="text:keep_document_parts" compatibility="5.3.002" expanded="true" height="60" name="Keep Document Parts (3)" width="90" x="112" y="30">
           <parameter key="extraction_regex" value="[\sA-Z0-9]+(BATTERY)[\sA-Z0-9']+|[.,]?\s?(BATTERY)[,]?[\sA-Z0-9']+"/>
         </operator>
         <connect from_port="single" to_op="Keep Document Parts (3)" to_port="document"/>
         <connect from_op="Keep Document Parts (3)" from_port="document" to_port="output 1"/>
         <portSpacing port="source_single" spacing="0"/>
         <portSpacing port="sink_output 1" spacing="0"/>
         <portSpacing port="sink_output 2" spacing="0"/>
       </process>
     </operator>
     <connect from_op="Create Document" from_port="output" to_op="Collect" to_port="input 1"/>
     <connect from_op="Create Document (3)" from_port="output" to_op="Collect" to_port="input 2"/>
     <connect from_op="Create Document (4)" from_port="output" to_op="Collect" to_port="input 3"/>
     <connect from_op="Collect" from_port="collection" to_op="Flatten Collection" to_port="collection"/>
     <connect from_op="Flatten Collection" from_port="flat" to_op="Filter Documents (by Content)" to_port="documents 1"/>
     <connect from_op="Filter Documents (by Content)" from_port="documents" to_op="Loop Collection" to_port="collection"/>
     <connect from_op="Loop Collection" from_port="output 1" 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>
Tagged:

Answers

  • fras
    fras New Altair Community Member
    Hi,

    I introduced "appendData" together with "Documents to Data". Please take a look at the following process:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="6.0.002">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="6.0.002" expanded="true" name="Process">
        <process expanded="true">
          <operator activated="true" class="text:create_document" compatibility="5.3.002" expanded="true" height="60" name="Create Document" width="90" x="45" y="30">
            <parameter key="text" value="AFTER USING APPLE FOR MORE THAN 2 YEARS, I WAS HESISTANT TO SWITCH TO ANDROID, NO PHONE IN THE MARKET COULD TEMPT ME EXCEPT THIS ONE .&#10;"/>
          </operator>
          <operator activated="true" class="text:create_document" compatibility="5.3.002" expanded="true" height="60" name="Create Document (3)" width="90" x="45" y="120">
            <parameter key="text" value="DISPLAY IS FANTASTIC, CAMERA PERFORMANCE IS CLASS APART, MOTION SENSORS ARE AMAZING AND SMART ENOUGH, BATTERY LIFE IS REALLY REALLY GOOD .&#10;"/>
          </operator>
          <operator activated="true" class="text:create_document" compatibility="5.3.002" expanded="true" height="60" name="Create Document (4)" width="90" x="45" y="210">
            <parameter key="text" value="STYLISH.WITH FLIP COVER AND GOOD BATTERY BACKUP THEN THIS IS THE BEST PHONE .&#10;&#10;"/>
          </operator>
          <operator activated="true" class="collect" compatibility="6.0.002" expanded="true" height="112" name="Collect" width="90" x="246" y="30"/>
          <operator activated="true" class="loop_collection" compatibility="6.0.002" expanded="true" height="76" name="Loop Collection" width="90" x="246" y="165">
            <process expanded="true">
              <operator activated="true" class="text:keep_document_parts" compatibility="5.3.002" expanded="true" height="60" name="Keep Document Parts (3)" width="90" x="45" y="30">
                <parameter key="extraction_regex" value="[\sA-Z0-9]+(BATTERY)[\sA-Z0-9']+|[.,]?\s?(BATTERY)[,]?[\sA-Z0-9']+"/>
              </operator>
              <operator activated="true" class="text:documents_to_data" compatibility="5.3.002" expanded="true" height="76" name="Documents to Data" width="90" x="313" y="30">
                <parameter key="text_attribute" value="textOfDocument"/>
              </operator>
              <connect from_port="single" to_op="Keep Document Parts (3)" to_port="document"/>
              <connect from_op="Keep Document Parts (3)" from_port="document" 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_single" spacing="0"/>
              <portSpacing port="sink_output 1" spacing="0"/>
              <portSpacing port="sink_output 2" spacing="0"/>
            </process>
          </operator>
          <operator activated="true" class="append" compatibility="6.0.002" expanded="true" height="76" name="Append" width="90" x="45" y="345"/>
          <operator activated="true" class="text:process_document_from_data" compatibility="5.3.002" expanded="true" height="76" name="Process Documents from Data" width="90" x="246" y="345">
            <parameter key="vector_creation" value="Term Occurrences"/>
            <parameter key="keep_text" value="true"/>
            <list key="specify_weights"/>
            <process expanded="true">
              <operator activated="true" class="text:tokenize" compatibility="5.3.002" expanded="true" height="60" name="Tokenize" width="90" x="112" y="30"/>
              <operator activated="true" class="text:filter_documents_by_content" compatibility="5.3.002" expanded="true" height="76" name="Filter Documents (2)" width="90" x="246" y="30">
                <parameter key="string" value="battery"/>
              </operator>
              <connect from_port="document" to_op="Tokenize" to_port="document"/>
              <connect from_op="Tokenize" from_port="document" to_op="Filter Documents (2)" to_port="documents 1"/>
              <connect from_op="Filter Documents (2)" from_port="documents" 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="Collect" to_port="input 1"/>
          <connect from_op="Create Document (3)" from_port="output" to_op="Collect" to_port="input 2"/>
          <connect from_op="Create Document (4)" from_port="output" to_op="Collect" to_port="input 3"/>
          <connect from_op="Collect" from_port="collection" to_op="Loop Collection" to_port="collection"/>
          <connect from_op="Loop Collection" from_port="output 1" to_op="Append" to_port="example set 1"/>
          <connect from_op="Append" from_port="merged set" to_op="Process Documents from Data" to_port="example set"/>
          <connect from_op="Process Documents from Data" 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>