<commit_before>require 'test_helper'

class AlchemyHelperTest < ActionView::TestCase

  TECH_CRUNCH_URL = 'http://www.techcrunch.com/'
  TEST_URL = 'http://www.test.com/'
  MICROFORMATS_URL = 'http://microformats.org/wiki/hcard'
  STRING_WITH_NAMES_ENTITIES = "Hello my name is Bob.  I am speaking to you at this very moment.  Are you listening to me, Bob?"

  def file_path(filename)
    "#{Rails.root}/test/unit/alchemy/data/#{filename}"
  end

  def setup
    @alchemyObj = AlchemyAPI.new();
    @alchemyObj.setAPIKey(AlchemyHelper::API_KEY);

    # Load a HTML document to analyze.
    @htmlFile = File.readlines(file_path('example.html')).map {|l| l.strip}
  end

  test 'author' do
    # Extract concept tags from a web URL.
    result = @alchemyObj.URLGetAuthor("http://www.politico.com/blogs/media/2012/02/detroit-news-ed-upset-over-romney-edit-115247.html");
    Rails.logger.info "AlchemyAPI result: #{result}"

    assert_raise RuntimeError do
      # Extract concept tags from a web URL.
      # Raises an error because it can't find the author.
      @alchemyObj.HTMLGetAuthor(@htmlFile, TEST_URL);
    end
  end

  test 'categories' do
    # Categorize a web URL.
    result = @alchemyObj.URLGetCategory(TECH_CRUNCH_URL);
    assert_not_nil result

    # Categorize some text.
    result = @alchemyObj.TextGetCategory("Latest on the War in Iraq.");
    assert_not_nil result
<commit_msg>AlchemyAPI has a very low daily limit of 1000 calls. I'm skipping all of the alchemy unit tests in order to avoid hitting that limit.<commit_after>require 'test_helper'

class AlchemyHelperTest < ActionView::TestCase

  TECH_CRUNCH_URL = 'http://www.techcrunch.com/'
  TEST_URL = 'http://www.test.com/'
  MICROFORMATS_URL = 'http://microformats.org/wiki/hcard'
  STRING_WITH_NAMES_ENTITIES = "Hello my name is Bob.  I am speaking to you at this very moment.  Are you listening to me, Bob?"

  ENABLE = false

  def file_path(filename)
    "#{Rails.root}/test/unit/alchemy/data/#{filename}"
  end

  def setup
    @alchemyObj = AlchemyAPI.new();
    @alchemyObj.setAPIKey(AlchemyHelper::API_KEY);

    # Load a HTML document to analyze.
    @htmlFile = File.readlines(file_path('example.html')).map {|l| l.strip}

    if !ENABLE
      skip 'Disabling AlchemyAPI tests in order to avoid hitting their daily API limit.'
    end
  end

  test 'author' do
    # Extract concept tags from a web URL.
    result = @alchemyObj.URLGetAuthor("http://www.politico.com/blogs/media/2012/02/detroit-news-ed-upset-over-romney-edit-115247.html");
    Rails.logger.info "AlchemyAPI result: #{result}"

    assert_raise RuntimeError do
      # Extract concept tags from a web URL.
      # Raises an error because it can't find the author.
      @alchemyObj.HTMLGetAuthor(@htmlFile, TEST_URL);
    end
  end

  test 'categories' do
    # Categorize a web URL.
    result = @alchemyObj.URLGetCategory(TECH_CRUNCH_URL);
    assert_not_nil result

    # Categorize some text.
    result = @alchemyObj.TextGetCategory("Latest on the War in Iraq.");
    assert_not_nil result

{'fraction_non_alphanumeric': 0.10743530953160825, 'fraction_numerical': 0.00917130691123485, 'mean_word_length': 3.537890044576523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '3496572', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1004, 'n_words': 270}