From 14a77d3914610490e91b7ad94b59ccb5baa17e12 Mon Sep 17 00:00:00 2001 From: garyelephant Date: Sat, 24 Sep 2016 08:22:45 +0000 Subject: [PATCH] update README --- README.md | 22 ++++++++++++++-------- README.rst | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5129ec7..07c9080 100644 --- a/README.md +++ b/README.md @@ -29,20 +29,26 @@ or download, uncompress and install pygrok from [here](https://github.com/garyel Getting Started --------------- ```Python ->>> import pygrok ->>> text = 'gary is male, 25 years old and weighs 68.5 kilograms' ->>> pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms' ->>> print pygrok.grok_match(text, pattern) -{'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'} +from pygrok import Grok +text = 'gary is male, 25 years old and weighs 68.5 kilograms' +pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms' +grok = Grok(pattern) +print grok.match(text) + +# {'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'} ``` Pretty Cool ! Numbers can be converted from string to `int` or `float` if you use `%{pattern:name:type}` syntax, such as `%{NUMBER:age:int}` ```Python ->>> pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age:int} years old and weighs %{NUMBER:weight:float} kilograms' ->>> print pygrok.grok_match(text, pattern) -{'gender': 'male', 'age': 25, 'name': 'gary', 'weight': 68.5} +from pygrok import Grok +text = 'gary is male, 25 years old and weighs 68.5 kilograms' +pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age:int} years old and weighs %{NUMBER:weight:float} kilograms' +grok = Grok(pattern) +print grok.match(text, pattern) + +# {'gender': 'male', 'age': 25, 'name': 'gary', 'weight': 68.5} ``` Now `age` is of type `int` and `weight` is of type `float`. diff --git a/README.rst b/README.rst index 1e78323..729e677 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,3 @@ -.. contents:: - :depth: 3 -.. - pygrok |Build Status| ===================== @@ -38,13 +34,34 @@ Getting Started .. code:: Python - >>> import pygrok - >>> text = 'gary is male, 25 years old and weighs 68.5 kilograms' - >>> pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms' - >>> print pygrok.grok_match(text, pattern) - {'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'} + from pygrok import Grok + text = 'gary is male, 25 years old and weighs 68.5 kilograms' + pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms' + grok = Grok(pattern) + print grok.match(text) + + # {'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'} + +Pretty Cool ! + +Numbers can be converted from string to ``int`` or ``float`` if you use +``%{pattern:name:type}`` syntax, such as ``%{NUMBER:age:int}`` + +.. code:: Python -Pretty Cool ! Some of the pattern you can use are listed here: + from pygrok import Grok + text = 'gary is male, 25 years old and weighs 68.5 kilograms' + pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age:int} years old and weighs %{NUMBER:weight:float} kilograms' + grok = Grok(pattern) + print grok.match(text, pattern) + + # {'gender': 'male', 'age': 25, 'name': 'gary', 'weight': 68.5} + +Now ``age`` is of type ``int`` and ``weight`` is of type ``float``. + +Awesome ! + +Some of the pattern you can use are listed here: :: @@ -56,6 +73,9 @@ Pretty Cool ! Some of the pattern you can use are listed here: See All patterns `here <./pygrok/patterns>`__ +You can also have custom pattern, see `these +codes `__. + More details ------------