Skip to content

Commit

Permalink
Merge pull request #2 from stscoundrel/feature/dictionary
Browse files Browse the repository at this point in the history
Feature/dictionary
  • Loading branch information
stscoundrel authored Dec 4, 2022
2 parents 1345d0b + 779e921 commit f0c86f8
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 36 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
</dependency>
</dependencies>

<build>
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/github/stscoundrel/javatemplate/App.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.stscoundrel.oldicelandicdictionary;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import com.google.gson.Gson;

public class Dictionary {
private DictionaryEntry[] entries;
private DictionaryEntry[] markupEntries;

enum DictionaryLocation {
NoMarkup,
Markup
}

private static String getDictionaryPath(DictionaryLocation location) {
if (location == DictionaryLocation.NoMarkup) {
return "/no-markup.json";
}
return "/markup.json";

}

private static DictionaryEntry[] readDictionary(DictionaryLocation location) {
// Read the JSON file from the resources folder
InputStream inputStream = Dictionary.class.getResourceAsStream(getDictionaryPath(location));
Reader reader = new InputStreamReader(inputStream);

// Create a Gson instance
Gson gson = new Gson();

// Parse the JSON and convert it to a Java object
DictionaryEntry[] result = gson.fromJson(reader, DictionaryEntry[].class);

return result;
}

public DictionaryEntry[] getMarkupDictionary() {
if (entries == null) {
entries = readDictionary(DictionaryLocation.Markup);
}

return entries;
}

public DictionaryEntry[] getNoMarkupDictionary() {
if (markupEntries == null) {
markupEntries = readDictionary(DictionaryLocation.NoMarkup);
}

return markupEntries;
}

public DictionaryEntry[] getDictionary() {
return getNoMarkupDictionary();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.github.stscoundrel.oldicelandicdictionary;

import com.google.gson.annotations.SerializedName;

public class DictionaryEntry {
@SerializedName("a")
public String headword;

@SerializedName("b")
public String[] definitions;
}
1 change: 1 addition & 0 deletions src/main/resources/markup.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/resources/no-markup.json

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions src/test/java/com/github/stscoundrel/javatemplate/AppTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.github.stscoundrel.oldicelandicdictionary;

import junit.framework.TestCase;

public class DictionaryTest
extends TestCase {
public void testDefaultDictionaryHasExpectedAmountOfEntries() {
Dictionary dictionary = new Dictionary();
DictionaryEntry[] result = dictionary.getDictionary();

assertEquals(29951, result.length);
}

public void testMarkupDictionaryHasExpectedAmountOfEntries() {
Dictionary dictionary = new Dictionary();
DictionaryEntry[] result = dictionary.getMarkupDictionary();

assertEquals(29951, result.length);
}

public void testDictionaryHeadwordsMatch() {
Dictionary dictionary = new Dictionary();
DictionaryEntry[] noMarkupResult = dictionary.getDictionary();
DictionaryEntry[] markupResult = dictionary.getMarkupDictionary();

for (int i = 0; i < 29951; i++) {
assertEquals(noMarkupResult[i].headword, markupResult[i].headword);
}
}

public void testDictionaryHasExpectedContent() {
Dictionary dictionary = new Dictionary();
DictionaryEntry[] result = dictionary.getDictionary();

assertEquals("a", result[0].headword);
assertEquals("a negative suffix to verbs, not;", result[0].definitions[0]);
assertEquals("era útmakligt, at it is not unmeet that.", result[0].definitions[1]);

assertEquals("afbindi", result[14].headword);
assertEquals("n. constipation.", result[14].definitions[0]);

assertEquals("andstreymr", result[1000].headword);
assertEquals(
"a. strongly adverse (andstreym ørlög); Sighvatr var heldr ~ um eptirmálin, hard to come to terms with.",
result[1000].definitions[0]);

assertEquals("undanhald", result[25000].headword);
assertEquals("n. flight.", result[25000].definitions[0]);
}

public void testMarkupDictionaryHasExpectedContent() {
Dictionary dictionary = new Dictionary();
DictionaryEntry[] result = dictionary.getMarkupDictionary();

assertEquals("a", result[0].headword);
assertEquals("a negative suffix to verbs, <i>not</i>;", result[0].definitions[0]);
assertEquals("era útmakligt, <i>at it is not unmeet that</i>.", result[0].definitions[1]);

assertEquals("afbindi", result[14].headword);
assertEquals("n. <i>constipation</i>.", result[14].definitions[0]);

assertEquals("andstreymr", result[1000].headword);
assertEquals(
"a. <i>strongly adverse</i> (andstreym ørlög); Sighvatr var heldr ~ um eptirmálin, <i>hard to come to terms with</i>.",
result[1000].definitions[0]);

assertEquals("undanhald", result[25000].headword);
assertEquals("n. <i>flight</i>.", result[25000].definitions[0]);
}
}

0 comments on commit f0c86f8

Please sign in to comment.