Skip to content

Commit

Permalink
add support for path authorship columns in output schema; related to g…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Apr 20, 2024
1 parent 3bf7ed0 commit 52d6655
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import picocli.CommandLine;

import static org.globalbioticinteractions.nomer.cmd.CmdMatcherParams.NOMER_SCHEMA_INPUT;

@CommandLine.Command(
name = "input-schema",
description = "Show input schema in JSON."
Expand All @@ -10,7 +12,7 @@ public class CmdInputSchema extends CmdProperties {

@Override
public void run() {
String property = getProperties().getProperty("nomer.schema.input");
String property = getProperties().getProperty(NOMER_SCHEMA_INPUT);
System.out.println(property);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

public abstract class CmdMatcherParams extends TermMatcherContextCaching implements Runnable {

public static final String NOMER_SCHEMA_INPUT = "nomer.schema.input";
public static final String NOMER_SCHEMA_OUTPUT = "nomer.schema.output";
@CommandLine.Parameters(description = "[matcher]", arity = "1")
private List<String> matchers = new ArrayList<>();

Expand All @@ -34,12 +36,12 @@ public List<String> getMatchers() {

@Override
public Map<Integer, String> getInputSchema() {
return parseSchema(getProperty("nomer.schema.input"));
return parseSchema(getProperty(NOMER_SCHEMA_INPUT));
}

@Override
public Map<Integer, String> getOutputSchema() {
return parseSchema(getProperty("nomer.schema.output"));
return parseSchema(getProperty(NOMER_SCHEMA_OUTPUT));
}

public static Map<Integer, String> parseSchema(String schema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import picocli.CommandLine;

import static org.globalbioticinteractions.nomer.cmd.CmdMatcherParams.NOMER_SCHEMA_OUTPUT;

@CommandLine.Command(name = "output-schema", description = "Show output schema in JSON.")
public class CmdOutputSchema extends CmdProperties {

@Override
public void run() {
System.out.println(getProperties().getProperty("nomer.schema.output"));
System.out.println(getProperties().getProperty(NOMER_SCHEMA_OUTPUT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static String valueForTaxonProperty(Taxon taxon,
List<String> ranks = splitAndTrim(taxon.getPathNames());
List<String> ids = splitAndTrim(taxon.getPathIds());
List<String> names = splitAndTrim(taxon.getPath());
List<String> authorships = splitAndTrim(taxon.getPathAuthorships());
String colValue = "";
if (StringUtils.equalsIgnoreCase(taxonPropertyName, "id")) {
colValue = taxon.getExternalId();
Expand Down Expand Up @@ -67,10 +68,14 @@ public static String valueForTaxonProperty(Taxon taxon,
int i1 = ranks.indexOf(rank);
if (i1 > -1) {
if (split.length > 2) {
boolean shouldUseId = "id".equalsIgnoreCase(split[2]);
colValue = shouldUseId
? ids.get(i1)
: names.get(i1);
String propertyName = split[2];
if ("id".equalsIgnoreCase(propertyName)) {
colValue = ids.get(i1);
} else if ("name".equalsIgnoreCase(propertyName)) {
colValue = names.get(i1);
} else if ("authorship".equalsIgnoreCase(propertyName)) {
colValue = authorships.get(i1);
}
} else {
colValue = rank;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ public void getUnknownKingdomFromPath() {
assertThat(kingdomName, is(""));
}

@Test
public void getKnownKingdomFromPath() {
TaxonImpl taxon = new TaxonImpl("someName", "someId");
taxon.setPathNames("kingdom | genus | species");
taxon.setPath("someKingdom | someGenus | someSpecies");
taxon.setPathIds("foo:0 | foo:1 | foo:2");
taxon.setPathAuthorships("Doe 2013 | Smith 2031 | Johnson 2012");
String kingdomName = AppenderUtil.valueForTaxonProperty(
taxon,
"path.kingdom.name");

assertThat(kingdomName, is("someKingdom"));

String authorship = AppenderUtil.valueForTaxonProperty(
taxon,
"path.kingdom.authorship");

assertThat(authorship, is("Doe 2013"));
}

@Test
public void getUnknownAuthorship() {
TaxonImpl taxon = new TaxonImpl("someName", "someId");
Expand Down

0 comments on commit 52d6655

Please sign in to comment.