Skip to content

Commit

Permalink
OndexRDFUtils.iri(), bugfixing.
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-brandizi committed Mar 11, 2024
1 parent 58ee8fe commit 08e41b1
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
MATCH
(toterm:TO {
iri: bkr + "to_0000233",
(toterm:TO {
prefName: "root volume",
altName: "RTVOL",
comment: "Is an indirect measure of root mass or density. Quantified in terms of cubic centimeters by water displacement method. ( Reference: GR:pj GR_REF:6917 )"
}) - [ :is_a ] -> ( :TO { identifier: "TO:0000043" } ),

(toterm) - [:identifier] -> (:Accession{ identifier: "TO:0000233" } )
- [:dataSource] -> ({ iri: bk + "TO" })

WHERE toterm.iri =~ bkr + "to_0000233.+"

RETURN
COUNT ( toterm ) = 1
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ public static String iri ( String ns, String classPart, String acc, int id, bool
.map ( StringUtils::trimToNull )
.map ( String::toLowerCase )
// To prevent cases like GO_GO:1234
.filter ( a -> !a.startsWith ( classPartNew ) )
.map ( OndexRDFUtils::idEncode )
.map ( a -> forceIdAddition ? a + "_" + id : a )
.orElse ( "" + id );

return ns + classPartNew + "_" + idPart;

return ns
// To prevent cases like GO_GO:1234
+ (idPart.startsWith ( classPartNew ) ? "" : classPartNew + "_" )
+ idPart;
}

/**
Expand All @@ -84,6 +86,7 @@ public static String iri ( String ns, String classPart, String acc, int id )

/**
* Don't use an ID, assuming the acc parameter is non empty.
* @throws NullPointerException when acc is null
* @throws IllegalArgumentException when acc is empty.
*
* This is a wrapper of {@link #iri(String, String, String, int, boolean)}.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package net.sourceforge.ondex.rdf;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
* TODO: comment me!
*
* @author Marco Brandizi
* <dl><dt>Date:</dt><dd>11 Mar 2024</dd></dl>
*
*/
public class OndexRDFUtilsTest
{
private static String NS = "http://foo.com/test/";

@Test
public void testIri ()
{
String cls = "TestConcept", acc = "A00";
int id = 1;

var iri = OndexRDFUtils.iri ( NS, cls, acc, id, false );
assertEquals ( "iri() failed!", (NS + cls + "_" + acc).toLowerCase (), iri );
}

@Test
public void testIriForceId ()
{
String cls = "TestConcept", acc = "A00";
int id = 1;

var iri = OndexRDFUtils.iri ( NS, cls, acc, id );
assertEquals ( "iri() failed!", (NS + cls + "_" + acc + "_" + id).toLowerCase (), iri );
}

@Test
public void testIriNoAcc ()
{
String cls = "TestConcept", acc = " ";
int id = 1;

var iri = OndexRDFUtils.iri ( NS, cls, acc, id );
assertEquals ( "iri() failed!", (NS + cls + "_" + id).toLowerCase (), iri );
}

@Test
public void testIriNoId ()
{
String cls = "TestConcept", acc = "A01";

var iri = OndexRDFUtils.iri ( NS, cls, acc );
assertEquals ( "iri() failed!", (NS + cls + "_" + acc).toLowerCase (), iri );
}

@Test ( expected = NullPointerException.class )
public void testIriNoAccNoId ()
{
String cls = "TestConcept";

OndexRDFUtils.iri ( NS, cls, null );
}

@Test
public void testIriRepeatedClass ()
{
String cls = "FOO", accCode = "001", acc = "FOO:" + accCode;
int id = 1;

var iri = OndexRDFUtils.iri ( NS, cls, acc, id );
assertEquals ( "iri() failed!",
(NS + cls + "_" + accCode + "_" + id).toLowerCase (),
iri
);
}

}

0 comments on commit 08e41b1

Please sign in to comment.