Skip to content

Commit

Permalink
Refactor calls to getRootArgument(Properties). See #188
Browse files Browse the repository at this point in the history
  • Loading branch information
enridaga committed Jan 24, 2022
1 parent 4eaba5b commit ef2b5f7
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DatasetGraph triplify(Properties properties) throws IOException {
if (url == null)
return dg;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public DatasetGraph triplify(Properties properties) throws IOException {
if (url == null)
return dg;

String root = Triplifier.getRootArgument(properties, url);
String root = Triplifier.getRootArgument(properties);
Charset charset = Triplifier.getCharsetArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
String matches = properties.getProperty(ZipTriplifier.MATCHES, ".*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DatasetGraph triplify(Properties properties) throws IOException {
if (url == null)
return dg;

String root = Triplifier.getRootArgument(properties, url);
String root = Triplifier.getRootArgument(properties);
Charset charset = Triplifier.getCharsetArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
String matches = properties.getProperty(MATCHES, ".*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder)
if (url == null && (content == null || content.isEmpty()))
return dg;

String root = Triplifier.getRootArgument(properties, url);
String root = Triplifier.getRootArgument(properties);
String dataSourceId = root;
String namespace = Triplifier.getNamespaceArgument(properties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public DatasetGraph triplify(Properties properties) throws IOException {
logger.warn("Using default encoding (Base64)");
}

String root = Triplifier.getRootArgument(properties, url);
String root = Triplifier.getRootArgument(properties);
// Charset charset = getCharsetArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
// String namespace = url.toString() + "#";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CSVTriplifier implements Triplifier {
public final static String PROPERTY_NULLSTRING = "csv.null-string";

@Override
public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder) throws IOException, TriplifierHTTPException{
public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder) throws IOException, TriplifierHTTPException {

URL url = Triplifier.getLocation(properties);
log.debug("Location: {}", url);
Expand All @@ -65,14 +65,14 @@ public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder)
format = format.withNullString(properties.getProperty(PROPERTY_NULLSTRING)) ;
}
if(properties.containsKey(PROPERTY_DELIMITER)){
System.out.println("Setting delimiter to " + properties.getProperty(PROPERTY_DELIMITER));
log.debug("Setting delimiter to {}", properties.getProperty(PROPERTY_DELIMITER));
if(properties.getProperty(PROPERTY_DELIMITER).length() != 1){
throw new IOException("Bad value for property " + PROPERTY_DELIMITER + ": string length must be 1, " + Integer.toString(properties.getProperty(PROPERTY_DELIMITER).length()) + " given");
}
format = format.withDelimiter(properties.getProperty(PROPERTY_DELIMITER).charAt(0)) ;
}

String root = Triplifier.getRootArgument(properties, url);
String root = Triplifier.getRootArgument(properties);
Charset charset = Triplifier.getCharsetArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
String namespace = Triplifier.getNamespaceArgument(properties);
Expand All @@ -88,7 +88,7 @@ public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder)
log.debug("Use headers: {}", headers);
Reader in = null;

String dataSourceId = Triplifier.getRootArgument(properties, url); // url.toString();
String dataSourceId = Triplifier.getRootArgument(properties); // there is always 1 data source id
String containerRowPrefix = url.toString() + "#row";
// Add type Root
builder.addRoot(dataSourceId, root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder)
if (url == null)
return builder.getDatasetGraph();

String root = Triplifier.getRootArgument(properties, url.toString());
String root = Triplifier.getRootArgument(properties);
String dataSourceId = root;
String namespace = Triplifier.getNamespaceArgument(properties);
boolean mergeParagraphs = Boolean.parseBoolean(properties.getProperty(MERGE_PARAGRAPHS, "false"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void test1() {
System.err.println(graphNodes.next());
}
assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p, doc)))
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p)))
.isIsomorphicWith(expectedGraph));

p.setProperty(DocxTriplifier.MERGE_PARAGRAPHS, "true");
Expand All @@ -96,7 +96,7 @@ public void test1() {
expectedGraph.add(new Triple(n, RDF.li(6).asNode(), NodeFactory.createLiteral("", XSDDatatype.XSDstring)));

assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p, doc)))
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p)))
.isIsomorphicWith(expectedGraph));

} catch (IOException e) {
Expand Down Expand Up @@ -210,7 +210,7 @@ public void test2() {
.add(new Triple(row4, RDF.li(5).asNode(), NodeFactory.createLiteral("45", XSDDatatype.XSDstring)));

assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p, doc)))
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p)))
.isIsomorphicWith(expectedGraph));

if (!dg.getDefaultGraph().isIsomorphicWith(expectedGraph)) {
Expand Down Expand Up @@ -295,7 +295,7 @@ public void test3() {
}

assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p, doc)))
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p)))
.isIsomorphicWith(expectedGraph));

} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder)
if (url == null)
return DatasetGraphFactory.create();

String root = Triplifier.getRootArgument(properties, url);
String root = Triplifier.getRootArgument(properties);
Charset charset = Triplifier.getCharsetArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
String namespace = Triplifier.getNamespaceArgument(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private String[] getDataSources(URL url) {
}

private String getRootId(URL url, String dataSourceId, Properties properties) {
return Triplifier.getRootArgument(properties, url);
return Triplifier.getRootArgument(properties);
}

private void transform(URL url, Properties properties, FacadeXGraphBuilder builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void transform(URL url, Properties properties, FacadeXGraphBuilder build

try {
// Only 1 data source expected
String dataSourceId = Triplifier.getRootArgument(properties, url);
String dataSourceId = Triplifier.getRootArgument(properties);
rootId = dataSourceId;
logger.trace("ds {} root {}", dataSourceId, rootId);
before(url, properties, builder, dataSourceId, rootId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public BaseFacadeXBuilder(String resourceId, Properties properties) {
this.mainGraphName = NodeFactory.createURI(resourceId);
this.p_blank_nodes = Triplifier.getBlankNodeArgument(properties);
this.p_namespace = Triplifier.getNamespaceArgument(properties);
this.p_root = Triplifier.getRootArgument(properties, resourceId);
this.p_root = Triplifier.getRootArgument(properties);
this.p_trim_strings = Triplifier.getTrimStringsArgument(properties);
this.p_null_string = Triplifier.getNullStringArgument(properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,33 @@ static Charset getCharsetArgument(Properties properties) {
return charset;
}

@Deprecated
static String getRootArgument(Properties properties, URL url) {
if (url != null) {
return getRootArgument(properties, url.toString());
} else {
return getRootArgument(properties, (String) null);
}
}
// @Deprecated
// static String getRootArgument(Properties properties, URL url) {
// if (url != null) {
// return getRootArgument(properties, url.toString());
// } else {
// return getRootArgument(properties, (String) null);
// }
// }

static String getRootArgument(Properties properties) {
URL url = null;
try {
return getRootArgument(properties, Triplifier.getLocation(properties));
url = Triplifier.getLocation(properties);
} catch (MalformedURLException e) {
log.error("Malformed url", e);
return getRootArgument(properties, (String) null);
}
}

/**
* Implementation to be moved to getRootArgument(Properties)
*
* @param properties
* @param url
* @return
*/
@Deprecated
static String getRootArgument(Properties properties, String url) {
// }
//
// /**
// * Implementation to be moved to getRootArgument(Properties)
// *
// * @param properties
// * @param url
// * @return
// */
// @Deprecated
// static String getRootArgument(Properties properties, String url) {
if (url != null) {
String root = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public DatasetGraph triplify(Properties properties) throws IOException {
URL url = Triplifier.getLocation(properties);
if (url == null)
return dg;
String root = Triplifier.getRootArgument(properties, url);
String root = Triplifier.getRootArgument(properties);
// Charset charset = getCharsetArgument(properties);
boolean blank_nodes = Triplifier.getBlankNodeArgument(properties);
String namespace = Triplifier.getNamespaceArgument(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected void inspect() {
protected void perform() throws TriplifierHTTPException, IOException, URISyntaxException {
logger.debug("{} (perform)", name.getMethodName());
logger.info("{}", properties);
String graphName = Triplifier.getRootArgument(properties, url);
String graphName = Triplifier.getRootArgument(properties);
logger.debug("Graph name: {}", graphName);

if (!useDatasetGraph) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder)
URL url = Triplifier.getLocation(properties);
if (url == null) {
value = properties.getProperty(IRIArgument.CONTENT.toString(), "");
root = Triplifier.getRootArgument(properties, Integer.toString(value.hashCode()));
dataSourceId = root; // Use the hashed value //builder.getMainGraphName().getURI();
root = Triplifier.getRootArgument(properties);
dataSourceId = root; //
} else {
value = readFromURL(url, properties);
root = Triplifier.getRootArgument(properties, url.toString());
root = Triplifier.getRootArgument(properties);
dataSourceId = root;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void test1() throws MalformedURLException, TriplifierHTTPException {
expectedGraph.add(new Triple(n, RDF.li(1).asNode(),
NodeFactory.createLiteral("this is a test", XSDDatatype.XSDstring)));
assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p, url))).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -90,7 +90,7 @@ public void testRegex() throws MalformedURLException, TriplifierHTTPException {
// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p, url))).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -122,7 +122,7 @@ public void testSplit() throws MalformedURLException, TriplifierHTTPException {
// ModelFactory.createModelForGraph(dg.getDefaultGraph()).write(System.out, "TTL");

assertTrue(dg.getDefaultGraph().isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p, url))).isIsomorphicWith(expectedGraph));
assertTrue(dg.getGraph(NodeFactory.createURI(Triplifier.getRootArgument(p))).isIsomorphicWith(expectedGraph));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public DatasetGraph triplify(Properties properties, FacadeXGraphBuilder builder)

String namespace = Triplifier.getNamespaceArgument(properties);
String dataSourceId = url.toString();
String root = Triplifier.getRootArgument(properties, url);
String root = Triplifier.getRootArgument(properties);

XMLInputFactory inputFactory = XMLInputFactory.newInstance();
// TODO allow users to configure XML parser via properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private String[] getDataSources(URL url) {
}

private String getRootId(URL url, String dataSourceId, Properties properties) {
return Triplifier.getRootArgument(properties, url);
return Triplifier.getRootArgument(properties);
}

protected void transform(URL url, Properties properties, FacadeXGraphBuilder builder)
Expand Down

0 comments on commit ef2b5f7

Please sign in to comment.