Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http//www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is ART Ontology API.
*
* The Initial Developer of the Original Code is University of Roma Tor Vergata.
* Portions created by University of Roma Tor Vergata are Copyright (C) 2007.
* All Rights Reserved.
*
* ART Ontology API was developed by the Artificial Intelligence Research Group
* (art.uniroma2.it) at the University of Roma Tor Vergata
* Current information about the ART Ontology API can be obtained at
* http//art.uniroma2.it/owlart
*
*/
/*
* Contributor(s): Armando Stellato [email protected]
*/
package it.uniroma2.art.owlart.utilities;
import it.uniroma2.art.owlart.exceptions.ModelAccessException;
import it.uniroma2.art.owlart.exceptions.ModelUpdateException;
import it.uniroma2.art.owlart.model.ARTBNode;
import it.uniroma2.art.owlart.model.ARTNode;
import it.uniroma2.art.owlart.model.ARTResource;
import it.uniroma2.art.owlart.model.ARTStatement;
import it.uniroma2.art.owlart.model.ARTURIResource;
import it.uniroma2.art.owlart.model.NodeFilters;
import it.uniroma2.art.owlart.models.DirectReasoning;
import it.uniroma2.art.owlart.models.OWLModel;
import it.uniroma2.art.owlart.models.RDFModel;
import it.uniroma2.art.owlart.models.RDFSModel;
import it.uniroma2.art.owlart.models.SKOSModel;
import it.uniroma2.art.owlart.models.SKOSXLModel;
import it.uniroma2.art.owlart.navigation.ARTNamespaceIterator;
import it.uniroma2.art.owlart.navigation.ARTResourceIterator;
import it.uniroma2.art.owlart.navigation.ARTStatementIterator;
import it.uniroma2.art.owlart.vocabulary.RDFResourceRolesEnum;
import it.uniroma2.art.owlart.vocabulary.RDFTypesEnum;
import java.util.ArrayList;
import java.util.Collection;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
public class ModelUtilities {
/**
* this method tells if namespace ns is present among the list of namespaces in model
* om
*
* @param rep
* @param ns
* @return
* @throws ModelAccessException
*/
public static boolean isAvailableNamespace(RDFModel om, String ns) throws ModelAccessException {
ARTNamespaceIterator nss = om.listNamespaces();
boolean avail = false;
while (avail == false && nss.streamOpen())
avail = nss.next().equals(ns);
return avail;
}
/**
* given namespace namespace, this tries to automatically suggest a prefix for it
*
* @param namespace
* @return
*/
public static String guessPrefix(String namespace) {
int lowerCutIndex;
String tempString;
if (namespace.endsWith("/") || namespace.endsWith("#"))
tempString = namespace.substring(0, namespace.length() - 1);
else
tempString = namespace;
if (tempString.matches(".*\\.(\\w{2}|\\w{3})"))
tempString = tempString.substring(0, tempString.lastIndexOf("."));
int pointLowerCutIndex = tempString.lastIndexOf(".");
int slashLowerCutIndex = tempString.lastIndexOf("/");
if (pointLowerCutIndex > slashLowerCutIndex)
lowerCutIndex = pointLowerCutIndex;
else
lowerCutIndex = slashLowerCutIndex;
return tempString.substring(lowerCutIndex + 1);
}
/**
* given the baseuri of an ontology, returns the baseuri
*
* @param baseuri
* @return
*/
public static String createDefaultNamespaceFromBaseURI(String baseuri) {
if (baseuri.endsWith("/") || baseuri.endsWith("#"))
return baseuri;
else
return baseuri + "#";
}
/**
* this method helps in deleting individuals and their associated info. the PropertyChainsTree is used to
* distinguish which linked nodes in the graph should be deleted together with the main individual
* If an individual reachable through the property chain is however referred (it is object of a triple) by
* other individuals, then it is not deleted
*
* @param resource
* @param model
* @throws ModelUpdateException
*/
public static void deepDeleteIndividual(ARTResource resource, RDFModel model,
PropertyChainsTree delPropTree, ARTResource... graphs) throws ModelUpdateException {
// the recursion is sound. The basic assumption is that the first resource (first call) is always to
// be deleted, while the linked ones are not necessarily deleted (see below), so the first call
// immediately deletes the resource, while the checks for any subsequent call (if delete or not) are
// made at the end of the previous call (so this code contains the check for the next invocation of
// this function)
// 1) removes all the incoming edges
model.deleteTriple(NodeFilters.ANY, NodeFilters.ANY, resource, graphs);
// 2) mark all objects pointed through outgoing properties in the PropertyChainsTree as
// "to be deleted" before deleting all triples having resource as their subject
Multimap deletePropagation = HashMultimap.create();
ARTStatementIterator stit;
try {
// TODO here we have to add the possibility of automatically recursively delete bnodes too.
// if the bnode is in the deletePropagation path, then it should be dealt with in the usual way of
// the deletion PropertyChainsTree. If it is not, a simple deep delete with the sole automation on
// bnodes (which still needs to be implemented) should be invoked.
// instead of cycling on the delPropTree.getChainedProperties to get all the triples of type
// (resource, delPropTree.getChainedProperties.getNext(), ANY) we simply list of the outgoing
// triples and then, for each of them, we check if the predicate is among the properties. We thus
// get all the predicates linking resource to any object, and if the property chain tree contains
// two properties p1 and p2 and there exist triples:
// resource p1 object
// resource p2 object
// then both the pairs