<commit_before>package wordcram.text;

/*
Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import java.util.Map;
import java.util.SortedSet;

import org.junit.*;

import wordcram.Word;

public class TestTextSplitter {

	private double epsilon = 0.00001;
	private TextSplitter ts;

	@Before
	public void setup() {
		ts = new TextSplitter("these are stop words");
	}

	@Test
	public void testFrontDoorWithStringArray() {
		String[] stringArray = new String[] { "BISCUIT biscuit, ",
				"mango, mAngO,", " MaNgO! Avocado." };
		Word[] results = ts.split(stringArray);
		Assert.assertEquals("mango", results[0].word);
		Assert.assertEquals("biscuit", results[1].word);
		Assert.assertEquals("avocado", results[2].word);
		Assert.assertEquals(3 / 3d, results[0].weight, epsilon);
		Assert.assertEquals(2 / 3d, results[1].weight, epsilon);
		Assert.assertEquals(1 / 3d, results[2].weight, epsilon);
	}

	@Test
	public void testFrontDoor() {
		Word[] results = ts
				.split("BISCUIT biscuit, mango, mAngO, MaNgO! Avocado.");
		Assert.assertEquals("mango", results[0].word);
		Assert.assertEquals("biscuit", results[1].word);
		Assert.assertEquals("avocado", results[2].word);
		Assert.assertEquals(3 / 3d, results[0].weight, epsilon);
		Assert.assertEquals(2 / 3d, results[1].weight, epsilon);
		Assert.assertEquals(1 / 3d, results[2].weight, epsilon);
	}

	@Test
	public void testRankingAndStopWords() {
		String[] words = ts
				.splitIntoWords("biscuit biscuit cocoa cherry cherry cherry stop words are these these are stop words");
		Map<String, Integer> counts = ts.count(words);
		SortedSet<Word> ranks = ts.weight(counts);
		Assert.assertEquals(3, ranks.size());

		Word[] ranksArray = ranks.toArray(new Word[0]);

		Assert.assertEquals("cherry", ranksArray[0].word);
		Assert.assertEquals("biscuit", ranksArray[1].word);
		Assert.assertEquals("cocoa", ranksArray[2].word);

		Assert.assertEquals(3 / 3d, ranksArray[0].weight, epsilon);
		Assert.assertEquals(2 / 3d, ranksArray[1].weight, epsilon);
		Assert.assertEquals(1 / 3d, ranksArray[2].weight, epsilon);
	}

	@Test
	public void testCounts() {
		String[] words = ts.splitIntoWords("a b c a");
		Map<String, Integer> counts = ts.count(words);
		Assert.assertEquals(new Integer(2), (Integer) counts.get("a"));
		Assert.assertEquals(new Integer(1), (Integer) counts.get("b"));
		Assert.assertEquals(new Integer(1), (Integer) counts.get("c"));
		Assert.assertNull(counts.get("d"));
	}

	@Test
	public void testSplit() {
		testSplit("yo baby boo", "yo baby boo", "basic test");
		testSplit("hey now mamma jamma", "hey  now  mamma    jamma",<commit_msg>forgot to commit the Tests, too  =(<commit_after>package wordcram.text;

/*
Copyright 2010 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import java.util.Map;
import java.util.SortedSet;

import org.junit.*;

import wordcram.Word;

public class TestTextSplitter {

	private double epsilon = 0.00001;
	private TextSplitter ts;

	@Before
	public void setup() {
		ts = new TextSplitter("these are stop words");
	}

	@Test
	public void testFrontDoorWithStringArray() {
		String[] stringArray = new String[] { "BISCUIT biscuit, ",
				"mango, mAngO,", " MaNgO! Avocado." };
		Word[] results = ts.split(stringArray);
		Assert.assertEquals("mango", results[0].word);
		Assert.assertEquals("biscuit", results[1].word);
		Assert.assertEquals("avocado", results[2].word);
		Assert.assertEquals(3, results[0].weight, epsilon);
		Assert.assertEquals(2, results[1].weight, epsilon);
		Assert.assertEquals(1, results[2].weight, epsilon);
	}

	@Test
	public void testFrontDoor() {
		Word[] results = ts
				.split("BISCUIT biscuit, mango, mAngO, MaNgO! Avocado.");
		Assert.assertEquals("mango", results[0].word);
		Assert.assertEquals("biscuit", results[1].word);
		Assert.assertEquals("avocado", results[2].word);
		Assert.assertEquals(3, results[0].weight, epsilon);
		Assert.assertEquals(2, results[1].weight, epsilon);
		Assert.assertEquals(1, results[2].weight, epsilon);
	}

	@Test
	public void testRankingAndStopWords() {
		String[] words = ts
				.splitIntoWords("biscuit biscuit cocoa cherry cherry cherry stop words are these these are stop words");
		Map<String, Integer> counts = ts.count(words);
		Word[] ranks = ts.weight(counts);
		Assert.assertEquals(3, ranks.length);

		Assert.assertEquals("cherry", ranks[0].word);
		Assert.assertEquals("biscuit", ranks[1].word);
		Assert.assertEquals("cocoa", ranks[2].word);

		Assert.assertEquals(3, ranks[0].weight, epsilon);
		Assert.assertEquals(2, ranks[1].weight, epsilon);
		Assert.assertEquals(1, ranks[2].weight, epsilon);
	}

	@Test
	public void testCounts() {
		String[] words = ts.splitIntoWords("a b c a");
		Map<String, Integer> counts = ts.count(words);
		Assert.assertEquals(new Integer(2), (Integer) counts.get("a"));
		Assert.assertEquals(new Integer(1), (Integer) counts.get("b"));
		Assert.assertEquals(new Integer(1), (Integer) counts.get("c"));
		Assert.assertNull(counts.get("d"));
	}

	@Test
	public void testSplit() {
		testSplit("yo baby boo", "yo baby boo", "basic test");
		testSplit("hey now mamma jamma", "hey  now  mamma    jamma",
{'fraction_non_alphanumeric': 0.14037103923822034, 'fraction_numerical': 0.016417665407978985, 'mean_word_length': 4.960861056751468, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3387215', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1903, 'n_words': 544}