Skip to content

Commit bef82b0

Browse files
committed
sssom-cli: Add new --cardinality option.
Replace the binary option `--force-cardinality` option with a new option `--cardinality` that accepts three values: * REMOVE, to forcefully remove the `mapping_cardinality` slot from the result set (default behaviour); * FORCE, to include freshly computed cardinality values (same behaviour as the old `--force-cardinality` option); * KEEP, to do nothing special with cardinality, just leaving any existing value untouched (new behaviour).
1 parent 45ce4c8 commit bef82b0

File tree

6 files changed

+106
-9
lines changed

6 files changed

+106
-9
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SSSOM-Java - SSSOM library for Java
3+
* Copyright © 2025 Damien Goutte-Gattat
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package org.incenp.obofoundry.sssom.cli;
20+
21+
/**
22+
* Possible behaviours regarding existing {@code mapping_cardinality} values.
23+
*/
24+
public enum CardinalityOption {
25+
/**
26+
* Remove the {@code mapping_cardinality} slot from the output completely.
27+
*/
28+
REMOVE,
29+
30+
/**
31+
* Leave any existing {@code mapping_cardinality} slot untouched.
32+
*/
33+
KEEP,
34+
35+
/**
36+
* Write freshly computed cardinality values (overwriting any existing value).
37+
*/
38+
FORCE
39+
}

cli/src/main/java/org/incenp/obofoundry/sssom/cli/SimpleCLI.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,17 @@ private static class OutputOptions {
193193
description = "Split the set along subject and object prefix names and write the split sets in the specified directory.")
194194
String splitDirectory;
195195

196-
@Option(names = { "-c", "--force-cardinality" }, description = "Include mapping cardinality values.")
197-
boolean forceCardinality;
196+
@Option(names = { "-c", "--force-cardinality" },
197+
hidden = true,
198+
description = "Include mapping cardinality values.")
199+
private void forceCardinality(boolean value) {
200+
cardinality = CardinalityOption.FORCE;
201+
}
202+
203+
@Option(names = {"-C", "--cardinality" },
204+
paramLabel = "OPT",
205+
description = "What to do with mapping cardinality values. Possible options: ${COMPLETION-CANDIDATES}. Default is REMOVE.")
206+
CardinalityOption cardinality = CardinalityOption.REMOVE;
198207

199208
@Option(names = "--output-prefix-map",
200209
paramLabel = "SRC",
@@ -496,9 +505,9 @@ private File getCatalogFile(String userSpecified, String defaultFile) {
496505
}
497506

498507
private void postProcess(MappingSet ms) {
499-
if ( outputOpts.forceCardinality ) {
508+
if ( outputOpts.cardinality == CardinalityOption.FORCE ) {
500509
new Cardinalizer().fillCardinality(ms.getMappings());
501-
} else {
510+
} else if ( outputOpts.cardinality == CardinalityOption.REMOVE ) {
502511
ms.getMappings().forEach(mapping -> mapping.setMappingCardinality(null));
503512
}
504513

cli/src/site/apt/index.apt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ sssom-cli set.sssom.tsv:metadata.yaml
324324
computed on the fly whenever needed, because pre-computed values found
325325
in a set may not be reliable (if the composition of the set has
326326
changed since the values were computed). Use the
327-
<<<--force-cardinality>>> option to include the
328-
<<<mapping_cardinality>>> slot in the result set. In that case, what
329-
will be written will always be the <effective> cardinality for each
330-
mapping, computed at the last moment before writing the set (in
331-
particular, after any transformation of the set).
327+
<<<--cardinality keep>>> option to include the
328+
<<<mapping_cardinality>>> slot in the result set, or
329+
<<<--cardinality force>>> to not only include the slot, but also
330+
compute the <effective> cardinality for each mapping (computed at the
331+
last moment before writing the set – in particular, after any
332+
transformation of the set).
332333

333334
The result set is always <sorted>, so that the mappings are written in
334335
a completely deterministic order. Use the <<<--no-sorting>>> option to

cli/src/test/java/org/incenp/obofoundry/sssom/cli/SSSOMCLITest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ void testWritingOutCardinality() throws IOException {
174174
// We merge the three O2C, O2N, and C2N sets to have a range of cardinalities
175175
TestUtils.runCommand(0, new String[] { "exo2c.sssom.tsv", "exo2n.sssom.tsv", "exc2n.sssom.tsv" },
176176
"exall-cardinality.sssom.tsv", new String[] { "--force-cardinality" });
177+
178+
// Same, but using the new --cardinality option.
179+
TestUtils.runCommand(0, new String[] { "exo2c.sssom.tsv", "exo2n.sssom.tsv", "exc2n.sssom.tsv" },
180+
"exall-cardinality.sssom.tsv", new String[] { "--cardinality", "force" });
181+
}
182+
183+
@Test
184+
void testKeepingCardinalityValues() throws IOException {
185+
TestUtils.runCommand(0, new String[] { "exo2c-with-cardinality.sssom.tsv" },
186+
"test-keeping-cardinality.sssom.tsv", new String[] { "--cardinality", "keep" });
177187
}
178188

179189
@Test
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#curie_map:
2+
# COMENT: https://example.com/entities/
3+
# ORGENT: https://example.org/entities/
4+
# ORGPID: https://example.org/people/
5+
#mapping_set_id: https://example.org/sets/exo2c
6+
#mapping_set_title: O2C set
7+
#creator_id:
8+
# - ORGPID:0000-0000-0001-1234
9+
#license: https://creativecommons.org/licenses/by/4.0/
10+
#publication_date: 2023-09-13
11+
subject_id subject_label predicate_id object_id object_label mapping_justification mapping_cardinality
12+
ORGENT:0001 alice skos:closeMatch COMENT:0011 alpha semapv:ManualMappingCuration 1:1
13+
ORGENT:0002 bob skos:closeMatch COMENT:0012 beta semapv:ManualMappingCuration 1:1
14+
ORGENT:0004 daphne skos:closeMatch COMENT:0014 delta semapv:ManualMappingCuration 1:1
15+
ORGENT:0005 eve skos:closeMatch COMENT:0015 epsilon semapv:ManualMappingCuration 1:1
16+
ORGENT:0006 fanny skos:closeMatch COMENT:0016 zeta semapv:ManualMappingCuration 1:1
17+
ORGENT:0007 gavin skos:exactMatch COMENT:0013 gamma semapv:ManualMappingCuration 1:1
18+
ORGENT:0008 hector skos:closeMatch COMENT:0017 eta semapv:ManualMappingCuration 1:1
19+
ORGENT:0009 ivan skos:exactMatch COMENT:0019 iota semapv:ManualMappingCuration 1:1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#curie_map:
2+
# COMENT: https://example.com/entities/
3+
# ORGENT: https://example.org/entities/
4+
# ORGPID: https://example.org/people/
5+
#mapping_set_id: https://example.org/sets/exo2c
6+
#mapping_set_title: O2C set
7+
#creator_id:
8+
# - ORGPID:0000-0000-0001-1234
9+
#license: https://creativecommons.org/licenses/by/4.0/
10+
#publication_date: 2023-09-13
11+
subject_id subject_label predicate_id object_id object_label mapping_justification mapping_cardinality
12+
ORGENT:0001 alice skos:closeMatch COMENT:0011 alpha semapv:ManualMappingCuration 1:1
13+
ORGENT:0002 bob skos:closeMatch COMENT:0012 beta semapv:ManualMappingCuration 1:1
14+
ORGENT:0004 daphne skos:closeMatch COMENT:0014 delta semapv:ManualMappingCuration 1:1
15+
ORGENT:0005 eve skos:closeMatch COMENT:0015 epsilon semapv:ManualMappingCuration 1:1
16+
ORGENT:0006 fanny skos:closeMatch COMENT:0016 zeta semapv:ManualMappingCuration 1:1
17+
ORGENT:0007 gavin skos:exactMatch COMENT:0013 gamma semapv:ManualMappingCuration 1:1
18+
ORGENT:0008 hector skos:closeMatch COMENT:0017 eta semapv:ManualMappingCuration 1:1
19+
ORGENT:0009 ivan skos:exactMatch COMENT:0019 iota semapv:ManualMappingCuration 1:1

0 commit comments

Comments
 (0)