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
3616c94
commit 110c102
Showing
5 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
...lgebra/src/main/java/com/msd/gin/halyard/query/algebra/evaluation/function/Serialize.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,28 @@ | ||
package com.msd.gin.halyard.query.algebra.evaluation.function; | ||
|
||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.model.ValueFactory; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.function.Function; | ||
import org.eclipse.rdf4j.rio.helpers.NTriplesUtil; | ||
import org.kohsuke.MetaInfServices; | ||
|
||
import com.msd.gin.halyard.model.vocabulary.HALYARD; | ||
|
||
@MetaInfServices(Function.class) | ||
public final class Serialize implements Function { | ||
|
||
@Override | ||
public String getURI() { | ||
return HALYARD.SERIALIZE_FUNCTION.stringValue(); | ||
} | ||
|
||
@Override | ||
public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { | ||
if (args.length != 1) { | ||
throw new ValueExprEvaluationException(String.format("%s requires 1 argument", getURI())); | ||
} | ||
return valueFactory.createLiteral(NTriplesUtil.toNTriplesString(args[0], true)); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...ra/src/test/java/com/msd/gin/halyard/query/algebra/evaluation/function/SerializeTest.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,22 @@ | ||
package com.msd.gin.halyard.query.algebra.evaluation.function; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.eclipse.rdf4j.model.Literal; | ||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.model.ValueFactory; | ||
import org.eclipse.rdf4j.query.algebra.evaluation.TripleSource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.msd.gin.halyard.query.algebra.evaluation.EmptyTripleSource; | ||
|
||
public class SerializeTest { | ||
@Test | ||
public void test() { | ||
TripleSource ts = new EmptyTripleSource(); | ||
ValueFactory vf = ts.getValueFactory(); | ||
Value v = vf.createTriple(vf.createIRI("http://whatever.com/subj"), vf.createIRI("http://whatever.com/pred"), vf.createLiteral("foobar")); | ||
Literal l = (Literal) new Serialize().evaluate(ts, v); | ||
assertEquals(vf.createLiteral("<<<http://whatever.com/subj> <http://whatever.com/pred> \"foobar\">>"), l); | ||
} | ||
} |
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