Hi, the code is:
----------------------------------
public class RDFMerge {
private static File folder;
private static Model kg;
// private static OutputStream out;
public static void iterate() {
folder = new File("C:\\Users\\Admin\\Desktop\\KG");
kg =
ModelFactory.createDefaultModel().read("C:\\Users\\Admin\\Desktop\\KG\\AccessComponent.bo.rdf");
File[] listOfFiles = folder.listFiles(); // Interating through the directory
for (File file : listOfFiles) {
if (file.isFile()) {
kg = merge(kg, file);
}
}
OutputStream out1;
try { out1 = new FileOutputStream( new
File("C:\\Users\\Admin\\Desktop\\merged.rdf"));
kg.write( out1, "RDF/XML", null );
System.out.println("RDFs merged successfully!"); }
catch(FileNotFoundException e) { e.printStackTrace(); }
}
public static Model merge(Model k, File i) {
// Model kg_in =
ModelFactory.createDefaultModel().read(k.getAbsolutePath());
Model other_in =
ModelFactory.createDefaultModel().read(i.getAbsolutePath());
Model union = ModelFactory.createUnion(k, other_in);
return union;
}}
On Fri, Feb 12, 2021 at 2:12 PM Andy Seaborne <[email protected]> wrote:
> Hi there - the attachment didn't make it through.
>
> Could you include the code in the body of the message please? Or put in
> somewhere like a gist on github / pastebin /... and send a link.
>
> Andy
>
> On 12/02/2021 11:45, emri mbiemri wrote:
> > Dear all,
> >
> > Do you know how I can merge some thousands RDF models into a single one?
> > I have tried it by iteration through all files within a folder and then
> > using Jena's union function to merge them one by one! The problem is
> > that the program is running for more than 13 hours and is still not
> > stopping (with only 50 models as test).
> >
> > So far I have close to 700 models, in total 68MB.
> >
> > Attached you seen the code I am using for.
> >
> > Do you have any idea what I can do to merge all these files into a
> > single knowledge-graph?
> >
> > Thanks for your help.
>