Tokenizer - Module python d'analyse syntaxique et de grammaire, tokenization

Overview

Tokenizer

Le Tokenizer est un analyseur lexicale, il permet, comme Flex and Yacc par exemple, de tokenizer du code, c'est à dire transformer du code en liste tokens. En l'occurence, contrairement à Flex and Yacc, la liste de token sera hiérarchisée et les tokens sont typés.

Qu'est-ce que c'est quoi dis donc un token ?

Un token, litteralement, c'est un jeton... Bof bof comme définition... Repprenons. Un token c'est une chaîne de caractères qui, ensemble, ont une signification. La chaîne de caractères qui forme un jeton est appelée Lexeme.

Et à quoi ça sert ?

La tokenization, c'est la prmière étape de la compilation ou de l'interprétation de la plupart des langages informatiques. Prenons Python par exemple, l'ordinateur ne sait absolument pas quoi faire avec le ficher qu'on lui donne, il le découpe donc pour avoir chacun des mots du code et pouvoir comprendre ce qu'on lui demande.


Exemple :

Du code python comme celui ci :

def hello(name) :
    print("Hello", name, "!")

sera convertit en YAML (ou n'importe quel autre langage de stockage de données comme JSON par exemple)

---
- {value: 'def', type: function.declaration}
- {value: 'hello', type: name.funciton.declaration}
- {value: '(', type: punctuation.begin}
- {value: 'name', type: parameter}
- {value: ')', type: punctuation.end}
- {value: ':', type: start.node}
- - {value: 'print', type: function}
  - {value: '(', type: punctuation.begin}
  - {value: '"Hello"', type: string}
  - {value: ',', type: separator}
  - {value: 'name', type: variable}
  - {value: ',', type: separator}
  - {value: '"!"', type: string}
  - {value: ')', type: punctuation.end}

Ici les tokens sont hiérarchisés et typés, c'est à dire que pour chaque nœud, une nouvelle liste est créée et pour chaque token, un attribut de type lui est appliqué.

Le typage des tokens peut être utile car le tokenizateur peut, avec une grammaire, faire un fichier de coloration syntaxique si l'on indique dans le type la couleur du token.


Spécifications

technologie outil
Langage Python
Version du langage 3.10
Gestionnaire des packets PIP
Gestionnaire d'environnement VirtualEnvironment
Environnement Windows 7/10
Librairie PyYaml, re

Installation

pip install -e git+https://github.com/Manolo-dev/tokenizer.git#egg=tokenizer


To do list

  • Grammaire
  • Classe Token
  • Classe Node
  • Main
  • Gestion des erreurs
  • Lecteur Yaml

Grammaire

Oui, il faut une grammaire à l'outil de grammaire ! Grammaception !

Corps

Le corps se compose d'au moins deux parties, variables, qui contient des expressions regexp, et les modules, dont main, seul module obligatoire.

  • variables

  • main

Module

main est le seul module qui est appelé sans qu'on l'incluse manuellement.

Les modules traitent le code et s'occupe de la grosse part du travail, ils peuvent utiliser les variables définies dans le module, dans un module encore ouvert (variables locale) ou dans variables.

Méthodes

  • include, inclut un module.

  • match, corresptond à un SI token correspond FAIRE, assigne à l'objet courant le token trouvé et éxécute le module donné (nommé ou non).

  • save, assigne un type à l'objet courant et enregistre le token dans la liste des tokens.

  • if, vérifie la condition donnée (liste de trois arguments, le premier l'opérateur, le second et le troisième les valeurs à tester). Exemple: if: ['==', ;a, ;b]

  • begin, crée un nœud et le débute.

  • end, ferme le nœud.

  • ignore, ne fait pas avancer le texte.

  • var, modifie les variables de la même manière que le module variables, la variable _ représente le token trouvé.

  • error, génère une erreur (équivalent au raise python)

  • print, affiche le texte donné dans la console.

Variables

Il y deux moyens d'utiliser les variables. Dans le cas d'une variable d'exemple appelée var, on peut faire :

  • ;var, seul dans l'élément.

  • {{var}}, peut-être placé n'importe où dans l'élément.

  • str:n, permet de supprimer n caractères à la chaîne str.

Exemple

variables:
  open: '\('
  close: '\)'
main:
  - match: ;open
    save: 'open'
    begin: # Ceci est un module non nommé
    - match: ;close
      save: 'close'
      end: 1
    - include: 'main'
  - match: '[^()]+' # pour éviter de prendre des parenthèses involontairement
    save: 'other'
  - match: ;close
    error: il y a une parenthèse de fermeture en trop

Cette grammaire fait de la parenthétisation simple, en simple, ça transforme ceci :

1 / (3 * (1 + 2))

en :

---
- {value: '1 / ', type: 'other'}
- {value: '(', type: 'open'}
- - {value: '3 * ', type: 'other'}
  - {value: '(', type: 'open'}
  - - {value: '1 + 2', type: 'other'}
  - {value: ')', type: 'close'}
- {value: ')', type: 'close'}
Owner
Manolo
Hi ! My name is Manolo, I am 18 years old. I have been programming since I was 11 or 12 (I can't quite remember) with BASIC CASIO. And i love code !
Manolo
It analyze the sentiment of the user, whether it is postive or negative.

Sentiment-Analyzer-Tool It analyze the sentiment of the user, whether it is postive or negative. It uses streamlit library for creating this sentiment

Paras Patidar 18 Dec 17, 2022
Pre-Training with Whole Word Masking for Chinese BERT

Pre-Training with Whole Word Masking for Chinese BERT

Yiming Cui 7.7k Dec 31, 2022
Python module (C extension and plain python) implementing Aho-Corasick algorithm

pyahocorasick pyahocorasick is a fast and memory efficient library for exact or approximate multi-pattern string search meaning that you can find mult

Wojciech Muła 763 Dec 27, 2022
Implementation of Natural Language Code Search in the project CodeBERT: A Pre-Trained Model for Programming and Natural Languages.

CodeBERT-Implementation In this repo we have replicated the paper CodeBERT: A Pre-Trained Model for Programming and Natural Languages. We are interest

Tanuj Sur 4 Jul 01, 2022
Chinese segmentation library

What is loso? loso is a Chinese segmentation system written in Python. It was developed by Victor Lin ( Fang-Pen Lin 82 Jun 28, 2022

🗣️ NALP is a library that covers Natural Adversarial Language Processing.

NALP: Natural Adversarial Language Processing Welcome to NALP. Have you ever wanted to create natural text from raw sources? If yes, NALP is for you!

Gustavo Rosa 21 Aug 12, 2022
Tool to check whether a GCP bucket is public or not.

Tool to check publicly accessible GCP bucket. Blog https://justm0rph3u5.medium.com/gcp-inspector-auditing-publicly-exposed-gcp-bucket-ac6cad55618c Wha

DIVYANSHU SHUKLA 7 Nov 24, 2022
TFIDF-based QA system for AIO2 competition

AIO2 TF-IDF Baseline This is a very simple question answering system, which is developed as a lightweight baseline for AIO2 competition. In the traini

Masatoshi Suzuki 4 Feb 19, 2022
Spokestack is a library that allows a user to easily incorporate a voice interface into any Python application with a focus on embedded systems.

Welcome to Spokestack Python! This library is intended for developing voice interfaces in Python. This can include anything from Raspberry Pi applicat

Spokestack 133 Sep 20, 2022
Coreference resolution for English, French, German and Polish, optimised for limited training data and easily extensible for further languages

Coreferee Author: Richard Paul Hudson, Explosion AI 1. Introduction 1.1 The basic idea 1.2 Getting started 1.2.1 English 1.2.2 French 1.2.3 German 1.2

Explosion 70 Dec 12, 2022
Python interface for converting Penn Treebank trees to Stanford Dependencies and Universal Depenencies

PyStanfordDependencies Python interface for converting Penn Treebank trees to Universal Dependencies and Stanford Dependencies. Example usage Start by

David McClosky 64 May 08, 2022
Text Normalization(文本正则化)

Text Normalization(文本正则化) 任务描述:通过机器学习算法将英文文本的“手写”形式转换成“口语“形式,例如“6ft”转换成“six feet”等 实验结果 XGBoost + bag-of-words: 0.99159 XGBoost+Weights+rules:0.99002

Jason_Zhang 0 Feb 26, 2022
Implementation of ProteinBERT in Pytorch

ProteinBERT - Pytorch (wip) Implementation of ProteinBERT in Pytorch. Original Repository Install $ pip install protein-bert-pytorch Usage import torc

Phil Wang 92 Dec 25, 2022
An easy-to-use framework for BERT models, with trainers, various NLP tasks and detailed annonations

FantasyBert English | 中文 Introduction An easy-to-use framework for BERT models, with trainers, various NLP tasks and detailed annonations. You can imp

Fan 137 Oct 26, 2022
Sequence-to-Sequence Framework in PyTorch

nmtpytorch allows training of various end-to-end neural architectures including but not limited to neural machine translation, image captioning and au

LIUM 395 Nov 21, 2022
Every Google, Azure & IBM text to speech voice for free

TTS-Grabber Quick thing i made about a year ago to download any text with any tts voice, over 630 voices to choose from currently. It will split the i

16 Dec 07, 2022
ACL22 paper: Imputing Out-of-Vocabulary Embeddings with LOVE Makes Language Models Robust with Little Cost

Imputing Out-of-Vocabulary Embeddings with LOVE Makes Language Models Robust with Little Cost LOVE is accpeted by ACL22 main conference as a long pape

Lihu Chen 32 Jan 03, 2023
A raytrace framework using taichi language

ti-raytrace The code use Taichi programming language Current implement acceleration lvbh disney brdf How to run First config your anaconda workspace,

蕉太狼 73 Dec 11, 2022
Library of deep learning models and datasets designed to make deep learning more accessible and accelerate ML research.

Tensor2Tensor Tensor2Tensor, or T2T for short, is a library of deep learning models and datasets designed to make deep learning more accessible and ac

12.9k Jan 07, 2023
Question answering app is used to answer for a user given question from user given text.

Question answering app is used to answer for a user given question from user given text.It is created using HuggingFace's transformer pipeline and streamlit python packages.

Siva Prakash 3 Apr 05, 2022