/** * */ package oboannotator.application; import java.io.IOException; import java.util.ArrayList; import java.util.Hashtable; import java.util.Scanner; import oboannotator.ontology.OBO_toLexiconConverter; import oboannotator.util.AppConfig; import oboannotator.util.UserCommand; import oboannotator.util.Util; /** * @author ahmedabdeenhamed * */ public class OBO_AnnotatorTool { private static String DICTIONARY_PATH ="/Users/ahmedabdeenhamed/Projects/concept-mapper-project/oboannotator/resources/dict"; private static final String DICTIONARY_EXTENSION=".xml"; private static boolean INCLUDE=false; private static boolean UPDATE=false; private static boolean ADD=false; /** * @param args */ public static void main(String[] args) { Hashtable fileOrderNamePair = new Hashtable(); ArrayList userSelectedEnginesToInclude = new ArrayList(); String aggAEName = null; String aggAEDir = null; String primAEName = null; String primAEDir = null; String ontologyURI= null; String dictionaryName=null; System.out.println(" -|----------------------------------|-"); System.out.println(" -|Welcome to MBL OBO-Annotator Tool!|-"); System.out.println(" -|----------------------------------|-"); System.out.println("\n\n"); System.out.println(" |------------------------------------------------------------------------------|"); System.out.println(" | This application allows users to do the following: |"); System.out.println(" | 1) Add new dictionaries from exiting Ontologies |"); System.out.println(" | - For Adding new dictionaries, users should enter the command 'A' |"); System.out.println(" | |"); System.out.println(" | 2) Update existing dictionaries from the list below: |"); System.out.println(" | - For Updating compiled dictionaries, users should enter the command Udict# |"); System.out.println(" | |"); System.out.println(" | 3) Include existing dictionares from the list below: |"); System.out.println(" | - For Including a dictionary, users must enter the dictionary# on the list |"); System.out.println(" |------------------------------------------------------------------------------|"); System.out.println("\n"); System.out.println("Please enter the dictionaries directory: "); String dictDir = new Scanner(System.in).nextLine().toString(); if(dictDir.equals("") || dictDir==null){ System.out.println("Invalid directory, application is terminating now..."); System.exit(0); } fileOrderNamePair = Util.getFilesByDirectoryName(dictDir); System.out.println("Following is a list of the available dictionaries:"); // display existing dictionaries and their order on the hashtable for(int i = 0; i < fileOrderNamePair.size(); i++){ System.out.println(new Integer(i+1).toString() + ": " + fileOrderNamePair.get(new Integer(i+1).toString())); } System.out.println("\n"); System.out.print("Please enter your commands seperated by commas \",\": \n"); String userInput = new Scanner(System.in).nextLine().toString(); ArrayList uComms = Util.interpretUserInput(userInput); if(uComms==null){ System.out.println("Invalid Entry, application is terminating now...."); System.exit(0); } for(UserCommand uComm: uComms){ if(uComm.getCommand().equals("INCLUDE_DICTIONARY")){ // turn the INCLUDE flag to true... OBO_AnnotatorTool.INCLUDE=true; Integer anInt = new Integer(uComm.getIntCommand()); if(fileOrderNamePair.get(anInt.toString())==null){ System.out.println("Invalid descriptor, command is ignored..."); continue; } if(primAEDir==null){ System.out.print("Please enter primitive AE directory: \n"); primAEDir = new Scanner(System.in).nextLine().toString(); if(primAEDir.equals("") || primAEDir==null){ System.out.println("Invalid directory, command is ignored..."); continue; } } System.out.println("\nINCLUDE-DICTIONARY: " + fileOrderNamePair.get(anInt.toString()) + " command is in action..."); System.out.println("----------------------------------------------"); //userSelectedList.add(fileOrderNamePair.get(uComm.getIntCommand())); System.out.println("Please enter the primitive engine associated with the dictionary: "); primAEName = new Scanner(System.in).nextLine().toString(); if(primAEName.equals("") || primAEName==null){ System.out.println("Invalid engine name, command is ignored..."); continue; } userSelectedEnginesToInclude.add(primAEName); // if(aggregateEnginesFileName==null){ // System.out.println("Please enter a name for the new aggregate engine: "); // aggregateEnginesFileName = new Scanner(System.in).nextLine().toString(); // } }else if(uComm.getCommand().equals("ADD_NEW_DICTIONARY")){ // 1- Ask for ontology URI // 2- Ask for a unique dictionary name // 3- add the new dctionary name System.out.println("\nADD-NEW-DICTIONARY command is in action..."); System.out.println("-------------------------------------------"); System.out.println("Enter Ontology URI that you would like to add: "); ontologyURI = new Scanner(System.in).nextLine(); if (ontologyURI.equals("") || ontologyURI==null){ System.out.println("Invalid ontology URI, command is ignored...."); continue; } System.out.println("Enter a dictionary name for your ontology: "); dictionaryName = new Scanner(System.in).nextLine(); if (dictionaryName.equals("") || dictionaryName==null){ System.out.println("Invalid dictionary name, command is ignored...."); continue; } System.out.println("Creating dictionary, this might take several minutes....."); OBO_toLexiconConverter.compileDictionaryFromOboUri(ontologyURI, dictionaryName, dictDir, AppConfig.ADD_NEW_DICTION); // generating the associated descriptor for a primitive engine System.out.println("Enter a primitive engine name to assocaite with the created dictionary: "); primAEName = new Scanner(System.in).nextLine(); if (primAEName==null || primAEName.equals("")){ System.out.println("Invalid descriptor name, command is ignored...."); continue; } System.out.println("Enter a directory location for the primitive engine: "); primAEDir = new Scanner(System.in).nextLine(); if (primAEDir==null || primAEDir.equals("")){ System.out.println("Invalid directory name, command is ignored...."); continue; } System.out.println("Generating the primitive analysis engine for the dictionary..."); try { UserCustomedAEApplication.composePrimitiveAE(dictionaryName, "ADD"); } catch (IOException e) { System.out.println("Error message is: " + e.getMessage()); } }else if(uComm.getCommand().equals("UPDATE_DICTIONARY")){ Integer anInt = new Integer(uComm.getCommandOption()); //System.out.println("\n\n---------------------------------"); if(fileOrderNamePair.get(anInt.toString())==null){ System.out.println("Invalid file number, command is ignored...."); continue; } System.out.println("\nUPDATE-DICTIONARY " + fileOrderNamePair.get(anInt.toString()) + " command is in action..."); System.out.println("-------------------------------------------"); System.out.println("Enter Ontology URI that you would like to update:"); ontologyURI = new Scanner(System.in).nextLine(); if (ontologyURI.equals("") || ontologyURI==null){ System.out.println("Invalid ontology URI, command is ignored...."); continue; } System.out.println("Updating dictionary, this might take several minutes....."); dictionaryName = fileOrderNamePair.get(anInt.toString()); OBO_toLexiconConverter.compileDictionaryFromOboUri(ontologyURI, dictionaryName, dictDir, AppConfig.UPDATE_DICTION); // lookup the file name from the hashtable using the intCommand // then override that file on the file system...... }else{ System.out.println("This should never get executed"); } } if(OBO_AnnotatorTool.INCLUDE){ System.out.println("Please enter a name for the new aggregate engine: "); aggAEName = new Scanner(System.in).nextLine().toString(); if (aggAEName.equals("") || aggAEName==null){ System.out.println("Invalid file name, operation is ignored...."); System.exit(0); } System.out.println("Please enter the path where for the new aggregate engine: "); aggAEDir = new Scanner(System.in).nextLine().toString(); if (aggAEDir.equals("") || aggAEDir==null){ System.out.println("Invalid directory name, operation is ignored...."); System.exit(0); } // take the files and create a new descriptor try { UserCustomedAEApplication.composeAggregateAE(userSelectedEnginesToInclude); } catch (IOException e) { System.out.println("Here is the error: \n" + e.getMessage()); e.printStackTrace(); } } System.out.println("\n\n"); System.out.println("Exiting the OBO-Annotator Tool ...."); System.out.println("Goodbye ..."); } }