@@ -0,0 +1,3476 @@
+/**%0A * Copyright (c) 2015, 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.micro.rdf;%0A%0Aimport com.hp.hpl.jena.rdf.model.Model;%0Aimport com.hp.hpl.jena.rdf.model.Property;%0Aimport com.hp.hpl.jena.rdf.model.Resource;%0Aimport com.hp.hpl.jena.rdf.model.Statement;%0Aimport com.hp.hpl.jena.rdf.model.StmtIterator;%0A%0A/**%0A * Class contains small helper functions when dealing with Jena RDF models.%0A *%0A * @author Michael Sonntag (sonntag@bio.lmu.de)%0A */%0Apublic final class RdfUtilsJena %7B%0A    /**%0A     * Method adds an RDF Literal only to a Jena Resource, if the Literal String%0A     * actually contains a value.%0A     * @param res Jena Resource.%0A     * @param p Jena Property.%0A     * @param litStr String containing the value of the Literal.%0A     */%0A    public static void addNonEmptyLiteral(final Resource res, final Property p, final String litStr) %7B%0A        if (litStr != null && !litStr.isEmpty()) %7B%0A            res.addLiteral(p, litStr);%0A        %7D%0A    %7D%0A    /**%0A     * Walk through existing %7B@link Resource%7Ds of an input RDF %7B@link Model%7D, check for Resources%0A     * identical by URI with another model and remove all Property and anonymous RDFNodes%0A     * from these identical Resources of the second model.%0A     * @param inModel RDF %7B@link Model%7D from which the Resources are printed and checked for in the removeFromModel.%0A     * @param removeFromModel RDF %7B@link Model%7D from which the resources are removed if identical with resources%0A     *                  in the inModel.%0A     * @param removeAnonNodes If true, anonymous RDFNodes that are referenced by properties%0A     *                        that are to be removed, are removed as well.%0A     * @return The %7B@link Model%7D removeFromModel from which all Properties and anonymous Nodes%0A     * of %7B@link Model%7D inModel identical by URI have been removed.%0A     */%0A    public static Model removePropertiesFromModel(final Model inModel, final Model removeFromModel,%0A                                                  final boolean removeAnonNodes) %7B%0A        inModel.listObjects().forEachRemaining(o -%3E %7B%0A                if (o.isURIResource()%0A                        && o.asResource().listProperties().hasNext()%0A                        && removeFromModel.containsResource(o.asResource())) %7B%0A                    final Resource resRemoveProps = removeFromModel.getResource(o.asResource().getURI());%0A                    if (removeAnonNodes) %7B%0A                        removeAnonProperties(resRemoveProps.listProperties());%0A                    %7D%0A                    resRemoveProps.removeProperties();%0A                %7D%0A            %7D);%0A        return removeFromModel;%0A    %7D%0A    /**%0A     * Check if a statement has an anonymous RDFNode as%0A     * an RDF Object and remove all properties of such an anonymous RDFNode%0A     * from the containing model without removing the anonymous RDFNode itself.%0A     * @param checkAnon This %7B@link StmtIterator%7D contains a list of statements.%0A     */%0A    public static void removeAnonProperties(final StmtIterator checkAnon) %7B%0A        while (checkAnon.hasNext()) %7B%0A            final Statement currStmt = checkAnon.nextStatement();%0A            if (currStmt.getObject().isAnon()) %7B%0A                currStmt.getObject().asResource().removeProperties();%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

Add class