SkillAgentSearch skills...

SoMaJo

A tokenizer and sentence splitter for German and English web and social media texts.

Install / Use

/learn @tsproisl/SoMaJo
About this skill

Quality Score

0/100

Category

Marketing

Supported Platforms

Universal

README

SoMaJo

PyPI Build

Introduction

echo 'Wow, superTool!;)' | somajo-tokenizer -c -
Wow
,
super
Tool
!
;)

SoMaJo is a rule-based tokenizer and sentence splitter that implements tokenization guidelines for German and English. It has a strong focus on web and social media texts (it was originally created as the winning submission to the EmpiriST 2015 shared task on automatic linguistic annotation of computer-mediated communication / social media) and is particularly well-suited to perform tokenization on all kinds of written discourse, for example chats, forums, wiki talk pages, tweets, blog comments, social networks, SMS and WhatsApp dialogues. Of course it also works on more formal texts.

Version 1 of the tokenizer is described in greater detail in Proisl and Uhrig (2016).

For part-of-speech tagging (in particular of German web and social media texts), we recommend SoMeWeTa:

somajo-tokenizer --split_sentences <file> | somewe-tagger --tag <model> -

Features

  • Rule-based tokenization and sentence-splitting:
    • EmpiriST 2015 tokenization guidelines for German
    • “New” Penn Treebank conventions for English (described, for example, in the guidelines for ETTB 2.0 (Mott et al., 2009) and CLEAR (Warner et al., 2012))
    • Optionally split camel-cased tokens
    • Optionally output token class information for each token, i.e. if it is a number, an emoticon, an abbreviation, etc.
    • Optionally output additional information for each token, e.g. if it was followed by whitespace or if it contained internal whitespace
    • Optionally split the tokenized text into sentences
    • Optionally determine the character offsets of the tokens in the input, allowing for stand-off tokenization
  • Text preprocessing/cleaning:
  • XML support:
    • Transparent processing of XML: Tokenize the textual content of an XML file while preserving the XML structure
    • Optionally delimit sentence boundaries by XML tags
    • Optionally prune tags, i.e. subtrees, from the XML before tokenization (for example to remove <script> and <style> tags from HTML input)
    • Optionally strip all tags from the output, effectively turning the XML into plain text
  • Parallelization: Optionally run multiple worker processes to speed up tokenization

Installation

SoMaJo can be easily installed using pip (pip3 in some distributions):

pip install -U SoMaJo

Alternatively, you can download and decompress the latest release or clone the git repository:

git clone https://github.com/tsproisl/SoMaJo.git

In the new directory, run the following command:

pip install -U .

Usage

Using the somajo-tokenizer executable

You can use the tokenizer as a standalone program from the command line. General usage information is available via the -h option:

somajo-tokenizer -h
usage: somajo-tokenizer [-h] [-l {en_PTB,de_CMC}]
                        [-s {single_newlines,empty_lines}] [-x] [--tag TAG]
                        [--prune PRUNE] [--strip-tags] [-c]
                        [--split_sentences] [--sentence_tag SENTENCE_TAG] [-t]
                        [-e] [--parallel N] [-v]
                        FILE

A tokenizer and sentence splitter for German and English texts. Currently, two
tokenization guidelines are implemented: The EmpiriST guidelines for German
web and social media texts (de_CMC) and the "new" Penn Treebank conventions
for English texts (en_PTB).

positional arguments:
  FILE                  The input file (UTF-8-encoded) or "-" to read from
                        STDIN.

options:
  -h, --help            show this help message and exit
  -l {en_PTB,de_CMC}, --language {en_PTB,de_CMC}
                        Choose a language. Currently supported are German
                        EmpiriST-style tokenization (de_CMC) and English Penn-
                        Treebank-style tokenization(en_PTB). (Default: de_CMC)
  -s {single_newlines,empty_lines}, --paragraph_separator {single_newlines,empty_lines}
                        How are paragraphs separated in the input text? Will
                        be ignored if option -x/--xml is used. (Default:
                        empty_lines)
  -x, --xml             The input is an XML file. You can specify tags that
                        always constitute a sentence break (e.g. HTML p tags)
                        via the --tag option.
  --tag TAG             Start and end tags of this type constitute sentence
                        breaks, i.e. they do not occur in the middle of a
                        sentence. Can be used multiple times to specify
                        multiple tags, e.g. --tag p --tag br. Implies option
                        -x/--xml. (Default: --tag title --tag h1 --tag h2
                        --tag h3 --tag h4 --tag h5 --tag h6 --tag p --tag br
                        --tag hr --tag div --tag ol --tag ul --tag dl --tag
                        table)
  --prune PRUNE         Tags of this type will be removed from the input
                        before tokenization. Can be used multiple times to
                        specify multiple tags, e.g. --tag script --tag style.
                        Implies option -x/--xml. By default, no tags are
                        pruned.
  --strip-tags          Suppresses output of XML tags. Implies option
                        -x/--xml.
  -c, --split_camel_case
                        Split items in written in camelCase (excluding
                        established names and terms).
  --split_sentences, --split-sentences
                        Also split the input into sentences.
  --sentence_tag SENTENCE_TAG, --sentence-tag SENTENCE_TAG
                        Tag name for sentence boundaries (e.g. --sentence_tag
                        s). If this option is specified, sentences will be
                        delimited by XML tags (e.g. <s>…</s>) instead of empty
                        lines. This option implies --split_sentences
  -t, --token_classes   Output the token classes (number, XML tag,
                        abbreviation, etc.) in addition to the tokens.
  -e, --extra_info      Output additional information for each token:
                        SpaceAfter=No if the token was not followed by a space
                        and OriginalSpelling="…" if the token contained
                        whitespace.
  --character-offsets   Output character offsets in the input for each token.
  --parallel N          Run N worker processes (up to the number of CPUs) to
                        speed up tokenization.
  -v, --version         Output version information and exit.

Here are some common use cases:

  • To tokenize a text file according to the guidelines of the EmpiriST 2015 shared task:

    somajo-tokenizer -c <file>
    
    <details><summary>Show example</summary>
    echo 'der beste Betreuer? - >ProfSmith! : )' | somajo-tokenizer -c -
    der
    beste
    Betreuer
    ?
    ->
    Prof
    Smith
    !
    :)
    
    </details>
  • If you do not want to split camel-cased tokens, simply drop the -c option:

    somajo-tokenizer <file>
    
    <details><summary>Show example</summary>
    echo 'der beste Betreuer? - >ProfSmith! : )' | somajo-tokenizer -
    der
    beste
    Betreuer
    ?
    ->
    ProfSmith
    !
    :)
    
    </details>
  • Your input delimits paragraphs by single newlines instead of empty lines? Tell the tokenizer via the -s/--paragraph_separator option:

    somajo-tokenizer --paragraph_separator single_newlines <file>
    
  • In addition to tokenizing the input, SoMaJo can also split it into sentences:

    somajo-tokenizer --split-sentences <file>
    
    <details><summary>Show example</summary>
    echo 'Palim, Palim! Ich hätte gerne eine Flasche Pommes Frites.' | somajo-tokenizer --split-sentences -
    Palim
    ,
    Palim
    !
    
    Ich
    hätte
    gerne
    eine
    Flasche
    Pommes
    Frites
    .
    
    
  • To tokenize English text according to the “new” Penn Treebank conventions, explicitly specify the tokenization guideline using the -l/--language option:

    somajo-tokenizer -l en_PTB <file>
    
    <details><summary>Show example</summary>
    echo 'Dont you wanna come?' | somajo-tokenizer -l en_PTB -
    Do
    nt
    you
    wan
    na
    

Related Skills

View on GitHub
GitHub Stars153
CategoryMarketing
Updated1mo ago
Forks21

Languages

Python

Security Score

100/100

Audited on Feb 20, 2026

No findings