Skip to content

Instantly share code, notes, and snippets.

@abrokenjester
Created December 18, 2019 08:23
Show Gist options
  • Save abrokenjester/2d331d77c9b03fcbbc331f7da798e0ad to your computer and use it in GitHub Desktop.
Save abrokenjester/2d331d77c9b03fcbbc331f7da798e0ad to your computer and use it in GitHub Desktop.
simple app using rdf4j to export contents of repository to Turtle file, with blank nodes inlined
import org.eclipse.rdf4j.query.QueryResults;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFWriter;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.helpers.BasicParserSettings;
import org.eclipse.rdf4j.rio.helpers.BasicWriterSettings;
import org.eclipse.rdf4j.sail.memory.MemoryStore;
import java.io.IOException;
public class App
{
public static void main( String[] args ) throws IOException {
Repository rep = new SailRepository(new MemoryStore());
try (RepositoryConnection conn = rep.getConnection()) {
conn.add(App.class.getResourceAsStream("/artists_data.ttl"), "", RDFFormat.TURTLE);
conn.add(App.class.getResourceAsStream("/artists_data_comp.ttl"), "", RDFFormat.TURTLE);
RDFWriter writer = Rio.createWriter(RDFFormat.TURTLE, System.out);
// use pretty-printing (nice indentation)
writer.getWriterConfig().set(BasicWriterSettings.PRETTY_PRINT, true);
// inline blank nodes where possible
writer.getWriterConfig().set(BasicWriterSettings.INLINE_BLANK_NODES, true);
conn.export(writer);
}
}
}
@prefix ex: <https://ax1tpschgs.proxynodejs.usequeue.com/> .
@prefix foaf: <https://o6sof3tfg6.proxynodejs.usequeue.com/foaf/0.1/> .
@prefix rdf: <https://nt6nqxrxfq.proxynodejs.usequeue.com/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <https://nt6nqxrxfq.proxynodejs.usequeue.com/2000/01/rdf-schema#> .
ex:Picasso a ex:Artist, foaf:Person;
ex:creatorOf ex:crossedArms, ex:guernica, ex:maJolie, ex:weepingWoman;
ex:homeAddress [
ex:birthCity "Malaga";
ex:city "Madrid";
ex:country "Spain";
ex:street "31 Art Gallery"
], [
ex:city "Madrid";
ex:country "Spain";
ex:street "31 Art Gallery"
];
foaf:firstName "Pablo";
foaf:surname "Picasso" .
ex:VanGogh a ex:Artist, foaf:Person;
ex:creatorOf ex:lumberSale, ex:minersInTheSnow, ex:potatoEaters, ex:starryNight, ex:sundayEindhoven,
ex:sunflowers;
ex:homeAddress [
ex:city "Zundert";
ex:country "Netherlands";
ex:street "12 Rijsbergen"
];
foaf:firstName "Vincent";
foaf:surname "van Gogh" .
ex:guernica a ex:Painting;
ex:paintingTechnique ex:oil;
ex:technique "oil on canvas";
rdfs:label "Guernica" .
ex:maJolie a ex:Painting;
ex:paintingTechnique ex:oil;
rdfs:label "Ma Jolie" .
ex:crossedArms a ex:Painting;
ex:paintingTechnique ex:watercolor;
rdfs:label "Man with crossed arms" .
ex:sundayEindhoven a ex:Painting;
ex:paintingTechnique ex:watercolor;
rdfs:label "A Sunday in Eindhoven" .
ex:starryNight a ex:Painting;
ex:paintingTechnique ex:oil;
rdfs:label "Starry Night" .
ex:sunflowers a ex:Painting;
ex:paintingTechnique ex:oil;
rdfs:label "Sunflowers" .
ex:potatoEaters a ex:Painting;
ex:paintingTechnique ex:oil;
rdfs:label "The Potato Eaters" .
ex:minersInTheSnow a ex:Painting;
ex:paintingTechnique ex:watercolor;
rdfs:label "Miners in the Snow: Winter" .
ex:paintingTechnique a rdfs:Class .
ex:oil a rdfs:class;
rdfs:subClassOf ex:paintingTechnique .
ex:acrylic a rdfs:Class;
rdfs:subClassOf ex:paintingTechnique .
ex:watercolor a rdfs:Class;
rdfs:subClassOf ex:paintingTechnique .
ex:weepingWoman a ex:Painting;
ex:technique "oil on canvas";
rdfs:label "The weeping woman" .
ex:lumberSale a ex:Painting;
ex:technique "watercolor";
rdfs:label "Lumber Sale" .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment