diff --git a/src/main/java/be/ugent/rml/Utils.java b/src/main/java/be/ugent/rml/Utils.java index d315846c..41c3caa2 100644 --- a/src/main/java/be/ugent/rml/Utils.java +++ b/src/main/java/be/ugent/rml/Utils.java @@ -195,6 +195,10 @@ public static boolean isRemoteFile(String location) { return location.startsWith("https://") || location.startsWith("http://"); } + public static boolean isLabeledFile(String location) { + return location.startsWith("label://"); + } + public static List getSubjectsFromQuads(List quads) { ArrayList subjects = new ArrayList<>(); diff --git a/src/main/java/be/ugent/rml/records/CSVW.java b/src/main/java/be/ugent/rml/records/CSVW.java index 5065bff9..09604041 100644 --- a/src/main/java/be/ugent/rml/records/CSVW.java +++ b/src/main/java/be/ugent/rml/records/CSVW.java @@ -35,6 +35,10 @@ private String getContentType() { this.is = Utils.getInputStreamFromLocation(path, new File(cwd), getContentType()); } + CSVW(InputStream inputStream) throws IOException { + this.is = inputStream; + } + private String helper(String term) { List terms = Utils.getObjectsFromQuads(this.rmlStore.getQuads(this.dialect, new NamedNode(NAMESPACES.CSVW + term), null)); if (!terms.isEmpty()) { diff --git a/src/main/java/be/ugent/rml/records/IteratorFormat.java b/src/main/java/be/ugent/rml/records/IteratorFormat.java index f7e175bc..ffb36991 100644 --- a/src/main/java/be/ugent/rml/records/IteratorFormat.java +++ b/src/main/java/be/ugent/rml/records/IteratorFormat.java @@ -23,6 +23,10 @@ public List get(String location, String iterator, String cwd) throws IOE return _get(stream, iterator); } + public List get(InputStream stream, String iterator) throws IOException { + return _get(stream, iterator); + } + abstract List _get(InputStream stream, String iterator) throws IOException; abstract String getContentType(); diff --git a/src/main/java/be/ugent/rml/records/RecordsFactory.java b/src/main/java/be/ugent/rml/records/RecordsFactory.java index 1faec391..d383dfae 100644 --- a/src/main/java/be/ugent/rml/records/RecordsFactory.java +++ b/src/main/java/be/ugent/rml/records/RecordsFactory.java @@ -11,6 +11,7 @@ import org.apache.commons.lang.NotImplementedException; import java.io.IOException; +import java.io.InputStream; import java.util.*; public class RecordsFactory { @@ -21,9 +22,9 @@ public class RecordsFactory { private Map>> allXMLRecords; private Map>> allRDBsRecords; private Map>> allSPARQLRecords; + private Map labeledFilesMap; - public RecordsFactory(DataFetcher dataFetcher) { - this.dataFetcher = dataFetcher; + private void Init() { allCSVRecords = new HashMap<>(); allJSONRecords = new HashMap<>(); allXMLRecords = new HashMap<>(); @@ -31,6 +32,22 @@ public RecordsFactory(DataFetcher dataFetcher) { allSPARQLRecords = new HashMap<>(); } + public RecordsFactory(DataFetcher dataFetcher) { + this.dataFetcher = dataFetcher; + this.Init(); + } + + public RecordsFactory(Map labeledFilesMap) { + this.labeledFilesMap = labeledFilesMap; + this.Init(); + } + + public RecordsFactory(DataFetcher dataFetcher, Map streamsMap) { + this.dataFetcher = dataFetcher; + this.labeledFilesMap = streamsMap; + this.Init(); + } + public List createRecords(Term triplesMap, QuadStore rmlStore) throws IOException { //get logical source List logicalSources = Utils.getObjectsFromQuads(rmlStore.getQuads(triplesMap, new NamedNode(NAMESPACES.RML + "logicalSource"), null)); @@ -120,7 +137,12 @@ private List getCSVRecords(String source) throws IOException { return allCSVRecords.get(source); } else { try { - CSVW CSVW = new CSVW(source, dataFetcher.getCwd()); + CSVW CSVW; + if(Utils.isLabeledFile(source)) { + CSVW = new CSVW(this.labeledFilesMap.get(source)); + } else { + CSVW = new CSVW(source, dataFetcher.getCwd()); + } allCSVRecords.put(source, CSVW.getRecords()); } catch (IOException e) { throw e; @@ -185,7 +207,12 @@ private List getXMLRecords(String source, List iterators, Term tri } else { try { XML xml = new XML(); - List records = xml.get(source, iterator, dataFetcher.getCwd()); + List records = new ArrayList<>(); + if(Utils.isLabeledFile(source)) { + records = xml.get(this.labeledFilesMap.get(source), iterator); + } else { + records = xml.get(source, iterator, dataFetcher.getCwd()); + } if (allXMLRecords.containsKey(source)) { allXMLRecords.get(source).put(iterator, records); @@ -213,8 +240,13 @@ private List getJSONRecords(String source, List iterators, Term tr return allJSONRecords.get(source).get(iterator); } else { try { - JSON json = new JSON(); - List records = json.get(source, iterator, dataFetcher.getCwd()); + JSON json = new JSON(); + List records = new ArrayList<>(); + if(Utils.isLabeledFile(source)) { + records = json.get(this.labeledFilesMap.get(source), iterator); + } else { + records = json.get(source, iterator, dataFetcher.getCwd()); + } if (allJSONRecords.containsKey(source)) { allJSONRecords.get(source).put(iterator, records);