@@ -0,0 +1,3163 @@
+/**%0A * Copyright (c) 2016, German Neuroinformatics Node (G-Node)%0A *%0A * All rights reserved.%0A *%0A * Redistribution and use in source and binary forms, with or without%0A * modification, are permitted under the terms of the BSD License. See%0A * LICENSE file in the root of the Project.%0A */%0A%0Apackage org.g_node.mergers;%0A%0Aimport com.hp.hpl.jena.rdf.model.Model;%0Aimport com.hp.hpl.jena.rdf.model.ModelFactory;%0Aimport org.apache.log4j.Logger;%0Aimport org.g_node.micro.commons.FileService;%0Aimport org.g_node.micro.commons.RDFService;%0Aimport org.g_node.srv.ModelUtils;%0A%0A/**%0A * Class handling the merging of RDF documents using the Apache Jena RDF suite.%0A *%0A * @author Michael Sonntag (sonntag@bio.lmu.de)%0A */%0Apublic class LktJenaMerger %7B%0A    /**%0A     * Access to the main LOGGER.%0A     */%0A    private static final Logger LOGGER = Logger.getLogger(LktJenaMerger.class.getName());%0A%0A    /**%0A     * Method merges two RDF files, one named mergeRDF, the other mainRDF. Information will be merged from the%0A     * mergeRDF file with the mainRDF file. If an output filename is provided, the merged RDF graph will be%0A     * saved to this output file. If no output filename is specified, a backup of the mainRDF file will be created,%0A     * using the format '%5Bdate_time%5D_backup_%5Bmain file name%5D' and the mainRDF file will be replaced with the merged%0A     * RDF graph.%0A     * If RDF Resources with the same URI are encountered in both mergeRDF and mainRDF, this Resource including all%0A     * referenced Blank Nodes will be removed from the mainRDF before the merge of the two graphs is performed. This%0A     * ensures, that only the information of the mergeRDF graph will be present in the merged final graph.%0A     * @param mainFile Main RDF file. Information will be merged into this file.%0A     * @param mergeFile Merge RDF file. Information from this file will be merged into the mainFile.%0A     * @param outputFile Name and Path of the output file.%0A     * @param outputFormat RDF format of the output file.%0A     */%0A    public static void mergeAndSave(final String mainFile, final String mergeFile,%0A                             final String outputFile, final String outputFormat) %7B%0A%0A        final Model mainModel = RDFService.openModelFromFile(mainFile);%0A        final Model addModel = RDFService.openModelFromFile(mergeFile);%0A%0A        Model mergeModel = ModelFactory.createDefaultModel();%0A%0A        mergeModel.setNsPrefixes(mainModel.getNsPrefixMap());%0A        mergeModel.setNsPrefixes(addModel.getNsPrefixMap());%0A%0A        mergeModel = ModelUtils.removePropertiesFromModel(addModel, mainModel, true);%0A        mergeModel.add(addModel);%0A%0A        // TODO test if this conditional works as required and maybe come up with a better solution.%0A        // Create backup, if the output file is the same as the main RDF file.%0A        if (mainFile.equals(outputFile) && !FileService.createTimeStampBackupFile(mainFile, %22yyyyMMddHHmm%22)) %7B%0A            LktJenaMerger.LOGGER.error(%0A                    String.join(%22%22, %22%5BERROR %5D While saving backup for file '%22, mainFile, %22'%22)%0A            );%0A            return;%0A        %7D%0A%0A        RDFService.saveModelToFile(outputFile, mergeModel, outputFormat);%0A    %7D%0A%7D%0A

Add file