From 3b468c5e208041c63ece57b3ea748e2cbb8e5cfd Mon Sep 17 00:00:00 2001 From: d1ana Date: Thu, 29 Mar 2012 15:40:40 -0400 Subject: [PATCH] docs --- doc/election.rst | 5 +++-- doc/keyset.rst | 5 ----- inferno/example_rules/election.py | 12 ++++++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/election.rst b/doc/election.rst index 5d7ed7c..23ee641 100644 --- a/doc/election.rst +++ b/doc/election.rst @@ -14,6 +14,7 @@ Inferno Rule The Inferno map/reduce rule (``inferno/example_rules/election.py``): .. literalinclude:: ../inferno/example_rules/election.py + :emphasize-lines: 44-49, 58, 66 Input ----- @@ -51,7 +52,7 @@ Output Contributions by Candidate ~~~~~~~~~~~~~~~~~~~~~~~~~~ -Run the contributions_by_candidate_name map/reduce job:: +Run the **contributions_by_candidate_name** job:: diana@ubuntu:~$ inferno -i election.presidential_2012.by_candidate 2012-03-19 Processing tags: ['gov:chunk:presidential_campaign_finance'] @@ -87,7 +88,7 @@ The output as a table: Contributions by Occupation ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Run the contributions_by_occupation_and_candidate_name map/reduce job:: +Run the **contributions_by_occupation_and_candidate_name** job:: diana@ubuntu:~$ inferno -i election.presidential_2012.by_occupation > occupations.csv 2012-03-19 Processing tags: ['gov:chunk:presidential_campaign_finance'] diff --git a/doc/keyset.rst b/doc/keyset.rst index 85e8efd..f31d32e 100644 --- a/doc/keyset.rst +++ b/doc/keyset.rst @@ -18,11 +18,6 @@ column_mappings TODO -table ------ - - TODO - parts_preprocess ---------------- diff --git a/inferno/example_rules/election.py b/inferno/example_rules/election.py index e344a21..3326a86 100644 --- a/inferno/example_rules/election.py +++ b/inferno/example_rules/election.py @@ -5,15 +5,18 @@ from inferno.lib.rule import InfernoRule from inferno.lib.rule import Keyset +# an example field_transform +def alphanumeric(val): + return re.sub(r'\W+', ' ', val).strip().lower() + + +# an example parts_preprocess that modifies the map input def count(parts, params): parts['count'] = 1 yield parts -def alphanumeric(val): - return re.sub(r'\W+', ' ', val).strip().lower() - - +# an example parts_preprocess that filters the map input def candidate_filter(parts, params): active = [ 'P20002721', # Santorum, Rick @@ -26,6 +29,7 @@ def candidate_filter(parts, params): yield parts +# an example parts_postprocess that filters the reduce output def occupation_count_filter(parts, params): if parts['count_occupation_candidate'] > 1000: yield parts