Skip to content

Commit

Permalink
Implement #233
Browse files Browse the repository at this point in the history
  • Loading branch information
enridaga committed Mar 23, 2022
1 parent db82b52 commit 6062644
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,41 @@ private void transformMap(Map o, String dataSourceId, String containerId,
@Override
public void triplify(Properties properties, FacadeXGraphBuilder builder)
throws IOException, TriplifierHTTPException {
// TODO Add support for JsonPath
transform(properties, builder);

if(properties.containsKey("json.path") || properties.containsKey("json.path.1`")){
transformFromJSONPath(properties, builder);
}else {
transform(properties, builder);
}
}

private void transformFromJSONPath(Properties properties, FacadeXGraphBuilder builder) throws TriplifierHTTPException, IOException {
JsonSurfer surfer = new JsonSurfer(JacksonParser.INSTANCE, JacksonProvider.INSTANCE);
final InputStream us = Triplifier.getInputStream(properties);
Collector collector = surfer.collector(us);
Set<ValueBox<Collection<Object>>> matches = new HashSet<ValueBox<Collection<Object>>>();
List<String> jsonPaths = Triplifier.getPropertyValues(properties, "json.path");
for(String jpath: jsonPaths) {
ValueBox<Collection<Object>> m = collector.collectAll(jpath);
matches.add(m);
}

try (us) {
collector.exec();
Iterator<ValueBox<Collection<Object>>> matchesIterator = matches.iterator();
// Only 1 data source expected
String rootId = Triplifier.getRootArgument(properties);
String dataSourceId = rootId;
builder.addRoot(dataSourceId, rootId);
int c = 0;
while(matchesIterator.hasNext()){
Iterator<Object> it = matchesIterator.next().get().iterator();
while(it.hasNext()){
transformArrayItem(c, it.next(), dataSourceId, rootId, builder);
c++;
}
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ protected void properties(Properties properties) {
properties.setProperty("blank-nodes", "false");
properties.setProperty("slice", "true");
properties.setProperty("json.path", "$.*");
}else if(name.getMethodName().equals("testSliceArray$4")){
properties.setProperty("blank-nodes", "false");
// properties.setProperty("slice", "true");
properties.setProperty("json.path", "$.*");
}else if(name.getMethodName().equals("testSliceArray_2$1")){
properties.setProperty("blank-nodes", "false");
// properties.setProperty("slice", "true");
Expand Down Expand Up @@ -86,6 +90,13 @@ protected void properties(Properties properties) {
assertResultIsIsomorphicWithExpected();
}

@Test
public void testSliceArray$4(){
L.info("Test simple array (one go + JsonPath)");
//RDFDataMgr.write(System.err, result, Lang.N3);
assertResultIsIsomorphicWithExpected();
}

@Test
public void testSliceArray_2$1(){
L.info("Test array of objects (one go)");
Expand All @@ -104,6 +115,12 @@ protected void properties(Properties properties) {
assertResultIsIsomorphicWithExpected();
}

@Test
public void testSliceArray_2$4(){
L.info("Test array of objects (one go + JsonPath)");
assertResultIsIsomorphicWithExpected();
}

@Test
public void testValueTypes_1$1(){
L.info("Test json value types (one go)");
Expand All @@ -124,4 +141,11 @@ protected void properties(Properties properties) {
//RDFDataMgr.write(System.err, result, Lang.N3);
assertResultIsIsomorphicWithExpected();
}

@Test
public void testValueTypes_1$4(){
L.info("Test json value types (one go + JsonPath)");
//RDFDataMgr.write(System.err, result, Lang.N3);
assertResultIsIsomorphicWithExpected();
}
}

0 comments on commit 6062644

Please sign in to comment.