Skip to content

Commit

Permalink
Add the --default-new-language option.
Browse files Browse the repository at this point in the history
Adds a new option `--default-new-language` to the `apply` ROBOT command.
The option expects a language tag. When it is used, the specified
language tag is assigned to the new value of any NodeChange operation
that does not have an explicit language tag already.
  • Loading branch information
gouttegd committed Mar 14, 2024
1 parent 3225b89 commit a681450
Show file tree
Hide file tree
Showing 5 changed files with 2,397 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/site/apt/robot.apt
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ $ robot merge -i input1.ofn -i input2.ofn \
applied. As for other ROBOT commands that need a reasoner, the
reasoner to use can be specified with the <<<--reasoner>>> (or
<<<-r>>>) option. The default reasoner is <ELK>.

If the <<<--default-new-language>>> option is specified, any
NodeChange operation that does not have an explicit language tag will
use the specified default new language tag.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.incenp.obofoundry.kgcl.KGCLWriter;
import org.incenp.obofoundry.kgcl.RejectedChange;
import org.incenp.obofoundry.kgcl.model.Change;
import org.incenp.obofoundry.kgcl.model.NodeChange;
import org.obolibrary.robot.Command;
import org.obolibrary.robot.CommandLineHelper;
import org.obolibrary.robot.CommandState;
Expand Down Expand Up @@ -64,6 +65,7 @@ public ApplyCommand() {
options.addOption("r", "reasoner", true, "reasoner to use");
options.addOption("p", "provisional", false, "Apply changes in a provisional manner");
options.addOption("P", "pending", true, "Apply pending (provisional) changes older than the specified date");
options.addOption("l", "default-new-language", true, "Use the specified new language tag by default");
}

@Override
Expand Down Expand Up @@ -145,6 +147,17 @@ public CommandState execute(CommandState state, String[] args) throws Exception
changeset.addAll(KGCLHelper.extractPendingChanges(ontology, before));
}

if ( line.hasOption("default-new-language") ) {
for ( Change change : changeset ) {
if ( change instanceof NodeChange ) {
NodeChange nc = (NodeChange) change;
if ( nc.getNewLanguage() == null ) {
nc.setNewLanguage(line.getOptionValue("default-new-language"));
}
}
}
}

if ( changeset.size() > 0 ) {
List<RejectedChange> rejects = new ArrayList<RejectedChange>();
KGCLHelper.apply(changeset, ontology, reasoner, line.hasOption("no-partial-apply"), rejects,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ void testExplicitNoRejectFile() {
Assertions.assertFalse(rejectFile.exists());
}

@Test
void testNoDefaultLanguageTag() {
runCommand("pizza.ofn", "pizza-renamed-reine-all-langs.ofn", "--kgcl",
"rename pizza:LaReine from 'LaReine' to 'TheQueen'");
}

@Test
void testDefaultLanguageTag() {
runCommand("pizza.ofn", "pizza-renamed-reine-english-only.ofn", "--kgcl",
"rename pizza:LaReine from 'LaReine' to 'TheQueen'", "--default-new-language", "en");
}

/*
* Try running a KGCL-Apply command and check that the output ontology matches
* what we expect.
Expand Down
Loading

0 comments on commit a681450

Please sign in to comment.