SELECT je->>'pos' AS pos, je->>'input-word' AS input_word, je->>'input-token' AS input_token, je->>'mapped-word' AS ouput_word, je->>'output-token' AS output_token FROM jsonb(debug_standardize_address('us_lex'::text, 'us_gaz'::text, 'us_rules'::text, '123 Main Street'::text, 'Kansas City, MO 45678'::text)) AS d, jsonb_array_elements(d->'rules'->0->'rule_tokens' ) AS je;
 pos | input_word | input_token | ouput_word | output_token 
-----+------------+-------------+------------+--------------
 0   | 123        | NUMBER      | 123        | HOUSE
 1   | MAIN       | WORD        | MAIN       | STREET
 2   | STREET     | TYPE        | STREET     | SUFTYP
(3 rows)

SELECT jsonb_array_length(jsonb(d)->'rules') FROM debug_standardize_address('us_lex','us_gaz','us_rules', '10-20 DORRANCE ST PROVIDENCE RI') AS d;
 jsonb_array_length 
--------------------
                  6
(1 row)

SELECT '#5299a' AS ticket, jsonb_array_length(d->'rules') AS num_rules, jsonb_array_length(d->'input_tokens') AS num_input_tokens,  d->'rules'->0->'raw_score' AS best_score FROM jsonb(debug_standardize_address('us_lex',  'us_gaz', 'us_rules','1 Timepiece Point','Boston, MA, 02220')) As d;
 ticket | num_rules | num_input_tokens | best_score 
--------+-----------+------------------+------------
 #5299a |         5 |                4 | 0.902500
(1 row)

SELECT '#2978c' As ticket, jsonb_array_length(d->'rules') AS num_rules, jsonb_array_length(d->'input_tokens') AS num_input_tokens,  d->'rules'->0->'raw_score' AS best_score FROM jsonb(debug_standardize_address('us_lex','us_gaz','us_rules', '10-20 DORRANCE ST, PROVIDENCE, RI')) AS d;
 ticket | num_rules | num_input_tokens | best_score 
--------+-----------+------------------+------------
 #2978c |         6 |                5 | 0.751875
(1 row)

SELECT '#5299b' AS ticket, jsonb_array_length(d->'rules') AS num_rules, jsonb_array_length(d->'input_tokens') AS num_input_tokens, d->'rules'->0->'score' AS best_score FROM jsonb(debug_standardize_address('us_lex',  'us_gaz', 'us_rules','50 Gold Piece Drive, Boston, MA, 02020')) AS d;
 ticket | num_rules | num_input_tokens | best_score 
--------+-----------+------------------+------------
 #5299b |         3 |                6 | 0.902500
(1 row)

SELECT '#5299bt' AS ticket, it->>'pos' AS pos, it->>'word' AS word,  it->>'token' AS token, it->>'stdword' AS stdword FROM jsonb(debug_standardize_address('us_lex',  'us_gaz', 'us_rules','50 Gold Piece Drive, Boston, MA, 02020')) AS d, jsonb_array_elements(d->'input_tokens') AS it
WHERE it @> '{"pos": 2}'::jsonb
ORDER BY pos, stdword, word, token;
 ticket  | pos | word  | token | stdword 
---------+-----+-------+-------+---------
 #5299bt | 2   | PIECE | UNITH | PIECE
 #5299bt | 2   | PIECE | UNITT | PIECE
 #5299bt | 2   | PIECE | WORD  | PIECE
(3 rows)

SELECT r->>'score' AS score,r->>'rule_string' AS rule, r->>'rule_stub_string' AS rule_stub  FROM jsonb(debug_standardize_address('us_lex','us_gaz','us_rules', '25 Prince Street, NC 09985')) AS d, jsonb_array_elements(d->'rules') AS r;
  score   |          rule          |      rule_stub      
----------+------------------------+---------------------
 0.902500 | 0 1 2 -1 1 5 6 -1 1 16 | 0 1 2 -1 1 5 6 -1 %
 0.791875 | 0 1 2 -1 1 5 6 -1 1 16 | 0 1 2 -1 1 5 6 -1 %
 0.661250 |                        | 0 1 2 -1 1 5 5 -1 %
(3 rows)

