package am.app.feedback.measures;

import java.util.ArrayList;

import am.app.Core;
import am.app.feedback.CandidateConcept;
import am.app.mappingEngine.AbstractMatcher.alignType;
import am.app.ontology.Ontology;
import am.userInterface.vertex.Vertex;

public class Specificity extends RelevanceMeasure {

	CandidateConcept.ontology whichOntology;
	alignType whichType;

	
	public void calculateRelevances() {
		
		Ontology sourceOntology = Core.getInstance().getSourceOntology();
		whichOntology = CandidateConcept.ontology.source;
		
		// source classes
		whichType     = alignType.aligningClasses;
		visitNode( sourceOntology.getClassesTree(), 1 );
		candidateList.add( new CandidateConcept( sourceOntology.getClassesTree().getNode(), 1.0d, whichOntology, whichType ));

		// source properties
		whichType     = alignType.aligningProperties;
		visitNode( sourceOntology.getPropertiesTree(), 1 );
		candidateList.add( new CandidateConcept( sourceOntology.getPropertiesTree().getNode(), 1.0d, whichOntology, whichType ));

		
		
		Ontology targetOntology = Core.getInstance().getTargetOntology();
		whichOntology = CandidateConcept.ontology.target;
		
		// target classes
		whichType     = alignType.aligningClasses;
		visitNode( targetOntology.getClassesTree(), 1 );
		candidateList.add( new CandidateConcept( targetOntology.getClassesTree().getNode(), 1.0d, whichOntology, whichType ));

		
		// target properties
		whichType     = alignType.aligningProperties;
		visitNode( targetOntology.getPropertiesTree(), 1 );
		candidateList.add( new CandidateConcept( targetOntology.getPropertiesTree().getNode(), 1.0d, whichOntology, whichType ));

		
		
		
	}
	
	protected void visitNode( Vertex concept, int depth ) {
		
		ArrayList<Vertex> childrenList = new ArrayList<Vertex>();
		int numChildren = concept.getChildCount();
		
		for( int i = 0; i < numChildren; i++ ) {
			childrenList.add((Vertex) concept.getChildAt(i));
		}
		
		depth = depth + 1;
		int fanout = childrenList.size();
		
		
		// visit the children
		for( int i = 0; i < childrenList.size(); i++ ) {
			double specificity = (1 / depth) * ( 1 / fanout);
			candidateList.add( new CandidateConcept( childrenList.get(i).getNode(), specificity, whichOntology, whichType ));
			visitNode( childrenList.get(i), depth );
		}
		
	}
	
	
	
	
}

@@ -637,32 +637,91 @@
 sesTree(), 1 );%0A
+%09%09if( sourceOntology.getClassesTree().getNode() != null )%0A%09
 %09%09candidateList.
@@ -943,32 +943,96 @@
 iesTree(), 1 );%0A
+%09%09if( sourceOntology.getPropertiesTree().getNode() != null )%09%09%0A%09
 %09%09candidateList.
@@ -1377,32 +1377,91 @@
 sesTree(), 1 );%0A
+%09%09if( targetOntology.getClassesTree().getNode() != null )%0A%09
 %09%09candidateList.
@@ -1694,16 +1694,78 @@
 ), 1 );%0A
+%09%09if( targetOntology.getPropertiesTree().getNode() != null )%0A%09
 %09%09candid

Fix null pointer error.