Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
garyelephant committed Sep 24, 2016
1 parent 91cea34 commit 14a77d3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
40 changes: 30 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. contents::
:depth: 3
..
pygrok |Build Status|
=====================

Expand Down Expand Up @@ -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:

::

Expand All @@ -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 <https://github.com/garyelephant/pygrok/blob/master/tests/test_pygrok.py#L97>`__.

More details
------------

Expand Down

0 comments on commit 14a77d3

Please sign in to comment.