TQL - TextQueryLanguage


About

TQL is a query language designed for flat text.


Getting started

1) Download the TQL.jar File.

2) Klick on the file to run TQL in GUI Mode or type java -jar TQL.jar console to run TQL in the terminal.

3) Create a new TQL File using the CREATE command. Easiest Usage: CREATE example CHOOSER

4) Select the file with USE example


System Commands

CREATE:

Used to load data or create text sources.

Syntax: CREATE <name> <mode> <args>

 

Possible usages:

 

CREATE example FILE /path/to/file.txt -> Loads a file.

CREATE example CHOOSER -> Shows a file chooser dialog to select a file and load it.

CREATE example URL http://example.com/file.txt -> Loads a file from the web-

CREATE example EMPTY -> Creates a empty text source.

CREATE example INPUT Example Text! -> Creates a text source with the given content.

 

Returns: The name of the created source.

 

USE:

Sets the main text source to use. You can use multiple sources using the (WITH) command.

 

Possible usages:

USE example -> Selects the given source.

 

Returns: The name of the selected source.

 

 

DELETE:

Deletes a text source. Delete large loaded sources to get more memory.

 

Possible usages:

DELETE example -> Deletes the given source

 

Returns: The name of the deleted source.

 

 

REFRESH:

Refreshes the current text source. This works only if the source is loaded from file or url.

 

Possible usages:

REFRESH

 

Returns: The name of the source.

 

 

LIST:

Lists all existing sources and shows the one that is selected.

 

Possible usages:

LIST

 

Returns: A formatted list with all source names.

 

 

 

 

 

Language commands

GET:

Used to get content from a source.

 

Possible usages:

 

(GET) -> The same as (GET LINE). Returns the whole source text.

(GET LINE) -> Returns all lines.

(GET LINE <condition>) -> Returns all lines that match a given condition.

(GET WORD) -> Returns all words.

(GET WORD <condition>) -> Returns all words that match a condition.

(GET CHAR) -> Returns all characters.

(GET CHAR <condition>) -> Returns all characters that match a condition.

 

 

DISTINCT:

Used to remove double results.

 

Possible usages:

(DISTINCT <command>)

 

Example (Get all different words from the source):

(DISTINCT (GET WORD))

 

 

COUNT:

Returns the number of returned results.

 

Possible usages:

(COUNT <command>)

 

Example (Count characters in the source):

(COUNT (GET CHAR))

 

 

INDEX:

Returns the result with the given index.

 

Possible usages:

(INDEX <index>|<command>) -> Gets the result with a static index.

(INDEX <index-command>|<main-command>) -> Gets the index from a command result.

 

Example (Returns the fifth word from the source):

(INDEX 4|(GET WORD))

 

 

SILENT:

Runs a command without returning the results.

 

Possible usages:

(SILENT <command>) 

 

KEYS:

Lists all yaml keys that can be used to get a property.

 

Possible usages:

(KEYS)

 

 

LINE:

Used to change the text source.

 

Possible usages:

(LINE ALL <Text or command>) -> Sets the whole text to the given content.

(LINE END <Text or command>) -> Appends the given text at the end.

 

 

SOURCE:

Used to use a other source than the selected one for the sub-commands.

 

Possible usages:

(SOURCE <source>|<command>) -> Execute the command with the given source.

(SOURCE <name-command>|<command>) -> Executes the command to receive the source name.

 

Example (Get a property with the key name from another file):

(PROPERTY (SOURCE keydata|(PROPERTY example-key)))

 

 

WITH:

Uses a text or a return value as source for the sub-commands.

 

Possible usages:

(WITH <text>|<command>) -> Executes the command on the given text.

(WITH <text-command>|<command>) -> Additionally executes a command to receives the source text.

 

Example (Get all characters of "Hello world"):

(WITH Hello world|(GET WORD)

 

 

 

 

 

 

Calculation commands:

 

(+ <command1>|<command2>)

(- <command1>|command2>)

(* <command1>|<command2>)

(/ <command1>|<command2>)

 

Text utility commands:

 

(SPACE) -> Returns a space character.

(SPACE <amount>) -> Returns the given amount of space characters.

 

 

Syntax

- All commands have to be written in upper case.

- Language commands are surrounded with ( and ).

- Multiple command can be combined to one string with < and >

- Run multiple command in one line with splitting them with semicolons.

 

- Use {nl} for multiple lines. Example:

Hello!{nl}Are you all right?

->

Hello!

Are you all right?

 

Examples:

Get all lines that contain "hello" or "hi":

(GET LINE CONTAINS:hallo,CONTAINS:hi)

 

Count how often the text contains "hello":

(COUNT (GET WORD MATCH:hello))

 

Count how many different characters the text contains:

(COUNT (DISTINCT (GET CHAR)))