/*
 * ComparisonHelper.java
 *
 */

package de.uni_stuttgart.vis.vowl.owl2vowl.parser.helper;

import de.uni_stuttgart.vis.vowl.owl2vowl.parser.Main;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLOntology;

import java.util.Set;

/**
 *
 */
public class ComparisonHelper {
	public static boolean hasDifferentNamespace(String elementNamespace, IRI ontologyNamespace) {
		int element = elementNamespace.indexOf("#");
		int ontologyIn = ontologyNamespace.toString().indexOf("#");

		String newElement = elementNamespace;
		String newOntology = ontologyNamespace.toString();

		if (element != -1) {
			newElement = newElement.substring(0, element);
		}

		if (ontologyIn != -1) {
			newOntology = newOntology.substring(0, ontologyIn);
		}

		/*
		System.out.println("ELEMENT: " + elementNamespace);
		System.out.println("ONTOLOGY: " + ontologyNamespace);
		System.out.println();
		*/

		return !(newElement.equals(newOntology));
	}

	public static boolean hasDifferentNameSpace(OWLEntity entity, OWLOntology ontology) {
		if (entity.getAnnotations(ontology, Main.factory.getRDFSIsDefinedBy()).isEmpty()) {
			return hasDifferentNamespace(entity.getIRI().toString(), ontology.getOntologyID().getOntologyIRI());
		} else {
			Set<OWLAnnotation> test = entity.getAnnotations(ontology, Main.factory.getRDFSIsDefinedBy());
			OWLAnnotation first = test.iterator().next();
			return hasDifferentNamespace(first.getValue().toString(), ontology.getOntologyID().getOntologyIRI());
		}
	}
}

@@ -540,16 +540,73 @@
 f(%22#%22);%0A
+%09%09int elementSlash = elementNamespace.lastIndexOf(%22/%22);%0A%0A
 %09%09int on
@@ -826,24 +826,118 @@
 lement);%0A%09%09%7D
+ else if (elementSlash != -1) %7B%0A%09%09%09newElement = newElement.substring(0, elementSlash + 1);%0A%09%09%7D
 %0A%0A%09%09if (onto
@@ -1014,16 +1014,22 @@
 %0A%09%09%7D%0A%0A%09%09
+      
 /*%0A%09%09Sys
@@ -1058,32 +1058,26 @@
 NT: %22 + 
-e
+newE
 lement
-Namespace
 );%0A%09%09Sys
@@ -1107,33 +1107,27 @@
 GY: %22 + 
-o
+newO
 ntology
-Namespace
 );%0A%09%09Sys
@@ -1151,16 +1151,17 @@
 ;%0A%09%09*/%0A%0A
+%0A
 %09%09return

Improve check for external elements now with '/' in the name.