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

import de.uni_stuttgart.vis.vowl.owl2vowl.model.data.VowlData;

import de.uni_stuttgart.vis.vowl.owl2vowl.model.nodes.classes.AbstractClass;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.util.OWLObjectVisitorAdapter;

import java.util.Set;

public class OwlClassAxiomVisitor extends OWLObjectVisitorAdapter {

	private VowlData vowlData;
	private OWLClass owlClass;
	private Logger logger = LogManager.getLogger(OwlClassAxiomVisitor.class);

	public OwlClassAxiomVisitor(VowlData vowlData, OWLClass owlClass) {
		this.vowlData = vowlData;
		this.owlClass = owlClass;
	}

	@Override
	protected void handleDefault(OWLObject axiom) {
		System.out.println(owlClass);
		System.out.println("\t" + axiom);
	}

	@Override
	public void visit(OWLEquivalentClassesAxiom axiom) {
		// TODO NamedClasses size != 1 means either
		if (axiom.getNamedClasses().size() != 1) {
			createEquivalentClass(axiom);
		}

		OWLClass referencedClass = axiom.getNamedClasses().iterator().next();

		Set<OWLClassExpression> expressionsWithoutRefClass = axiom.getClassExpressionsMinus(referencedClass);
		for (OWLClassExpression anonymExpressions : expressionsWithoutRefClass) {
			anonymExpressions.accept(new VowlClassVisitor(vowlData, referencedClass));
		}
	}

	protected void createEquivalentClass(OWLEquivalentClassesAxiom axiom) {

	}

	@Override
	public void visit(OWLSubClassOfAxiom axiom) {
		if (axiom.isGCI()) {
			// TODO anonym subclass behaviour
			logger.info("Anonym subclass: " + axiom);
			return;
		}

		OWLClass subClass = axiom.getSubClass().asOWLClass();
		AbstractClass vowlSubclass = vowlData.getClassForIri(subClass.getIRI());

		if (axiom.getSuperClass().isAnonymous()) {
			axiom.getSuperClass().accept(new OwlSubclassAnonymVisitor(vowlData, owlClass));
		} else {
			OWLClass superClass = axiom.getSuperClass().asOWLClass();
			AbstractClass vowlSuperClass = vowlData.getClassForIri(superClass.getIRI());
			vowlSubclass.addSuperEntity(vowlSuperClass.getIri());
			vowlSuperClass.addSubEntity(vowlSubclass.getIri());
		}
	}

	@Override
	public void visit(OWLDisjointClassesAxiom axiom) {
		for (OWLDisjointClassesAxiom pairwiseAxiom : axiom.asPairwiseAxioms()) {
			IRI[] domainRange = new IRI[2];
			int index = 0;

			for (OWLClass aClass : pairwiseAxiom.getClassesInSignature()) {
				domainRange[index++] = aClass.getIRI();
			}

			vowlData.getGenerator().generateDisjointProperty(domainRange[0], domainRange[1]);
		}
	}

	@Override
	public void visit(OWLDisjointUnionAxiom axiom) {
		super.visit(axiom);
	}
}

@@ -50,16 +50,83 @@
 .vowl;%0A%0A
+import de.uni_stuttgart.vis.vowl.owl2vowl.constants.VowlAttribute;%0A
 import d
@@ -1116,16 +1116,27 @@
 axiom);%0A
+%09%09%09return;%0A
 %09%09%7D%0A%0A%09%09O
@@ -1544,16 +1544,374 @@
 xiom) %7B%0A
+%09%09AbstractClass topClass = vowlData.getClassForIri(owlClass.getIRI());%0A%0A%09%09for (OWLClassExpression owlClassExpression : axiom.getClassExpressionsMinus(owlClass)) %7B%0A%09%09%09topClass.addEquivalentElement(owlClassExpression.asOWLClass().getIRI());%0A%09%09%7D%0A%0A%09%09topClass.addAttribute(VowlAttribute.EQUIVALENT);%0A%0A%09%09// TODO post parsing determine correct top equivalent class?
 %0A%09%7D%0A%0A%09@O
@@ -3087,27 +3087,44 @@
 %7B%0A%09%09
-super.visit(axiom);
+// TODO DisjointUnion implementation
 %0A%09%7D%0A

Implement equivalent classes