Changeset 4540


Ignore:
Timestamp:
2003-06-10T15:32:55+12:00 (21 years ago)
Author:
kjdon
Message:

have changed teh way indexes are written to and read from the config file: greenstone extracted metadata has the ex namespace internally in the gatherer, but not in the index specifications in the config file.

Location:
trunk/gli/src/org/greenstone/gatherer/cdm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMeta.java

    r4494 r4540  
    143143        text = text + ".";
    144144        Index index = (Index)name;
    145         text = text + index.toString(false) + " ";
     145        text = text + index.toStringConfig() + " ";
    146146    }
    147147    else if(name instanceof SubIndex) {
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMetaManager.java

    r4512 r4540  
    221221            ///ystem.err.println("Detected '.' prefix.");
    222222            String key_str = (String)key;
     223            key = null;
    223224            key_str = key_str.substring(1);
    224             key = manager.indexes.getIndex(key_str);
     225            Index ind = Index.parseIndexConfig(key_str, manager);
     226            if (ind != null) {
     227               
     228                key = manager.indexes.getIndex(ind.toString(false));
     229            }
     230           
    225231            // If that didn't work, then it might be a subindex so have a bash at retrieving that instead.
    226232            if(key == null) {
  • trunk/gli/src/org/greenstone/gatherer/cdm/Index.java

    r4494 r4540  
    5252import java.util.Collections;
    5353import java.util.Comparator;
     54import java.util.StringTokenizer;
    5455import java.util.Vector;
    5556import org.greenstone.gatherer.cdm.CollectionMeta;
    5657import org.greenstone.gatherer.msm.MSMUtils;
     58import org.greenstone.gatherer.util.Utility;
    5759import org.w3c.dom.Element;
    5860/** This class encapsulates a single indexing pair.
     
    7678    /** An values of items in the index level enumeration. */
    7779    static public final String LEVEL[] = {"document","paragraph","section"};
     80
    7881    /** Constructor.
    7982     * @param level The level of this index as a <strong>String</string>.
     
    121124    return result;
    122125    }
     126    /** Method to get the data source of this index.
     127     * @return A <strong>String</string> which is a comma separated list of either fully qualified names of an assigned metadata elements, or "text".
     128     * Note, greenstone extracted metadata do not have the ex.
     129     */
     130    public String getDataConfig() {
     131    String result = "";
     132    Collections.sort(sources, new IndexComparator());
     133    for(int i = 0; i < sources.size(); i++) {
     134        String source = sources.get(i).toString();
     135        if (source.startsWith("ex.")) {
     136        // remove the ex. bit
     137        source = source.substring(3);
     138        }
     139        result = result + source;
     140        if(i < sources.size() - 1) {
     141        result = result + ",";
     142        }
     143    }
     144    return result;
     145    }
     146   
    123147    /** Method to get the value of level.
    124148      * @return The value of level as a <strong>String</strong>.
     
    146170    }
    147171    return "";
     172   
    148173    }
    149174    /** Method to turn this object into a string representation ready to be placed in the collection configuration file.
     
    162187    return LEVEL[level] + ":" + getData();
    163188    }
     189   
     190    /** Retrieve a textual representation of this index, specifically for the configuration files. Extracted metadata is shown to teh user and stored as ex.MD, however in the config file it should have no namespace */
     191    public String toStringConfig() {
     192
     193    return LEVEL[level] + ":" + getDataConfig();
     194    }
     195
     196    /** Method to parse a configuration file index specification into an Index
     197     * object. returns null if invalid syntax */
     198    public static Index parseIndexConfig(String entry, CollectionDesignManager manager) {
     199    // all (mg) indexes must start with level:
     200    if(entry.indexOf(":") == -1) {
     201        return null;
     202    }
     203   
     204    String level_str = entry.substring(0, entry.indexOf(":"));
     205    String sources_raw = entry.substring(entry.indexOf(":") + 1);
     206    Vector sources = new Vector();
     207    StringTokenizer st = new StringTokenizer(sources_raw, ",");
     208    while(st.hasMoreTokens()) {
     209        String token = st.nextToken();
     210        // We may have to replace old : with whatever namespace separator we are using.
     211        token = token.replace(':', MSMUtils.NS_SEP);
     212        // if there is no namespace, we need to add one, except for text
     213        if (token.indexOf(MSMUtils.NS_SEP)==-1) {
     214        if (!token.equals("text")) {
     215            token = Utility.EXTRACTED_METADATA_NAMESPACE+MSMUtils.NS_SEP+token;
     216        }
     217        }
     218       
     219        sources.add(token);
     220    }
     221    Index index = null;
     222    for(int i = 0; i < Index.LEVEL.length; i++) {
     223        if(level_str.equals(Index.LEVEL[i])) {
     224        return new Index(i, sources, manager);
     225       
     226        }
     227    }
     228    // somethings gone wrong
     229    return null;
     230   
     231    }
     232   
    164233    /** A custom comparator for comparing Indexes. */
    165234    private class IndexComparator
  • trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java

    r4533 r4540  
    217217        while(ct.hasMoreTokens()) {
    218218        String entry = ct.nextToken();
    219         if(entry.indexOf(":") != -1) {
    220             String level_str = entry.substring(0, entry.indexOf(":"));
    221             String sources_raw = entry.substring(entry.indexOf(":") + 1);
    222             Vector sources = new Vector();
    223             StringTokenizer st = new StringTokenizer(sources_raw, ",");
    224             while(st.hasMoreTokens()) {
    225             String token = st.nextToken();
    226             // We may have to replace old : with whatever namespace separator we are using.
    227             token = token.replace(':', MSMUtils.NS_SEP);
    228             sources.add(token);
    229             }
    230             for(int i = 0; i < Index.LEVEL.length; i++) {
    231             if(level_str.equals(Index.LEVEL[i])) {
    232                 addIndex(new Index(i, sources, manager));
    233             }
    234             }
    235         }
    236         else {
     219        Index index = Index.parseIndexConfig(entry, manager);
     220        if (index != null) {
     221            addIndex(index);
     222           
     223        } else { // return false if there is one error??
    237224            return false;
    238225        }
    239226        }
     227       
    240228        return true;
    241229    }
     
    244232        ct.nextToken();
    245233        String entry = ct.nextToken();
    246         if(entry.indexOf(":") != -1) {
    247         String level_str = entry.substring(0, entry.indexOf(":"));
    248         String sources_raw = entry.substring(entry.indexOf(":") + 1);
    249         Vector sources = new Vector();
    250         StringTokenizer st = new StringTokenizer(sources_raw, ",");
    251         while(st.hasMoreTokens()) {
    252             sources.add(st.nextToken());
    253         }
    254         for(int i = 0; i < Index.LEVEL.length; i++) {
    255             if(level_str.equals(Index.LEVEL[i])) {
    256             setDefault(new Index(i, sources, manager));
    257             }
    258         }
    259         }
    260         else {
    261         return false;
    262         }
    263         return true;
    264     }
     234        Index index = Index.parseIndexConfig(entry, manager);
     235        if (index != null) {
     236        setDefault(index);
     237        return true;
     238        }
     239        return false;
     240    }
     241   
    265242    return false;
    266243    }
     
    316293        for(int i = 0; i < size(); i++) {
    317294        Index index = (Index) get(i);
    318         text = text + index.toString(false);
     295        text = text + index.toStringConfig();
    319296        if(i < size() - 1) {
    320297            text = text + " ";
    321298        }
    322299        }
    323                 // Now the default index if there is one, or just the first index
    324                 // if there isn't
     300        // Now the default index if there is one, or just the first index
     301        // if there isn't
    325302        if(default_index != null) {
    326         text = text + "\ndefaultindex " + default_index.toString(false) + "\n";
     303        text = text + "\ndefaultindex " + default_index.toStringConfig() + "\n";
    327304        }
    328305        text = text + "\n";
     
    330307    return text;
    331308    }
     309
     310
     311
     312
     313   
    332314    /** Overloaded to call get with both a key and an empty argument array.
    333315      * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
Note: See TracChangeset for help on using the changeset viewer.