/** * */ 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.ontology.OntoUtil; import oboannotator.util.AppConfig; import oboannotator.util.UserCommand; import oboannotator.util.Util; /** * @author ahmedabdeenhamed * */ public class OBO_DocumentAnalyzerApplication { /** * @param args */ public static void main(String[] args) { Hashtable fileOrderNamePair = new Hashtable(); ArrayList userSelectedEnginesList = new ArrayList(); String primAEName = null; String ontologyURI= null; String dictionaryName=null; System.out.println(" |--------------------------------------------------------|"); System.out.println(" | Welcome to OBO-Annotator Application |"); 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("Following is the list of available dictionary\n"); //String primitiveDescriptorsLocation = AppConfig.PRIMITIVE_AE_LOCATION; //System.out.print("current directory" + primitiveDescriptorsLocation); System.out.println(AppConfig.DICTIONARY_AE_DIR); fileOrderNamePair = Util.getFilesByDirectoryName(AppConfig.DICTIONARY_AE_DIR); //System.out.println(fileOrderNamePair); 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(AppConfig.INCLUDE_DICTION)){ // turn the INCLUDE flag to true... AppConfig.INCLUDE=true; Integer anInt = new Integer(uComm.getIntCommand()); if(fileOrderNamePair.get(anInt.toString())==null){ System.out.println("Invalid descriptor, command is ignored..."); continue; } primAEName = fileOrderNamePair.get(anInt.toString()); userSelectedEnginesList.add(primAEName); }else if(uComm.getCommand().equals(AppConfig.ADD_NEW_DICTION)){ // 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....."); if(OntoUtil.oboOrOwl(ontologyURI).equals(OntoUtil.OBO)){ OBO_toLexiconConverter.compileDictionaryFromOboUri(ontologyURI, dictionaryName, AppConfig.DICTIONARY_DIR, AppConfig.ADD_NEW_DICTION); } if(OntoUtil.oboOrOwl(ontologyURI).equals(OntoUtil.OWL)){ OBO_toLexiconConverter.compileDictionaryFromOwlURI(ontologyURI, dictionaryName, AppConfig.DICTIONARY_DIR, AppConfig.ADD_NEW_DICTION); } System.out.println("Generating the primitive analysis engine for the dictionary..."); try { UserCustomedAEApplication.composePrimitiveAE(dictionaryName, AppConfig.ADD_NEW_DICTION); } catch (IOException e) { System.out.println("Error message is: " + e.getMessage()); } }else if(uComm.getCommand().equals(AppConfig.UPDATE_DICTION)){ Integer anInt = new Integer(uComm.getCommandOption()); if(fileOrderNamePair.get(anInt.toString())==null){ System.out.println("Invalid dictionary name, 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()); String validDictionaryName = Util.removeString(dictionaryName, "AE.xml"); if(OntoUtil.oboOrOwl(ontologyURI).equals(OntoUtil.OBO)){ OBO_toLexiconConverter.compileDictionaryFromOboUri(ontologyURI, validDictionaryName, AppConfig.DICTIONARY_DIR, AppConfig.ADD_NEW_DICTION); } if(OntoUtil.oboOrOwl(ontologyURI).equals(OntoUtil.OWL)){ OBO_toLexiconConverter.compileDictionaryFromOwlURI(ontologyURI, validDictionaryName, AppConfig.DICTIONARY_DIR, AppConfig.ADD_NEW_DICTION); } System.out.println("Upadting the primitive analysis engine for the dictionary..."); try { UserCustomedAEApplication.composePrimitiveAE(dictionaryName, AppConfig.UPDATE_DICTION); } catch (IOException e) { System.out.println("Error message is: " + e.getMessage()); } // 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(AppConfig.INCLUDE){ // take the files and create a new descriptor try { UserCustomedAEApplication.composeAggregateAE(userSelectedEnginesList); // annotate documents... OBO_DocumentAnalyzer.annotateDocuments(AppConfig.AGGREGATE_AE_DIR+AppConfig.USER_ASSEMBLED_AGGREGATE_AE, AppConfig.INPUT_FILES_DIR); } catch (IOException e) { System.out.println("Here is the error: \n" + e.getMessage()); e.printStackTrace(); } } System.out.println("\n\n"); System.out.println("Application finished processing ..."); System.out.println("Exiting the OBO-Annotator Tool ..."); System.out.println("Goodbye!"); } }