Skip to content

Commit

Permalink
fixing format for hp international parser
Browse files Browse the repository at this point in the history
  • Loading branch information
pnrobinson committed Jul 2, 2024
1 parent 46f24e1 commit 52c7baa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class HpInternationalOboParser {
* @param annots a String such as source:value="Split hand", translation:status="OFFICIAL", source:language="en", translation:language="tr"}
* @return in this case "tr"
*/
public Optional<String> getLanguage(String annots) {
final String translation = "translation:language=\"(\\w{2,3})\"";
public static Optional<String> getLanguage(String annots) {
final String translation = "babelon:translation_language=\"(\\w{2,3})\"";
final Pattern pattern = Pattern.compile(translation);
Matcher matcher = pattern.matcher(annots);
if (matcher.find()) {
Expand All @@ -38,17 +38,6 @@ public Optional<String> getLanguage(String annots) {
}
}

public Optional<String> getTranslation(String annots) {
final String translation = "translation:language=\"(\\w{2,2})\"";
final Pattern pattern = Pattern.compile(translation);
Matcher matcher = pattern.matcher(annots);
if (matcher.find()) {
String language = matcher.group(1);
return Optional.of(language);
} else {
return Optional.empty();
}
}

public HpInternationalOboParser(File file) {
languageToInternationalMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,42 @@

import org.junit.jupiter.api.Test;

import java.io.File;
import java.net.URL;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;

public class HpInternationalOboParserTest {
private static final String pbpoPath = "data/small-hp-international.obo";
/*private static final String pbpoPath = "data/small-hp-international.obo";
private static final ClassLoader classLoader = HpInternationalOboParserTest.class.getClassLoader();
private static final URL resource = (classLoader.getResource(pbpoPath));
private static final File file = new File(resource.getFile());
private static final HpInternationalOboParser parser = new HpInternationalOboParser(file);
@Test
public void testParser() {
assertNotNull(parser);
} */

@Test
public void testSpanish() {
String line = "name: Displasia renal multiquística {babelon:source_value=\"Multicystic kidney dysplasia\", babelon:translation_status=\"OFFICIAL\", babelon:source_language=\"en\", babelon:translation_language=\"es\"}";
Optional<String> opt = HpInternationalOboParser.getLanguage(line);
assertTrue(opt.isPresent());
String lang = opt.get();
assertEquals("es", lang);
}


@Test
public void testLanguage() {
String line = "name: 手劈裂 {source:value=\"Split hand\", translation:status=\"OFFICIAL\", source:language=\"en\", translation:language=\"zh\"}";
Optional<String> opt = parser.getLanguage(line);
public void testDutch() {
String line = "babelon:translation_status=\"CANDIDATE\", babelon:source_value=\"All\", babelon:source_language=\"en\", babelon:translation_language=\"nl\"}";
Optional<String> opt = HpInternationalOboParser.getLanguage(line);
assertTrue(opt.isPresent());
String lang = opt.get();
assertEquals("zh", lang);
assertEquals("nl", lang);

}

}

0 comments on commit 52c7baa

Please sign in to comment.