<commit_before>package am.batchMode;

import am.GlobalStaticVariables;
import am.Utility;
import am.application.Core;
import am.application.mappingEngine.AlignmentSet;
import am.application.mappingEngine.MatchersRegistry;
import am.application.mappingEngine.oaei2009.OAEI2009parameters;
import am.application.ontology.ontologyParser.OntoTreeBuilder;
import am.output.AlignmentOutput;

import java.io.*;
import java.util.Vector;

public class ConferenceTrack extends Track {

	public final static String AM_NAME = "amaker";
	public final static String OAEI_DIR = "./OAEI09/";
	public final static String OAEI_OUTPUT_DIR = OAEI_DIR+AM_NAME+"/";
	public final static String TRACK_DIR = "conference/";
	public final static String TRACK_INPUT_DIR = OAEI_DIR+TRACK_DIR;
	public final static String TRACK_OUTPUT_DIR = OAEI_OUTPUT_DIR+TRACK_DIR;
	
	private String ontodir; // ontology files directory

	private File[] ontologyFiles;

	
	public ConferenceTrack(String directory) {
		super();
		
		ontodir = directory;
	}
	
	
	public void execute() throws Exception {

		// get a list of the conference track ontology files.
		ontologyFiles = getOntologyFiles();
		if( ontologyFiles == null ) { 
			System.out.println("Error loading ontology files."); 
			System.exit(1); 
		}
		
		// compare each ontology to every other ontology
		for( int i = 0; i < ontologyFiles.length - 1; i++ ) {		
			for( int j = i+1; j < ontologyFiles.length; j++ ) {
				computeMatching( i, j );
			}
		}
		
	}
	
	
	private void computeMatching( int sourceIndex, int targetIndex ) throws Exception {
		System.out.println("Matching: " + ontologyFiles[sourceIndex].getName() + " <-> " + ontologyFiles[targetIndex].getName() );
		
		
		MatchersRegistry matcher = MatchersRegistry.OAEI2009;
		OAEI2009parameters param = new OAEI2009parameters(OAEI2009parameters.CONFERENCE);
		
		double threshold = 0.6;
		int sourceCardinality = 1;
		int targetCardinality = 1;
		
		
		String sourceOntology;
		String targetOntology;
		String sourceUri;
		String targetUri;
		AlignmentSet as;
		AlignmentOutput ao;
		String outputFileDir;
		long startTime = System.nanoTime()/1000000;
		
		sourceOntology = ontologyFiles[sourceIndex].getAbsolutePath();
		targetOntology = ontologyFiles[targetIndex].getAbsolutePath();

		as = computeAlignment(sourceOntology, targetOntology, GlobalStaticVariables.LANG_OWL, GlobalStaticVariables.SYNTAX_RDFXML, true, matcher, threshold, sourceCardinality, targetCardinality, param);
		sourceUri = Core.getInstance().getSourceOntology().getURI();
		targetUri = Core.getInstance().getTargetOntology().getURI();
			
	
		outputFileDir = TRACK_OUTPUT_DIR;//the last / is not needed for mkdirs but is needed later
		(new File(outputFileDir)).mkdirs();//create directories
		
		ao = new AlignmentOutput(as, outputFileDir+"/" + removeFileExtension(ontologyFiles[sourceIndex].getName()) + "-"+ removeFileExtension(ontologyFiles[targetIndex].getName()) +".rdf");
		ao.write(sourceUri, targetUri, sourceUri, targetUri);
		
		long endTime = System.nanoTime()/1000000;
		long totTime = endTime - startTime;
		System.out.println("Total execution time in h.m.s.ms: "+Utility.getFormattedTime(totTime));
		String timeFileName = TRACK_OUTPUT_DIR+"executionTime.txt";
		TrackDispatcher.printExecutionTime(totTime, timeFileName);
	}
	
	/**<commit_msg>Correctly calculate total running time.<commit_after>package am.batchMode;

import am.GlobalStaticVariables;
import am.Utility;
import am.application.Core;
import am.application.mappingEngine.AlignmentSet;
import am.application.mappingEngine.MatchersRegistry;
import am.application.mappingEngine.oaei2009.OAEI2009parameters;
import am.application.ontology.ontologyParser.OntoTreeBuilder;
import am.output.AlignmentOutput;

import java.io.*;
import java.util.Vector;

public class ConferenceTrack extends Track {

	public final static String AM_NAME = "amaker";
	public final static String OAEI_DIR = "./OAEI09/";
	public final static String OAEI_OUTPUT_DIR = OAEI_DIR+AM_NAME+"/";
	public final static String TRACK_DIR = "conference/";
	public final static String TRACK_INPUT_DIR = OAEI_DIR+TRACK_DIR;
	public final static String TRACK_OUTPUT_DIR = OAEI_OUTPUT_DIR+TRACK_DIR;
	
	private String ontodir; // ontology files directory

	private File[] ontologyFiles;

	
	public ConferenceTrack(String directory) {
		super();
		
		ontodir = directory;
	}
	
	
	public void execute() throws Exception {

		// get a list of the conference track ontology files.
		ontologyFiles = getOntologyFiles();
		if( ontologyFiles == null ) { 
			System.out.println("Error loading ontology files."); 
			System.exit(1); 
		}
		
		long startTime = System.nanoTime()/1000000;
		
		// compare each ontology to every other ontology
		for( int i = 0; i < ontologyFiles.length - 1; i++ ) {		
			for( int j = i+1; j < ontologyFiles.length; j++ ) {
				computeMatching( i, j );
			}
		}
		
		long endTime = System.nanoTime()/1000000;
		long totTime = endTime - startTime;
		System.out.println("Total execution time in h.m.s.ms: "+Utility.getFormattedTime(totTime));
		String timeFileName = TRACK_OUTPUT_DIR+"executionTime.txt";
		TrackDispatcher.printExecutionTime(totTime, timeFileName);
		
	}
	
	
	private void computeMatching( int sourceIndex, int targetIndex ) throws Exception {
		System.out.println("Matching: " + ontologyFiles[sourceIndex].getName() + " <-> " + ontologyFiles[targetIndex].getName() );
		
		
		MatchersRegistry matcher = MatchersRegistry.OAEI2009;
		OAEI2009parameters param = new OAEI2009parameters(OAEI2009parameters.CONFERENCE);
		
		double threshold = 0.6;
		int sourceCardinality = 1;
		int targetCardinality = 1;
		
		
		String sourceOntology;
		String targetOntology;
		String sourceUri;
		String targetUri;
		AlignmentSet as;
		AlignmentOutput ao;
		String outputFileDir;
		
		sourceOntology = ontologyFiles[sourceIndex].getAbsolutePath();
		targetOntology = ontologyFiles[targetIndex].getAbsolutePath();

		as = computeAlignment(sourceOntology, targetOntology, GlobalStaticVariables.LANG_OWL, GlobalStaticVariables.SYNTAX_RDFXML, true, matcher, threshold, sourceCardinality, targetCardinality, param);
		sourceUri = Core.getInstance().getSourceOntology().getURI();
		targetUri = Core.getInstance().getTargetOntology().getURI();
			
	
		outputFileDir = TRACK_OUTPUT_DIR;//the last / is not needed for mkdirs but is needed later
		(new File(outputFileDir)).mkdirs();//create directories
		
		ao = new AlignmentOutput(as, outputFileDir+"/" + removeFileExtension(ontologyFiles[sourceIndex].getName()) + "-"+ removeFileExtension(ontologyFiles[targetIndex].getName()) +".rdf");
		ao.write(sourceUri, targetUri, sourceUri, targetUri);
		
	}
	
	/**
{'fraction_non_alphanumeric': 0.1044170673076923, 'fraction_numerical': 0.014423076923076924, 'mean_word_length': 4.901595744680851, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '6032424', 'n_tokens_mistral': 2285, 'n_tokens_neox': 1976, 'n_words': 474}