Make pattern jsonl file from a text file

I have in a text file a list of expressions of interest, with every single expression on a single line.
Is there a simple way to convert this into a python file directly from the text file (other than doing it programmatically)? terms.to-patterns requires the existence of a dataset and does not take text files in directly.

1 Like

Hi! I do think writing a small script would be most efficient. If your code editor supports multi-line editing/cursors (like this in Visual Studio Code) you could also use that – or just add the same string to the start and end of each line, and save the result as JSONL.

Ultimately, you need to get from this:

hello
world

To this:

{"pattern": "hello", "label": "YOUR_LABEL"}
{"pattern": "world", "label": "YOUR_LABEL"}

The only difference are the pattern values – everything else is the same.

If your terms are all single words/tokens, you could import your text file to a new dataset with db-in (.txt file with one text per line is a valid input format) and then use terms.to-patterns to convert it. However, it does seem like a roundabout way to do it.