<commit_before>package am.app;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;
import org.osgi.framework.BundleContext;

import am.AMException;
import am.app.mappingEngine.AbstractMatcher;
import am.app.mappingEngine.LexiconStore;
import am.app.mappingEngine.Mapping;
import am.app.mappingEngine.MatcherChangeListener;
import am.app.mappingEngine.MatcherResult;
import am.app.mappingEngine.MatchersRegistry;
import am.app.mappingEngine.MatchingTask;
import am.app.mappingEngine.MatchingTaskChangeEvent;
import am.app.mappingEngine.MatchingTaskChangeEvent.EventType;
import am.app.ontology.Node;
import am.app.ontology.Ontology;
import am.app.ontology.OntologyChangeEvent;
import am.app.ontology.OntologyChangeListener;
import am.app.ontology.profiling.OntologyProfiler;
import am.app.osgi.AMHost;
import am.userInterface.AppPreferences;
import am.userInterface.UI;
import am.userInterface.VisualizationChangeEvent;
import am.userInterface.VisualizationChangeListener;

import com.hp.hpl.jena.rdf.model.Model;

/**
 * SINGLETON JAVA PATTERN
 * There will be only one instance of this class in the whole application
 * All classes can access it without having any reference to it, just invoking the static method
 * Core.getInstance()
 * All model information of the system will be accessible from this class:
 * ontologies, matchings and so on.
 *
 */
public class Core {
	
	private final Logger log = Logger.getLogger(Core.class);
	
	// Program wide DEBUG flag. -- Deprecated, these flags will be removed and replaced with log4j!!! -- Cosmin Aug. 3, 2012.
	@Deprecated public static final boolean DEBUG = false;
	@Deprecated public static final boolean DEBUG_STACK_TRACE_MSG = false;
	@Deprecated public static final boolean DEBUG_NORMALIZER = false;  // debug flag for the am.app.mappingEngine.StringUtil.Normalizer class
	@Deprecated public static final boolean DEBUG_ONTOLOGYLEXICONSYNSET = false;
	@Deprecated public static boolean DEBUG_PSM = true;
	@Deprecated public static boolean DEBUG_VMM = false;
	@Deprecated public static final boolean DEBUG_FCM = false;
	
	/**
	 * The root directory for all of our runtime data files.
	 */
	private String amRoot;
	
	/**List of matchers instances run by the user
	 * Data of the tableModel of the matcherTable is taken from this structure
	 * Can't be null;
	 */
	
	private final List<AbstractMatcher> matcherInstances = new ArrayList<AbstractMatcher>();
	private final List<MatcherResult> matcherResults = new ArrayList<MatcherResult>();
	
	/**
	 * Keep a list of completed matching tasks currently in the system.
	 * When two ontologies are to be aligned a matching task is created and then
	 * executed.  The completed matching task is stored in this list, to be used by 
	 * the various components in AgreementMaker (e.g., visualization).
	 */
	private final List<MatchingTask> completedMatchingTasks = new ArrayList<MatchingTask>();
	
	private int IDcounter = 0;  // used in generating IDs for the ontologies and matchers
	public static final int ID_NONE = -1;  // the ID for when no ID has been set	
	
	private Ontology sourceOntology; //Null if it's not loaded yet
	private Ontology targetOntology; //Null if it's not loaded yet
	
	/**
	 * The ArrayList of ontologies that are currently loaded into the AgreementMaker.
	 * This adds support for more than two ontologies to be loaded into the AgreementMaker
	 * 
	 * Also, when an ontology is loaded, we need to let the GUI know, so we have an OntologyChangeListener interface.
	 * Interested parts of our code can register as an OntologyChangeListener of the core, by calling:
	 * 		- addChangeListener()
	 * 		- or removeChangeListener() to remove from the listener list
	 */
	private ArrayList<Ontology> loadedOntologies;
	
	/** Various change listeners. **/
	private ArrayList<OntologyChangeListener>      ontologyListeners;
	private ArrayList<MatcherChangeListener>  	   matcherListeners;
	private ArrayList<VisualizationChangeListener> visualizationListeners;
	
	
	private static AppPreferences prefs;
	
	private static LexiconStore lexstore; // The Lexicon store for these ontologies.
	
	private static UI ui; 	// A reference to the userinterface instance, canvas and table can be accessed anytime. 
							// It used often to invoke the method redisplayCanvas()
	
	private static Core core  = new Core(); // Singleton pattern: unique instance

	private AMHost osgi;
	
	
	/**
	 * 
	 * @return the unique instance of the core
	 */
	public static Core getInstance() {
		return core;
	}
	/**
	 * It's private because it's not possible to create new instances of this class
	 */
	private Core() {
		
		//System.setProperty("log4j.debug","strue" );  // Use this to see what log4j gets configured to.
	
		amRoot = System.getenv("AM_ROOT");

		if( amRoot == null ) {
			log.warn("The environment variable AM_ROOT is not set.  Using working directory as our root.");
			amRoot = System.getProperty("user.dir", (new File(".")).getAbsolutePath());
		}
		
		log.info("AgreementMaker root directory: " + amRoot);<commit_msg>Added default directory for AM_ROOT.<commit_after>package am.app;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;
import org.osgi.framework.BundleContext;

import am.AMException;
import am.app.mappingEngine.AbstractMatcher;
import am.app.mappingEngine.LexiconStore;
import am.app.mappingEngine.Mapping;
import am.app.mappingEngine.MatcherChangeListener;
import am.app.mappingEngine.MatcherResult;
import am.app.mappingEngine.MatchersRegistry;
import am.app.mappingEngine.MatchingTask;
import am.app.mappingEngine.MatchingTaskChangeEvent;
import am.app.mappingEngine.MatchingTaskChangeEvent.EventType;
import am.app.ontology.Node;
import am.app.ontology.Ontology;
import am.app.ontology.OntologyChangeEvent;
import am.app.ontology.OntologyChangeListener;
import am.app.ontology.profiling.OntologyProfiler;
import am.app.osgi.AMHost;
import am.userInterface.AppPreferences;
import am.userInterface.UI;
import am.userInterface.VisualizationChangeEvent;
import am.userInterface.VisualizationChangeListener;

import com.hp.hpl.jena.rdf.model.Model;

/**
 * SINGLETON JAVA PATTERN
 * There will be only one instance of this class in the whole application
 * All classes can access it without having any reference to it, just invoking the static method
 * Core.getInstance()
 * All model information of the system will be accessible from this class:
 * ontologies, matchings and so on.
 *
 */
public class Core {
	
	private final Logger log = Logger.getLogger(Core.class);
	
	// Program wide DEBUG flag. -- Deprecated, these flags will be removed and replaced with log4j!!! -- <NAME>. 3, 2012.
	@Deprecated public static final boolean DEBUG = false;
	@Deprecated public static final boolean DEBUG_STACK_TRACE_MSG = false;
	@Deprecated public static final boolean DEBUG_NORMALIZER = false;  // debug flag for the am.app.mappingEngine.StringUtil.Normalizer class
	@Deprecated public static final boolean DEBUG_ONTOLOGYLEXICONSYNSET = false;
	@Deprecated public static boolean DEBUG_PSM = true;
	@Deprecated public static boolean DEBUG_VMM = false;
	@Deprecated public static final boolean DEBUG_FCM = false;
	
	/**
	 * The root directory for all of our runtime data files.
	 */
	private String amRoot;
	
	/**List of matchers instances run by the user
	 * Data of the tableModel of the matcherTable is taken from this structure
	 * Can't be null;
	 */
	
	private final List<AbstractMatcher> matcherInstances = new ArrayList<AbstractMatcher>();
	private final List<MatcherResult> matcherResults = new ArrayList<MatcherResult>();
	
	/**
	 * Keep a list of completed matching tasks currently in the system.
	 * When two ontologies are to be aligned a matching task is created and then
	 * executed.  The completed matching task is stored in this list, to be used by 
	 * the various components in AgreementMaker (e.g., visualization).
	 */
	private final List<MatchingTask> completedMatchingTasks = new ArrayList<MatchingTask>();
	
	private int IDcounter = 0;  // used in generating IDs for the ontologies and matchers
	public static final int ID_NONE = -1;  // the ID for when no ID has been set	
	
	private Ontology sourceOntology; //Null if it's not loaded yet
	private Ontology targetOntology; //Null if it's not loaded yet
	
	/**
	 * The ArrayList of ontologies that are currently loaded into the AgreementMaker.
	 * This adds support for more than two ontologies to be loaded into the AgreementMaker
	 * 
	 * Also, when an ontology is loaded, we need to let the GUI know, so we have an OntologyChangeListener interface.
	 * Interested parts of our code can register as an OntologyChangeListener of the core, by calling:
	 * 		- addChangeListener()
	 * 		- or removeChangeListener() to remove from the listener list
	 */
	private ArrayList<Ontology> loadedOntologies;
	
	/** Various change listeners. **/
	private ArrayList<OntologyChangeListener>      ontologyListeners;
	private ArrayList<MatcherChangeListener>  	   matcherListeners;
	private ArrayList<VisualizationChangeListener> visualizationListeners;
	
	
	private static AppPreferences prefs;
	
	private static LexiconStore lexstore; // The Lexicon store for these ontologies.
	
	private static UI ui; 	// A reference to the userinterface instance, canvas and table can be accessed anytime. 
							// It used often to invoke the method redisplayCanvas()
	
	private static Core core  = new Core(); // Singleton pattern: unique instance

	private AMHost osgi;
	
	
	/**
	 * 
	 * @return the unique instance of the core
	 */
	public static Core getInstance() {
		return core;
	}
	/**
	 * It's private because it's not possible to create new instances of this class
	 */
	private Core() {
		
		//System.setProperty("log4j.debug","strue" );  // Use this to see what log4j gets configured to.
	
		amRoot = System.getenv("AM_ROOT");

		if( amRoot == null ) {
			// Check if AM_ROOT is a sibling project in the Eclipse Workspace, which is a typical setup
			final File defaultPath = new File("../AM_ROOT"); 
			if( defaultPath.exists() ) {
				if( !defaultPath.isDirectory() ) {
					log.warn("Cannot use Default directory for AM_ROOT because it is a file: " + defaultPath.getAbsolutePath());
				}
				else if( !defaultPath.canRead() ) {
					log.warn("Cannot use default directory for AM_ROOT because it does not have read permissions: " + defaultPath.getAbsolutePath());
				}
				else {
					amRoot = defaultPath.getAbsolutePath();
				}
			}
			else {
				log.warn("The environment variable AM_ROOT is not set.  Using working directory as our root.");
				amRoot = System.getProperty("user.dir", (new File(".")).getAbsolutePath());
			}
		}
		
		log.info("AgreementMaker root directory: " + amRoot);
{'fraction_non_alphanumeric': 0.08103147655317977, 'fraction_numerical': 0.002018904285583188, 'mean_word_length': 4.24446583253128, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7372440', 'n_tokens_mistral': 3208, 'n_tokens_neox': 2937, 'n_words': 1124}