Skip to content

Commit f8b828b

Browse files
committed
Add the upper and lower format modifier functions.
Add a generic mechanism to easily create new simple format modifiers, and use it to two new format modifiers to transform the substituted text into lower case or upper case.
1 parent 21fda3b commit f8b828b

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

ext/src/main/java/org/incenp/obofoundry/sssom/transform/MappingFormatter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public void setStandardModifiers() {
234234
setModifier(new SSSOMTFlattenFunction());
235235
setModifier(new SSSOMTDefaultModifierFunction());
236236
setModifier(new SSSOMTReplaceModifierFunction());
237+
setModifier(new SimpleStringModifierFunction("upper", (s) -> s.toUpperCase()));
238+
setModifier(new SimpleStringModifierFunction("lower", (s) -> s.toLowerCase()));
237239
if ( pfxMgr != null ) {
238240
setModifier(new SSSOMTShortFunction(pfxMgr));
239241
setModifier(new SSSOMTPrefixFunction(pfxMgr));
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.transform;
20+
21+
import java.util.List;
22+
import java.util.function.Function;
23+
24+
/**
25+
* Represents a simple format modifier function that does not take any argument.
26+
* <p>
27+
* This class is intended to allow creating simple modifiers without having to
28+
* create a new dedicated class. For example, to create a modifier that turns
29+
* its input into lowercase:
30+
*
31+
* <pre>
32+
* new SimpleStringModifierFunction("lower", (input) -&gt; input.toLowerCase());
33+
* </pre>
34+
*/
35+
public class SimpleStringModifierFunction extends BaseStringModifierFunction {
36+
37+
private String name;
38+
private Function<String, String> func;
39+
40+
/**
41+
* Creates a new instance.
42+
*
43+
* @param name The name of the modifier function to create.
44+
* @param func The implementation of the function.
45+
*/
46+
public SimpleStringModifierFunction(String name, Function<String, String> func) {
47+
this.name = name;
48+
this.func = func;
49+
}
50+
51+
@Override
52+
public String getName() {
53+
return name;
54+
}
55+
56+
@Override
57+
public String getSignature() {
58+
return "";
59+
}
60+
61+
@Override
62+
protected String apply(Object value, List<String> extra) {
63+
return func.apply(value.toString());
64+
}
65+
66+
}

ext/src/site/apt/sssom-transform.apt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,11 @@ predicate==* -> replace("object_id", "https://meshb.nlm.nih.gov/record/ui[?]ui="
10341034
shortened identifier to keep only the suffix (also known as the “local
10351035
name”).
10361036

1037+
*** 6.5.9. <lower> and <upper>
1038+
1039+
These modifiers turn the substituted text into lower case and upper
1040+
case, respectively.
1041+
10371042
* 7. Grouping rules
10381043

10391044
If several actions need to be performed on the same selection of

0 commit comments

Comments
 (0)