<commit_before>$:.unshift "#{File.dirname(__FILE__)}/../lib"

require "test/unit"
require 'spec'

require "hansard_speech"

describe HansardSpeech, "should recognise who's talking" do
  
  it "in a speech block" do
    speech = HansardSpeech.new(Hpricot.XML('
		<speech>
			<talk.start>
				<talker>
					<name role="metadata">Rudd, Kevin, MP</name>
					<name.id>83T</name.id>
					<name role="display">Mr RUDD</name>
				</talker>
			</talk.start>
		</speech>'), nil)
		
		speech.speakername.should == "<NAME>"
		speech.aph_id.should == "83T"
		speech.interjection.should be_false
  end

	it "in a motionnospeech block" do
	  speech = HansardSpeech.new(Hpricot.XML('<motionnospeech><name><NAME></name></motionnospeech>'), nil)
		speech.speakername.should == "<NAME>"
		speech.aph_id.should be_nil
		speech.interjection.should be_false
	end

	it "in an interjection block" do
	  speech = HansardSpeech.new(Hpricot.XML('
	  <interjection>
			<talk.start>
				<talker>
					<name.id>10000</name.id>
					<name role="metadata">SPEAKER, The</name>
					<name role="display">The SPEAKER</name>
				</talker>
			</talk.start>
		</interjection>'), nil)
		speech.speakername.should == "<NAME>"
		speech.aph_id.should == "10000"
		speech.interjection.should be_true
  end
  
  it "is not an interjection if the talker is specified but there is interjecting in the text" do
    speech = HansardSpeech.new(Hpricot.XML('
    <continue>
			<talk.start>
				<talker>
					<name.id>EZ5</name.id>
					<name role="metadata"><NAME>, MP</name>
					<name role="display">Mr ABBOTT</name>
				</talker>
				<para>I listened to all the accusations of bad faith without interjecting.</para>
			</talk.start>
		</continue>'), nil)
		speech.interjection.should be_false		
  end
end

describe HansardSpeech, "should clean content" do
  
  it "in a simple paragraph" do
    speech = HansardSpeech.new(Hpricot.XML('<speech><talk.start><para>—I move:</para></talk.start></speech>').at('//(talk.start)'), nil)
		expected_result = '<p>I move:</p>'
		speech.clean_content.to_s.should == expected_result
  end
  
  it "in a para (block)" do
    content = '<speech><para class="block">Some text</para></speech>'
    expected = '<p>Some text</p>'
    HansardSpeech.clean_content_para(Hpricot.XML(content).at('para')).should == expected

    speech = HansardSpeech.new(Hpricot.XML(content).at('para'), nil)
    speech.clean_content.to_s.should == expected
  end  <commit_msg>New test for when there are two versions of the speaker name available. Return the one that's longer.<commit_after>$:.unshift "#{File.dirname(__FILE__)}/../lib"

require "test/unit"
require 'spec'

require "hansard_speech"

describe HansardSpeech, "should recognise who's talking" do
  
  it "in a speech block" do
    speech = HansardSpeech.new(Hpricot.XML('
		<speech>
			<talk.start>
				<talker>
					<name role="metadata"><NAME>, MP</name>
					<name.id>83T</name.id>
					<name role="display">Mr RUDD</name>
				</talker>
			</talk.start>
		</speech>'), nil)
		
		speech.speakername.should == "<NAME>"
		speech.aph_id.should == "83T"
		speech.interjection.should be_false
  end

	it "in a motionnospeech block" do
	  speech = HansardSpeech.new(Hpricot.XML('<motionnospeech><name><NAME></name></motionnospeech>'), nil)
		speech.speakername.should == "<NAME>"
		speech.aph_id.should be_nil
		speech.interjection.should be_false
	end

	it "in an interjection block" do
	  speech = HansardSpeech.new(Hpricot.XML('
	  <interjection>
			<talk.start>
				<talker>
					<name.id>10000</name.id>
					<name role="metadata">SPEAKER, The</name>
					<name role="display">The SPEAKER</name>
				</talker>
			</talk.start>
		</interjection>'), nil)
		speech.speakername.should == "<NAME>"
		speech.aph_id.should == "10000"
		speech.interjection.should be_true
  end
  
  it "is not an interjection if the talker is specified but there is interjecting in the text" do
    speech = HansardSpeech.new(Hpricot.XML('
    <continue>
			<talk.start>
				<talker>
					<name.id>EZ5</name.id>
					<name role="metadata"><NAME></name>
					<name role="display"><NAME></name>
				</talker>
				<para>I listened to all the accusations of bad faith without interjecting.</para>
			</talk.start>
		</continue>'), nil)
		speech.interjection.should be_false		
  end
  
  it "should return the version of the speakername with more information" do
    speech = HansardSpeech.new(Hpricot.XML('
    <interjection>
			<talk.start>
				<talker>
					<name role="metadata"><NAME> (The DEPUTY SPEAKER)</name>
					<name role="display">The DEPUTY SPEAKER</name>
				</talker>
			</talk.start>
		</interjection>'), nil)
		speech.speakername.should == "<NAME> (The DEPUTY SPEAKER)"
		speech.interjection.should be_true
  end
end

describe HansardSpeech, "should clean content" do
  
  it "in a simple paragraph" do
    speech = HansardSpeech.new(Hpricot.XML('<speech><talk.start><para>—I move:</para></talk.start></speech>').at('//(talk.start)'), nil)
		expected_result = '<p>I move:</p>'
		speech.clean_content.to_s.should == expected_result
  end
  
  it "in a para (block)" do
    content = '<speech><para class="block">Some text</para></speech>'
    expected = '<p>Some text</p>'
    HansardSpeech.clean_content_para(Hpricot.XML(content).at('para')).should == expected

    speech = HansardSpeech.new(Hpricot.XML(content).at('para'), nil)
    speech.clean_content.to_s.should == expected
  end  
{'fraction_non_alphanumeric': 0.15464298927118017, 'fraction_numerical': 0.005549389567147614, 'mean_word_length': 3.763876651982379, 'pattern_counts': {'":': 0, '<': 139, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5740516', 'n_tokens_mistral': 2166, 'n_tokens_neox': 1869, 'n_words': 416}