Changeset 3481


Ignore:
Timestamp:
09/08/10 10:20:57 (17 months ago)
Author:
antonak
Message:

Just some comments added.

Location:
biobank_search/handwritten/java/plugins
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • biobank_search/handwritten/java/plugins/Annotator.java

    r3413 r3481  
    1111import uk.ac.ebi.ontocat.OntologyTerm; 
    1212 
    13 /* 
     13/** 
    1414 * Annotates the input text: searches words and phrases in ontologies and adds XML tags to found terms  
    1515 */ 
  • biobank_search/handwritten/java/plugins/DBIndexPlugin.java

    r3425 r3481  
    6060         
    6161         
    62         static final String LUCENE_INDEX_DIRECTORY = "/Users/jorislops/Documents/workspace/Dasha/molgenis_db_index"; 
     62        static final String LUCENE_INDEX_DIRECTORY = "/Users/despoina/Documents/biobank_search_index/molgenis_db_index"; 
    6363        static final String PROJECTNAME = "biobank_search";  //TODO : This should be retrieved, not hardcoded.   
    6464        List<String> OntologiesForExpansion = null; 
     
    109109                if (ontologies.isEmpty()){ 
    110110                        System.out.println("[Ontologies] is empty"); 
    111                         this.setStatus("<h4>choose the ontologies to use for query expansion</h4>"); 
     111                        this.setStatus("<h4>Choose the ontologies to use for query expansion</h4>"); 
    112112                } 
    113113                 
    114114                setOntologiesForExpansion(ontologies); 
    115                 System.out.println("ontologies : " + ontologies); 
     115                System.out.println("Ontologies : " + ontologies); 
    116116                 
    117117                 
     
    345345         
    346346         
     347        /** 
     348         * The function for query expansion.  
     349         * Creates a new (empty) instance of OntocatQueryExpansion_lucene class  
     350         * @param db 
     351         */ 
    347352        public void ExpandQuery(Database db){ 
    348353 
  • biobank_search/handwritten/java/plugins/OntoCatIndexPlugin2.java

    r3425 r3481  
    4141 
    4242 
    43 /* 
    44  * Indexes all ontologies specified in ontologyNamesMap. The ontologies should be downloaded on the computer in ONTOLOGIES_DIRECTORY 
     43/** 
     44 * Indexes all ontologies specified in ontologyNamesMap.  
     45 * The ontologies should be downloaded on the computer in ONTOLOGIES_DIRECTORY 
    4546 * Searches through the index  
    4647 *  
     
    5556        private String InputToken = "lung disease"; 
    5657        // 
    57         static final String LUCENE_ONTOINDEX_DIRECTORY = "/Users/jorislops/Documents/workspace/Dasha/biobank_search"; 
    58         static final String ONTOLOGIES_DIRECTORY = "/Users/jorislops/Documents/workspace/Dasha/biobank_search/ontologies/"; 
     58        static final String LUCENE_ONTOINDEX_DIRECTORY = "/Users/despoina/Documents/biobank_search_index/"; 
     59    static final String ONTOLOGIES_DIRECTORY = "/Users/despoina/Documents/workspace/biobank_search/ontologies"; 
     60 
     61                                                                                         
    5962 
    6063        public static final Map<String , String> ontologyNamesMap = new HashMap<String, String>() {{ 
     
    170173                        collector = TopScoreDocCollector.create(1000, true); 
    171174         
    172                         //making a boolean query to specify in which ontologies to search  
     175                        /** 
     176                         * making a boolean query to specify in which ontologies to search  
     177                         */ 
    173178                        BooleanQuery labelQuery = new BooleanQuery(); 
    174179                        BooleanQuery finalQuery = new BooleanQuery(); 
     
    179184                        } 
    180185                 
    181                         //the query to search the term in the field "term" 
     186                        /** 
     187                         * the query to search the term in the field "term" 
     188                         */ 
    182189                        query2 = new TermQuery(new Term("term", query)); 
    183190                         
    184                         //merging 2 queries together 
     191                        /** 
     192                         * merging 2 queries together 
     193                         */ 
    185194                        finalQuery.add(query2, BooleanClause.Occur.MUST); 
    186195                        finalQuery.add(labelQuery, BooleanClause.Occur.MUST); 
     
    246255           try { 
    247256                   System.out.println("Start Indexing Ontocat results") ; 
    248                    this.setStatus("Starting indexing Ontocat results in " + 
    249                 LUCENE_ONTOINDEX_DIRECTORY); 
     257                   this.setStatus("Starting indexing Ontocat results in " + LUCENE_ONTOINDEX_DIRECTORY); 
    250258         
    251259                   file = new File(LUCENE_ONTOINDEX_DIRECTORY); 
    252260                   analyzer = new StandardAnalyzer(Version.LUCENE_30); 
    253                    writer = new IndexWriter(FSDirectory.open(file), analyzer, true, 
    254                    IndexWriter.MaxFieldLength.UNLIMITED); 
     261                   writer = new IndexWriter(FSDirectory.open(file), analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); 
    255262                     
    256                    for(String ontology_file: ontologyNamesMap.keySet()){ 
     263                   for (String ontology_file: ontologyNamesMap.keySet()){ 
    257264                           say("now " + writer.getReader().numDocs() + " terms indexed"); 
    258265                         
     
    267274                           for(OntologyTerm term: all_terms) 
    268275                           { 
    269                                    //getting the term with ontology label inside the index 
    270                                    //for each term we use a separate Document 
     276                                   /** 
     277                                    * getting the term with ontology label inside the index 
     278                                    * for each term we use a separate Document 
     279                                    */ 
     280                                    
    271281                               Document document = new Document(); 
    272282                               Field termField = new Field("term", term.getLabel().toLowerCase(), Field.Store.YES, Field.Index.NOT_ANALYZED); 
     
    277287                               document.add(ontologyLabelField); 
    278288         
    279                                //searching for synonyms and children in ontology, writing them to "expansion" with delimiters ";" 
     289                               /** 
     290                                * searching for synonyms and children in ontology, writing them to "expansion" with delimiters ";" 
     291                                */ 
    280292                               List<OntologyTerm> children = new ArrayList<OntologyTerm>(); 
    281293                               List<String> syns = new ArrayList <String>(); 
     
    285297                               //System.out.println("syns:\n" + syns); 
    286298                               for (String s : syns){ 
    287                                    if (term.getLabel().toLowerCase() != s){ 
     299                                   if (term.getLabel().toLowerCase() != s){ //if it doesn't already exists  
    288300                                           s = "\"" + s.toLowerCase() + "\""; 
    289301                                           //System.out.println("syns: " + s); 
     
    309321         
    310322                    } 
    311                     //optimize the index 
     323                    /** 
     324                     * optimize the index 
     325                     */ 
    312326                    System.out.println(": Optimizing Index :" ); 
    313327                    this.setStatus("Optimizing Ontocat Index" ); 
  • biobank_search/handwritten/java/plugins/OntocatQueryExpansion_lucene.java

    r3413 r3481  
    1919import uk.ac.ebi.ontocat.virtual.CompositeDecorator; 
    2020 
    21 /* 
     21/** 
    2222 *  Expands the query by adding synonyms and children to initial query, using Boolean OR (not necessary, but more convenient to look through the query), expansion terms are weighted less than initial query terms  
    2323 *  @param query_terms - chunks: all possible combinations of query terms(subsequent) 
     
    5858        } 
    5959 
    60         //chunking the query into strings of different length 
     60        /** 
     61         * Chunking the query into strings of different length  
     62         */ 
    6163        public List<String> chunk (List<String> words){ 
    6264                String q = ""; 
     
    7981        } 
    8082         
    81         // generating a list of possible word combinations of different length from 
    82         // the query and setting it as query_terms 
     83        /** 
     84         * generating a list of possible word combinations of different length from  
     85         * the query and setting it as query_terms 
     86         */ 
    8387        public List<String> parseQuery(String query) 
    8488        { 
     
    9094                 
    9195                 
    92                 String ignore = "[,.\\:\\!\\?;]"; //punctuation to be ignored 
    93                 query = query.replaceAll(ignore, " ").trim(); //remove punctuation 
    94                  
    95                 //replacing special symbols 
     96                String ignore = "[,.\\:\\!\\?;]";  /** punctuation to be ignored*/ 
     97                query = query.replaceAll(ignore, " ").trim(); /** remove punctuation */ 
     98                 
     99                /** replacing special symbols */ 
    96100                query = query.replaceAll("( *OR)|(OR *)", "|"); 
    97101                query = query.replaceAll(" *AND *", "&"); 
    98102                query = query.toLowerCase(); 
    99103                int len = query.length(); 
    100                 //splitting by ' ' and by spec_symbols, leaving phrases in "" as single unit phrases 
     104                //* splitting by ' ' and by spec_symbols, leaving phrases in "" as single unit phrases */ 
    101105                while(i < len){ 
    102106                         
     
    154158                         
    155159                } 
    156                 //setting the initial query list (with Boolean operators) 
     160                 
     161                /** 
     162                 * setting the initial query list (with Boolean operators)  
     163                 */ 
    157164                setInit_query(words); 
    158165                 
     
    160167                List<String> tmp = new ArrayList<String>(); 
    161168                 
    162                 //chunking the query into all possible n-grams, skipping the Boolean operators 
     169                /** 
     170                 * chunking the query into all possible n-grams, skipping the Boolean operators 
     171                 */ 
    163172                int size = words.size(); 
    164173                for (int x = 0; x < size; x++){ 
     
    178187        } 
    179188         
    180         //convert String[] to List<String>, removing repeated elements 
     189        /**  
     190         * convert String[] to List<String>, removing repeated elements 
     191         * @param arr 
     192         * @return 
     193         */ 
    181194        public List<String> array2listNotDuplicate (String[] arr){ 
    182195                List<String> list = new ArrayList<String>(); 
     
    189202        } 
    190203         
    191         //query expansion. Changes init_query by adding expansion terms after found terms and joining found phrase terms  
     204        /** 
     205         * Query expansion. Changes init_query by adding expansion terms after found terms and joining found phrase terms  
     206         * hrase - current part of the query 
     207         * found_terms - terms found in ontologies 
     208         * searcher.SearchIndexOntocat(String phrase, List<Strings> ontologies) searches the phrase in index files of ontologies, returns (term:syn1;syn2;...;child1;child2;...) 
     209         * expansion - synonyms + children 
     210         * found all - found_terms + expansion 
     211         * @param ontologiesToUse 
     212         */ 
    192213        public void expand(List<String> ontologiesToUse) { 
    193214                /* 
     
    209230                        OntoCatIndexPlugin2 searcher = new OntoCatIndexPlugin2("x",null); 
    210231                         
    211                         //searching the phrase in ontologies 
     232                        /** 
     233                         * searching the phrase in ontologies 
     234                         */ 
    212235                        List<String> found_terms = new ArrayList<String>(); 
    213236                        for( String str : searcher.SearchIndexOntocat(phrase, ontologiesToUse).split(":")) 
     
    223246                                List<String> expansion = new ArrayList<String>(); 
    224247                                 
    225                                 //adding the phrase and expansion terms 
     248                                /** adding the phrase and expansion terms */ 
    226249                                found_all.add(phrase.toLowerCase()); 
    227250                                if (!found_all.contains(found_terms.get(0))) 
     
    237260 
    238261                                 
    239                                 //replacing the words in init_query, corresponding to the phrase, with the expanded phrase (found_all)  
     262                                /** replacing the words in init_query, corresponding to the phrase, with the expanded phrase (found_all) */ 
    240263                                String[] spl = phrase.split(" "); 
    241264                                String first_word = spl[0]; 
     
    271294 
    272295                                 
    273                                 // replacing phrases, containing words from the found phrase, from query terms (to avoid duplicate expansions, to reduce the time spent on searching) 
     296                                /**  
     297                                 * replacing phrases, containing words from the found phrase, from query terms  
     298                                 * (to avoid duplicate expansions, to reduce the time spent on searching)  
     299                                 */ 
    274300                                z = 0; 
    275301                                List<String> new_query_terms = new ArrayList<String>(); 
     
    294320        } 
    295321 
    296         //constructing the expanded query 
     322        /** 
     323         * constructing the expanded query 
     324         * @param parsed 
     325         * @return 
     326         */ 
    297327        //TODO: do it with the help of Lucene. OR isn't necessary, ' ' = OR 
    298328        public String output(List<String> parsed) { 
     
    306336                                String next = init_query.get(i + 1); 
    307337                                if ((parsed.contains(s)) || (spec_symbols.contains(s))) { 
    308                                         // to avoid having stopwords in "" 
     338                                        /** 
     339                                         *  to avoid having stopwords in "" 
     340                                         */ 
    309341                                        if (s.split(" ").length == 1) 
    310342                                                res_query += s + " "; 
  • biobank_search/handwritten/java/plugins/OntologyIndexerAndSearcher.java

    r3413 r3481  
    4242public class OntologyIndexerAndSearcher { 
    4343 
    44         static final String INDEX_DIRECTORY = "C:/Dasha/studies/programming/eclipse/GEO_ontocat_index";  
    45         static final String ONTOLOGIES_DIRECTORY = "C:/Dasha/ontologies/"; 
     44        //static final String INDEX_DIRECTORY = "C:/Dasha/studies/programming/eclipse/GEO_ontocat_index";        
     45        static final String INDEX_DIRECTORY = "/Users/despoina/Documents/dashaworkspace/GEO_ontocat_index"; 
     46        //static final String ONTOLOGIES_DIRECTORY = "C:/Dasha/ontologies/"; 
     47        static final String ONTOLOGIES_DIRECTORY = "/Users/despoina/Documents/workspace/biobank_search/ontologies";  
    4648 
    4749        OntologyService os; 
     
    6163 
    6264        public void buildIndexOntocat() throws Exception { 
    63              try { 
     65          try { 
    6466                
    6567            /**An IndexWriter creates and maintains an index. 
Note: See TracChangeset for help on using the changeset viewer.