GithubHelp home page GithubHelp logo

auto_regex's Introduction

auto_regex

regex automated

install

install from pip

   pip install auto_regex

or install from github with pip

    pip install git+https://github.com/JarbasAl/auto_regex

or install from source

    git clone https://github.com/JarbasAl/auto_regex
    cd auto_regex
    python setup.py install

or just bundle the python file with your project, it is standalone

usage

importing the module

from autoregex import AutoRegex

a = AutoRegex()

generating a regex expression

texts = ["say {word}", "repeat {word}"]
for regex_expression in a.get_expressions(texts):
  print(regex_expression)

outputs

^\W*say\W*(?P<word>.*?\w.*?)\W*$
^\W*repeat\W*(?P<word>.*?\w.*?)\W*$

extracting entities from regex

  lines= ["say {word}", "repeat {word}"]
  query = "say hello"
  a.create_regex(lines)
  for ent in a.get_entities(query):
      print(ent)

outputs

  {'word': 'hello'}

matching regexes

  lines= ["say {word}", "repeat {word}"]
  query = "say i am a bot, blip blop"
  a.create_regex(lines)
      for e in a.get_matches(query):
          print(e)

outputs

  {
    'query': 'say i am a bot, blip blop', 
    'entities': {'word': 'i am a bot, blip blop'}, 
    'regexes': ['^\\W*repeat\\W*(?P<word>.*?\\w.*?)\\W*$']
  }

while there is no documentation take a look at the unittests to have an idea of expected behaviour and use cases

Caveats and known bugs

  • extra spaces will be removed

  • spaces in entities will be replaced with _

    say {two words} -> say {two_words}

  • sentences become lower case

Credits

JarbasAI

Heavily borrowed from Padaos

auto_regex's People

Contributors

jarbasal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.