Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How are characters like tab and new line handled? #105

Closed
dclong opened this issue Dec 30, 2017 · 4 comments
Closed

How are characters like tab and new line handled? #105

dclong opened this issue Dec 30, 2017 · 4 comments
Labels

Comments

@dclong
Copy link

dclong commented Dec 30, 2017

When converting a CSV file to TSV? I assume there are either default alternative characters or users have to specify alternative filed/line delimiters?

@jondegenhardt
Copy link
Contributor

By default, TAB and newline characters are replaced a space. A different replacement string can be specified using the --r|replacement option.

These details can be found in the csv2tsv reference, or by using the --help-verbose option.

@dclong
Copy link
Author

dclong commented Jan 1, 2018

But doesn't this change the original data? Tabs and newlines might special means in the original CSV files.

Generally speaking, are there field delimiters and line delimiters that are safe to use in most situations? That is people seldom use them in text and no escape is required for them.

@jondegenhardt
Copy link
Contributor

jondegenhardt commented Jan 1, 2018

TSV file format uses TABs and newlines as delimiters precisely because these characters are not part of the data in the vast majority of large data sets. It's certainly true of most data mining scenarios. The reason csv2tsv defaults to spaces as the replacement character is that it tends to be a reasonable choice when working with NLP data sets.

Of course, TAB and newline may carry meaning in some data sets. Most software tools support alternate field delimiters, so something other than TAB can be chosen. Very few tools support alternate record (line) delimiters. If newlines need to be preserved in the data set being used, then it's better to use a file format that supports full character escaping.

Using TSV is a tradeoff. The lack of escapes results in much simpler and less error prone processing, and can run faster as well. However, it is not the best format for every use case.

To your more general question: ASCII does define control characters intended for these purposes, CTRL-~ and CTRL-_ (decimal 30 and 31, Hex 1E and 1F) for record separator and field separator. However, these never got much support. However, you use one of these in place of TAB for field delimiter.

There is related discussion in the Comparing TSV and CSV formats page in this repository.

The wikipedia article on Tab-separated values has more info on TSV file format.

Update: In Release 2.1.0 csv2tsv supports options to specify separate replacement strings for TABs and newlines found in CSV data fields. This allows selection of characters that can used to preserve the meaning of TAB and newline characters. There are several unicode characters that can be used for this purpose, including U+2028 (Line Separator), U+2029 (Paragraph Separator), U+2424 (␤, Visual Newline), U+2409 (␉, Visual TAB). Whether this is approach is applicable depends on the specific task. See PR #303 for details.

@jondegenhardt
Copy link
Contributor

Been 13 days, assuming the answer is sufficient and closing. Please add addition comments if further discussion would benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants