forked from Merck/Halyard
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark Hale
committed
Oct 10, 2024
1 parent
70044c4
commit a4c42ee
Showing
6 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
model/src/main/java/com/msd/gin/halyard/model/vocabulary/APF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.msd.gin.halyard.model.vocabulary; | ||
|
||
import org.eclipse.rdf4j.model.IRI; | ||
import org.eclipse.rdf4j.model.Namespace; | ||
import org.eclipse.rdf4j.model.impl.SimpleNamespace; | ||
import org.eclipse.rdf4j.model.impl.SimpleValueFactory; | ||
import org.kohsuke.MetaInfServices; | ||
|
||
/** | ||
* http://jena.apache.org/ARQ/property#. | ||
*/ | ||
@MetaInfServices(Vocabulary.class) | ||
public final class APF implements Vocabulary { | ||
private static final SimpleValueFactory SVF = SimpleValueFactory.getInstance(); | ||
|
||
/** | ||
* http://jena.apache.org/ARQ/property# | ||
*/ | ||
public static final String NAMESPACE = "http://jena.apache.org/ARQ/property#"; | ||
|
||
public static final String PREFIX = "apf"; | ||
|
||
public static final Namespace NS = new SimpleNamespace(PREFIX, NAMESPACE); | ||
public static final IRI STR_SPLIT = SVF.createIRI(NAMESPACE, "strSplit"); | ||
public static final IRI CONCAT = SVF.createIRI(NAMESPACE, "concat"); | ||
public static final IRI SPLIT_IRI = SVF.createIRI(NAMESPACE, "splitIRI"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
spin/src/main/java/com/msd/gin/halyard/spin/function/apf/SplitIRI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.msd.gin.halyard.spin.function.apf; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.rdf4j.common.iteration.CloseableIteration; | ||
import org.eclipse.rdf4j.common.iteration.SingletonIteration; | ||
import org.eclipse.rdf4j.model.IRI; | ||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.model.ValueFactory; | ||
import org.eclipse.rdf4j.query.QueryEvaluationException; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.function.TupleFunction; | ||
|
||
import com.msd.gin.halyard.model.vocabulary.APF; | ||
|
||
public class SplitIRI implements TupleFunction { | ||
|
||
@Override | ||
public String getURI() { | ||
return APF.SPLIT_IRI.toString(); | ||
} | ||
|
||
@Override | ||
public CloseableIteration<? extends List<? extends Value>> evaluate(ValueFactory valueFactory, Value... args) throws QueryEvaluationException { | ||
if (args.length != 1 || !args[0].isIRI()) { | ||
throw new ValueExprEvaluationException(String.format("%s requires an IRI", getURI())); | ||
} | ||
IRI iri = (IRI) args[0]; | ||
return new SingletonIteration<List<? extends Value>>( | ||
Arrays.asList(valueFactory.createLiteral(iri.getNamespace()), valueFactory.createLiteral(iri.getLocalName()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
spin/src/test/java/com/msd/gin/halyard/spin/SailApfTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.msd.gin.halyard.spin; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.eclipse.rdf4j.query.BooleanQuery; | ||
import org.eclipse.rdf4j.query.QueryLanguage; | ||
import org.eclipse.rdf4j.repository.Repository; | ||
import org.eclipse.rdf4j.repository.RepositoryConnection; | ||
import org.eclipse.rdf4j.repository.sail.SailRepository; | ||
import org.eclipse.rdf4j.sail.Sail; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class SailApfTest { | ||
|
||
private Repository repo; | ||
|
||
private RepositoryConnection conn; | ||
|
||
@Before | ||
public final void setup() throws Exception { | ||
repo = new SailRepository(createSail()); | ||
repo.init(); | ||
conn = repo.getConnection(); | ||
} | ||
|
||
protected Sail createSail() throws Exception { | ||
return new SpinMemoryStore(); | ||
} | ||
|
||
@After | ||
public final void tearDown() throws Exception { | ||
if (conn != null) { | ||
conn.close(); | ||
} | ||
if (repo != null) { | ||
repo.shutDown(); | ||
} | ||
postCleanup(); | ||
} | ||
|
||
protected void postCleanup() throws Exception { | ||
} | ||
|
||
@Test | ||
public void testConcat() throws Exception { | ||
BooleanQuery bq = conn.prepareBooleanQuery(QueryLanguage.SPARQL, "prefix apf: <http://jena.apache.org/ARQ/property#> " + "ask where { ?y apf:concat ('Foo' ' ' 'Bar') filter(?y = 'Foo Bar')}"); | ||
assertTrue(bq.evaluate()); | ||
} | ||
|
||
@Test | ||
public void testStrSplit() throws Exception { | ||
BooleanQuery bq = conn.prepareBooleanQuery(QueryLanguage.SPARQL, "prefix apf: <http://jena.apache.org/ARQ/property#> " + "ask where { ?y apf:strSplit ('Foo Bar' '\\\\s+') filter(?y in ('Foo', 'Bar'))}"); | ||
assertTrue(bq.evaluate()); | ||
} | ||
|
||
@Test | ||
public void testSplitIRI() throws Exception { | ||
BooleanQuery bq = conn.prepareBooleanQuery(QueryLanguage.SPARQL, "prefix apf: <http://jena.apache.org/ARQ/property#> " + "ask where { apf:foobar apf:splitIRI (?ns ?ln) filter(?ns = str(apf:) && ?ln = 'foobar')}"); | ||
assertTrue(bq.evaluate()); | ||
} | ||
} |