Skip to content

Commit

Permalink
improve title parsing (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Sep 14, 2014
1 parent 8926885 commit d197d2e
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 76 deletions.
171 changes: 97 additions & 74 deletions lib/namae/parser.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions lib/namae/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ rule
honorific : APPELLATION { result = Name.new(:appellation => val[0]) }
| TITLE { result = Name.new(:title => val[0]) }

display_order : u_words word opt_suffices
display_order : u_words word opt_suffices opt_titles
{
result = Name.new(:given => val[0], :family => val[1], :suffix => val[2])
result = Name.new(:given => val[0], :family => val[1], :suffix => val[2], :title => val[3])
}
| u_words NICK last
{
Expand Down Expand Up @@ -91,6 +91,11 @@ rule
suffices : SUFFIX
| suffices SUFFIX { result = val.join(' ') }

opt_titles : /* empty */ | titles

titles : TITLE
| titles TITLE { result = val.join(' ') }

---- header
require 'singleton'
require 'strscan'
Expand Down
16 changes: 16 additions & 0 deletions spec/namae/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ module Namae
end
end

%w{Ph.D. PhD PHD Dr. Dr Prof.}.each do |title|
describe "the next token is #{title.inspect}" do
before { parser.send(:input).string = title }
it 'returns a TITLE token' do
expect(parser.send(:next_token)).to eq([:TITLE, title])
end

it 'the input matches the suffix pattern' do
expect(parser.title).to match(title)
end
end
end
end

describe '#parse!' do
Expand Down Expand Up @@ -125,6 +137,10 @@ module Namae
expect(parser.parse!('Ken Griffey Jr.')[0].values_at(:given, :family, :suffix)).to eq(['Ken', 'Griffey', 'Jr.'])
end

it 'parses Ph.D. title suffix in display order' do
expect(parser.parse!('Bernado Franecki Ph.D.')[0].values_at(:given, :family, :title)).to eq(['Bernado', 'Franecki', 'Ph.D.'])
#expect(parser.parse!('Bernado Franecki, Ph.D.')[0].values_at(:given, :family, :title)).to eq(['Bernado', 'Franecki', 'Ph.D.'])
end
end
end

Expand Down

0 comments on commit d197d2e

Please sign in to comment.