Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ on:
push:
branches:
- dev
pull_request:
branches:
- dev

jobs:
testDataload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '14'
java-version: '25'
distribution: 'adopt'
- name: Build with Maven
run: mvn clean package
Expand All @@ -23,5 +27,3 @@ jobs:
- uses: actions/checkout@v3
- name: Run API tests
run: ./test_api.sh


20 changes: 20 additions & 0 deletions dataload/rdf2json/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter-params</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter-engine</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>11</maven.compiler.target>
Expand Down
7 changes: 7 additions & 0 deletions dataload/rdf2json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
<artifactId>logback-classic</artifactId>
<version>1.4.11</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class ShortFormAnnotator {
private static final Logger logger = LoggerFactory.getLogger(ShortFormAnnotator.class);
private static final String oboPurlPrefix = "http://purl.obolibrary.org/obo/";

public static void annotateShortForms(OntologyGraph graph) {

Expand All @@ -36,7 +37,7 @@ public static void annotateShortForms(OntologyGraph graph) {
preferredPrefix = graph.config.get("id").toString().toUpperCase();
}

String shortForm = extractShortForm(graph, ontologyBaseUris, preferredPrefix, c.uri);
String shortForm = extractShortForm(ontologyBaseUris, preferredPrefix, c.uri);

/*
CURIEs are formed by following rules:
Expand Down Expand Up @@ -75,16 +76,26 @@ public static void annotateShortForms(OntologyGraph graph) {

}

private static String extractShortForm(OntologyGraph graph, Set<String> ontologyBaseUris, String preferredPrefix,
public static String extractShortForm(Set<String> ontologyBaseUris, String preferredPrefix,
String uri) {

if (uri.startsWith("urn:")) {
return uri.substring(4);
}

// if(uri.startsWith("http://purl.obolibrary.org/obo/")) {
// return uri.substring("http://purl.obolibrary.org/obo/".length());
// }
// Check if it's an ad-hoc member of an OBO space, for example, how
// http://obolibrary.org/obo/mesh#C is an ad-hoc member of the OBO
// mesh space or http://purl.obolibrary.org/obo/chebi#mass as an ad-hoc
// member of the OBO chebi space (not the same as the CHEBI space).
//
// For example, http://purl.obolibrary.org/obo/chebi#mass becomes
// obo:chebi#mass
//
// See further discussion at https://github.com/EBISPOT/ols4/issues/935.
String oboAdHocURIPrefix = oboPurlPrefix + preferredPrefix.toLowerCase() + "#";
if (uri.startsWith(oboAdHocURIPrefix)) {
return "obo:" + uri.substring(oboPurlPrefix.length());
}

for (String baseUri : ontologyBaseUris) {
if (uri.startsWith(baseUri) && preferredPrefix != null) {
Expand Down
41 changes: 41 additions & 0 deletions dataload/rdf2json/src/test/java/TestShortFormAnnotator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.junit.jupiter.api.Test;
import static uk.ac.ebi.rdf2json.annotators.ShortFormAnnotator.extractShortForm;
import java.util.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestShortFormAnnotator {
static Set<String> uriPrefixes = new HashSet<>() {{
add("http://purl.obolibrary.org/obo/TEST_");
}};

@Test
public void testURN() {
// Test slicing off front of URN
assertEquals("garbage", extractShortForm(uriPrefixes, "TEST", "urn:garbage"));
}

@Test
public void testOBODefaultNamespace() {
// Test OBO default namespaces (added in https://github.com/EBISPOT/ols4/pull/937)
assertEquals("obo:test#abc", extractShortForm(uriPrefixes, "TEST", "http://purl.obolibrary.org/obo/test#abc"));

// Reverts to the guess workflow
assertEquals("abc", extractShortForm(uriPrefixes, "XXX", "http://purl.obolibrary.org/obo/test#abc"));
}

@Test
public void testRegular() {
// Test regular parsing based, note that it takes the prefix given
assertEquals("XXX_1234567", extractShortForm(uriPrefixes, "XXX", "http://purl.obolibrary.org/obo/TEST_1234567"));
assertEquals("TEST_1234567", extractShortForm(uriPrefixes, "TEST", "http://purl.obolibrary.org/obo/TEST_1234567"));
}

@Test
public void testGuesses() {
// Guesses
assertEquals("1234567", extractShortForm(uriPrefixes, "XXX", "http://example.org/1234567"));
assertEquals("1234567", extractShortForm(uriPrefixes, "TEST", "http://example.org/1234567"));
assertEquals("1234567", extractShortForm(uriPrefixes, "XXX", "http://example.org/any.html#1234567"));
assertEquals("1234567", extractShortForm(uriPrefixes, "TEST", "http://example.org/any.html#1234567"));
}
}
Loading