-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to generate markdown files, could be for github pages
- Loading branch information
1 parent
eaaf5fe
commit bf1c111
Showing
5 changed files
with
107 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target/ | ||
/examples_*.ttl | ||
/examples/**/*.rq | ||
/examples/**/*.md |
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
49 changes: 49 additions & 0 deletions
49
src/main/java/swiss/sib/rdf/sparql/examples/SparqlInRdfToMd.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,49 @@ | ||
package swiss.sib.rdf.sparql.examples; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import java.util.stream.StreamSupport; | ||
|
||
import org.eclipse.rdf4j.model.IRI; | ||
import org.eclipse.rdf4j.model.Model; | ||
import org.eclipse.rdf4j.model.Resource; | ||
import org.eclipse.rdf4j.model.Statement; | ||
import org.eclipse.rdf4j.model.Value; | ||
import org.eclipse.rdf4j.model.impl.SimpleValueFactory; | ||
import org.eclipse.rdf4j.model.vocabulary.RDF; | ||
import org.eclipse.rdf4j.model.vocabulary.RDFS; | ||
import org.eclipse.rdf4j.model.vocabulary.SHACL; | ||
|
||
public class SparqlInRdfToMd { | ||
private static final IRI KEYWORD = SimpleValueFactory.getInstance().createIRI("https://schema.org/keyword"); | ||
|
||
|
||
public static List<String> asRq(Model ex) { | ||
List<String> rq = new ArrayList<>(); | ||
|
||
streamOf(ex, null, RDF.TYPE, SHACL.SPARQL_EXECUTABLE).map(Statement::getSubject).distinct() | ||
.forEach(s -> { | ||
rq.add("# "+s.stringValue()+"\n"); | ||
streamOf(ex, s, KEYWORD, null).map(Statement::getObject).map(Value::stringValue) | ||
.map(k -> " * " + k) | ||
.forEach(rq::add); | ||
streamOf(ex, s, RDFS.COMMENT, null).map(Statement::getObject).map(Value::stringValue).forEach(rq::add); | ||
rq.add("\n"); | ||
rq.add("```sparql"); | ||
Stream.of(SHACL.ASK, SHACL.SELECT, SHACL.CONSTRUCT, SIB.DESCRIBE) | ||
.flatMap(qt -> streamOf(ex, s, qt, null)).map(Statement::getObject) | ||
.map(o -> o.stringValue()).forEach(q ->SparqlInRdfToRq.addPrefixes(q, ex, rq)); | ||
rq.add("```"); | ||
}); | ||
return rq; | ||
} | ||
|
||
|
||
|
||
private static Stream<Statement> streamOf(Model ex, Resource s, IRI p, Value o) { | ||
return StreamSupport.stream(ex.getStatements(s, p, o).spliterator(), false); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/test/java/swiss/sib/rdf/sparql/examples/SparqlInRdfToRqTest.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 swiss.sib.rdf.sparql.examples; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class SparqlInRdfToRqTest { | ||
|
||
@Test | ||
public void prefixInQuery() { | ||
String q =""" | ||
SELECT ?taxon | ||
FROM <http://sparql.uniprot.org/taxonomy> | ||
WHERE | ||
{ | ||
?taxon a up:Taxon . | ||
}"""; | ||
assertTrue(SparqlInRdfToRq.queryContainsPrefix(q, "up:"), "up: (uniprot) is in the query"); | ||
assertFalse(SparqlInRdfToRq.queryContainsPrefix(q, "p:"), "p: (wikidata) not in the query"); | ||
} | ||
} |