Note that there are some explanatory texts on larger screens.

plurals
  1. POMerging Words into a Line
    primarykey
    data
    text
    <p>I am currently using Python v2.6 and trying to merge words into a line. My code supposed to read data from a text file, in which I have two rows of data both of which are strings. Then, it takes the second row data every time, which are the words of sentences, those are separated by delimiter strings, such that:</p> <p>Inside the .txt:</p> <pre><code>"delimiter_string" "row_1_data" "row_2_data" "row_1_data" "row_2_data" "row_1_data" "row_2_data" "row_1_data" "row_2_data" "row_1_data" "row_2_data" "delimiter_string" "row_1_data" "row_2_data" "row_1_data" "row_2_data" ... </code></pre> <p>Those "row_2_data" will add-up to a sentence later. Sorry for the long introduction btw.</p> <p>Here is my code:</p> <pre><code>import sys import re newLine = '' for line in sys.stdin: word = line.split(' ')[1] if word == '&lt;S&gt;+BSTag': continue elif word == '&lt;/S&gt;+ESTag': print newLine newLine = '' continue else: w = re.sub('\[.*?]', '', word) if newLine == '': newLine += w else: newLine += ' ' + w </code></pre> <p>"BSTag" is the tag for "Sentence Begins" and "ESTag" is for "Sentence Ends": the so called "delimiters". "re.sub" is used for a special purpose and it works as far as I checked. </p> <p>The problem is that, when I execute this python script from the command line in linux with the following command: $ cat file.txt | script.py | less, I can not see any output, but just a blank file.</p> <p>For those who are not familiar with linux, I guess the problem has nothing to do with terminal execution, thus you can neglect that part. Simply, the code does not work as intended and I can not find a single mistake.</p> <p>Any help will be appreciated, and thanks for reading the long post :)</p> <hr> <p>Ok, the problem is solved, which was actually a corpus error instead of a coding one. A very odd entry was detected in the text file, which was causing problems. Removing it solved it. You can use both of these approaches: mine and the one presented by "snurre" if you want a similar text processing.</p> <p>Cheers. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload