Skip to content

Commit

Permalink
Deleted deprecated constructor. See #190 also preparing for #187
Browse files Browse the repository at this point in the history
  • Loading branch information
enridaga committed Jan 24, 2022
1 parent 9934bc4 commit 49868e4
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,60 +49,31 @@ public class FolderTriplifier implements Triplifier {

@Override
public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder) throws IOException {
// TODO Not implemented yet
return triplify(properties);
}

@Override
public DatasetGraph triplify(Properties properties) throws IOException {
DatasetGraph dg = DatasetGraphFactory.create();

URL url = Triplifier.getLocation(properties);

if (url == null)
return dg;

String root = Triplifier.getRootArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
String dataSourceId = root;
String matches = properties.getProperty(ZipTriplifier.MATCHES, ".*");

logger.trace("BN nodes {}", blank_nodes);
logger.trace("Matches {}", matches);

Node rootResource;
if (!blank_nodes) {
if (root == null) {
rootResource = NodeFactory.createURI(url.toString());
} else {
rootResource = NodeFactory.createURI(root);
}
} else {
rootResource = NodeFactory.createBlankNode();
}

Graph g = GraphFactory.createDefaultGraph();
g.add(new Triple(rootResource, RDF.type.asNode(), NodeFactory.createURI(Triplifier.FACADE_X_TYPE_ROOT)));
builder.addRoot(dataSourceId, root);

try {
Path path = Paths.get(url.toURI());
AtomicInteger i = new AtomicInteger(1);
Files.walk(path).forEach(p -> {
logger.trace("{} matches? {}", p.toString(), path.toString().matches(matches));
if (p.toString().matches(matches)) {
g.add(new Triple(rootResource, RDF.li(i.getAndIncrement()).asNode(),
NodeFactory.createLiteral(p.toUri().toString())));
builder.addValue(dataSourceId, root, i.getAndIncrement(), p.toUri().toString());
}

});

} catch (URISyntaxException e) {
e.printStackTrace();
}

dg.setDefaultGraph(g);
dg.addGraph(NodeFactory.createURI(url.toString()), g);

return dg;
return builder.getDatasetGraph();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,24 @@ public class TarTriplifier implements Triplifier {

@Override
public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder) throws IOException {
// TODO Not implemented yet
return triplify(properties);
}

@Override
public DatasetGraph triplify(Properties properties) throws IOException {
DatasetGraph dg = DatasetGraphFactory.create();

URL url = Triplifier.getLocation(properties);

if (url == null)
return dg;

String root = Triplifier.getRootArgument(properties);
URL location = Triplifier.getLocation(properties);
Charset charset = Triplifier.getCharsetArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
String root = Triplifier.getRootArgument(properties);
String dataSourceId = root;
String matches = properties.getProperty(ZipTriplifier.MATCHES, ".*");

logger.trace("BN nodes {}", blank_nodes);

Node rootResource;
if (!blank_nodes) {
if (root == null) {
rootResource = NodeFactory.createURI(url.toString());
} else {
rootResource = NodeFactory.createURI(root);
}
} else {
rootResource = NodeFactory.createBlankNode();
}

Graph g = GraphFactory.createDefaultGraph();
g.add(new Triple(rootResource, RDF.type.asNode(), NodeFactory.createURI(Triplifier.FACADE_X_TYPE_ROOT)));
builder.addRoot(dataSourceId, root);

try {
TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory()
.createArchiveInputStream("tar", url.openStream(), charset.toString());
.createArchiveInputStream("tar", location.openStream(), charset.toString());
int i = 1;
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {

if (entry.getName().matches(matches)) {
g.add(new Triple(rootResource, RDF.li(i).asNode(), NodeFactory.createLiteral(entry.getName())));
builder.addValue(dataSourceId, root, i, entry.getName());
i++;
}

Expand All @@ -100,10 +75,7 @@ public DatasetGraph triplify(Properties properties) throws IOException {
throw new IOException(e);
}

dg.setDefaultGraph(g);
dg.addGraph(NodeFactory.createURI(url.toString()), g);

return dg;
return builder.getDatasetGraph();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,27 @@ public class ZipTriplifier implements Triplifier {

@Override
public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder) throws IOException {
// TODO Not implemented yet
return triplify(properties);
}

@Override
public DatasetGraph triplify(Properties properties) throws IOException {
DatasetGraph dg = DatasetGraphFactory.create();

URL url = Triplifier.getLocation(properties);

if (url == null)
return dg;

String root = Triplifier.getRootArgument(properties);
String dataSourceId = root;
Charset charset = Triplifier.getCharsetArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
String matches = properties.getProperty(MATCHES, ".*");

logger.trace("BN nodes {}", blank_nodes);

Node rootResource;
if (!blank_nodes) {
if (root == null) {
rootResource = NodeFactory.createURI(url.toString());
} else {
rootResource = NodeFactory.createURI(root);
}
} else {
rootResource = NodeFactory.createBlankNode();
}

Graph g = GraphFactory.createDefaultGraph();
g.add(new Triple(rootResource, RDF.type.asNode(), NodeFactory.createURI(Triplifier.FACADE_X_TYPE_ROOT)));
builder.addRoot(dataSourceId, root);

ZipInputStream zis = new ZipInputStream(url.openStream(), charset);
ZipEntry ze;
int i = 1;
while ((ze = zis.getNextEntry()) != null) {
if (ze.getName().matches(matches)) {
g.add(new Triple(rootResource, RDF.li(i).asNode(), NodeFactory.createLiteral(ze.getName())));
builder.addValue(dataSourceId, root, i, NodeFactory.createLiteral(ze.getName()));
i++;
}
}

dg.setDefaultGraph(g);
dg.addGraph(NodeFactory.createURI(url.toString()), g);

return dg;
return builder.getDatasetGraph();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Properties;
import java.util.Set;

import com.github.sparqlanything.model.BaseFacadeXGraphBuilder;
import com.github.sparqlanything.model.FacadeXGraphBuilder;
import com.github.sparqlanything.zip.FolderTriplifier;
import com.github.sparqlanything.zip.ZipTriplifier;
import org.apache.jena.graph.NodeFactory;
Expand All @@ -47,10 +49,9 @@ public void test1() throws MalformedURLException {

Properties p = new Properties();
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
DatasetGraph dg = tt.triplify(p);

// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();
Set<String> expected = new HashSet<>();

expected.add("");
Expand Down Expand Up @@ -92,8 +93,9 @@ public void testMatches() throws MalformedURLException {
Properties p = new Properties();
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
p.setProperty(ZipTriplifier.MATCHES.toString(), "[^j]*");
DatasetGraph dg = tt.triplify(p);

FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();
ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

Set<String> expected = new HashSet<>();
Expand Down Expand Up @@ -131,8 +133,9 @@ public void testBN() throws MalformedURLException {
Properties p = new Properties();
p.setProperty(IRIArgument.BLANK_NODES.toString(), "false");
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
DatasetGraph dg = tt.triplify(p);

FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();
// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

Set<String> expected = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.net.URL;
import java.util.Properties;

import com.github.sparqlanything.model.BaseFacadeXGraphBuilder;
import com.github.sparqlanything.model.FacadeXGraphBuilder;
import com.github.sparqlanything.zip.ZipTriplifier;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
Expand All @@ -48,9 +50,9 @@ public void test1() throws MalformedURLException {
URL url = getClass().getClassLoader().getResource("test.tar").toURI().toURL();
Properties p = new Properties();
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
DatasetGraph dg = tt.triplify(p);

// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");
FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();

Graph expectedGraph = GraphFactory.createGraphMem();
Node n = NodeFactory.createBlankNode();
Expand All @@ -61,7 +63,7 @@ public void test1() throws MalformedURLException {
expectedGraph.add(new Triple(n, RDF.li(5).asNode(), NodeFactory.createLiteral("test/test.txt")));
expectedGraph.add(new Triple(n, RDF.li(1).asNode(), NodeFactory.createLiteral("test/")));
assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(url.toString())).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));

} catch (IOException | URISyntaxException e) {
e.printStackTrace();
Expand All @@ -76,7 +78,10 @@ public void testMatches() throws MalformedURLException {
Properties p = new Properties();
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
p.setProperty(ZipTriplifier.MATCHES.toString(), "test/.*\\..*");
DatasetGraph dg = tt.triplify(p);

FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();

// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

Expand All @@ -89,7 +94,7 @@ public void testMatches() throws MalformedURLException {
expectedGraph.add(new Triple(n, RDF.li(4).asNode(), NodeFactory.createLiteral("test/test.txt")));
// expectedGraph.add(new Triple(n, RDF.li(1).asNode(), NodeFactory.createLiteral("test/")));
assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(url.toString())).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));

} catch (IOException | URISyntaxException e) {
e.printStackTrace();
Expand All @@ -104,7 +109,9 @@ public void testBNNODE() throws MalformedURLException {
Properties p = new Properties();
p.setProperty(IRIArgument.BLANK_NODES.toString(), "false");
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
DatasetGraph dg = tt.triplify(p);
FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();

// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

Expand All @@ -117,7 +124,7 @@ public void testBNNODE() throws MalformedURLException {
expectedGraph.add(new Triple(n, RDF.li(5).asNode(), NodeFactory.createLiteral("test/test.txt")));
expectedGraph.add(new Triple(n, RDF.li(1).asNode(), NodeFactory.createLiteral("test/")));
assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(url.toString())).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));

} catch (IOException | URISyntaxException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
import java.net.URL;
import java.util.Properties;

import com.github.sparqlanything.model.BaseFacadeXGraphBuilder;
import com.github.sparqlanything.model.FacadeXGraphBuilder;
import com.github.sparqlanything.zip.ZipTriplifier;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.graph.Triple;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.graph.GraphFactory;
import org.apache.jena.vocabulary.RDF;
Expand All @@ -47,7 +50,9 @@ public void test1() throws MalformedURLException {
URL url = getClass().getClassLoader().getResource("test.zip").toURI().toURL();
Properties p = new Properties();
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
DatasetGraph dg = tt.triplify(p);
FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();

// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

Expand All @@ -59,7 +64,7 @@ public void test1() throws MalformedURLException {
expectedGraph.add(new Triple(n, RDF.li(3).asNode(), NodeFactory.createLiteral("test.xml")));
expectedGraph.add(new Triple(n, RDF.li(4).asNode(), NodeFactory.createLiteral("test.txt")));
assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(url.toString())).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));

} catch (IOException | URISyntaxException e) {
e.printStackTrace();
Expand All @@ -76,7 +81,9 @@ public void testMatches() throws MalformedURLException {
Properties p = new Properties();
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
p.setProperty(ZipTriplifier.MATCHES.toString(), ".*\\.(csv|json)");
DatasetGraph dg = tt.triplify(p);
FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();

// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

Expand All @@ -88,7 +95,7 @@ public void testMatches() throws MalformedURLException {
// expectedGraph.add(new Triple(n, RDF.li(3).asNode(), NodeFactory.createLiteral("test.xml")));
// expectedGraph.add(new Triple(n, RDF.li(4).asNode(), NodeFactory.createLiteral("test.txt")));
assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(url.toString())).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));

} catch (IOException | URISyntaxException e) {
e.printStackTrace();
Expand All @@ -103,9 +110,11 @@ public void testBNNODE() throws MalformedURLException {
Properties p = new Properties();
p.setProperty(IRIArgument.BLANK_NODES.toString(), "false");
p.setProperty(IRIArgument.LOCATION.toString(), url.toString());
DatasetGraph dg = tt.triplify(p);
FacadeXGraphBuilder builder = new BaseFacadeXGraphBuilder(url.toString(), p);
tt.triplify(p, builder);
DatasetGraph dg = builder.getDatasetGraph();

// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");
ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

Graph expectedGraph = GraphFactory.createGraphMem();
Node n = NodeFactory.createURI(url.toString() + "#");
Expand All @@ -115,7 +124,7 @@ public void testBNNODE() throws MalformedURLException {
expectedGraph.add(new Triple(n, RDF.li(3).asNode(), NodeFactory.createLiteral("test.xml")));
expectedGraph.add(new Triple(n, RDF.li(4).asNode(), NodeFactory.createLiteral("test.txt")));
assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(url.toString())).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));

} catch (IOException | URISyntaxException e) {
e.printStackTrace();
Expand Down
Loading

0 comments on commit 49868e4

Please sign in to comment.