Ignore:
Timestamp:
2004-01-06T11:46:04+13:00 (20 years ago)
Author:
cs025
Message:

Modified indexerinterface to allow easier configuration, improved MG section handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/indexers/MGIndexer.java

    r6283 r6349  
    3535  List         indexes;
    3636  String       level;
    37 
    38   public static final String MG_INDEX = "Index";
     37  String       field;
    3938
    4039  class MGIndex
     
    4241    String field;
    4342
     43    public MGIndex(String level, String field)
     44    { this.level = level;
     45      this.field = field;
     46    }
     47
    4448    public MGIndex(String indexLabel)
    4549    { int colonAt = indexLabel.indexOf(':');
     50   
    4651      if (colonAt >= 0)
    4752      { field = indexLabel.substring(colonAt+1);
    4853        level = indexLabel.substring(0, colonAt);
    49       }
    50       else
    51       {
    5254      }
    5355    }
     
    9193  /**
    9294   *  The output directory should be (collection)/building/text/ for
    93    *  normal Greenstone builds
     95   *  normal Greenstone builds.
     96   *
     97   *  @param <code>String</code> the label to configure
     98   *  @param <code>String</code> the value...
    9499   */
    95100  public boolean configure(String label, String value)
     
    114119      System.out.println("Output MG directory is " + this.textStem);
    115120    }
    116     else if (label.equals(MG_INDEX)) {
     121    else if (label.equals(IndexerInterface.GS2_INDEX_LABEL)) {
    117122      this.indexes.add(new MGIndex(value));
    118123    }
     
    121126  }
    122127
     128  public boolean addIndex(String level, String field)
     129  {
     130    MGIndex index = new MGIndex(level, field);
     131    this.indexes.add(index);
     132    return true;
     133  }
     134
    123135  private Node recurseDOM(DocumentInterface metsDoc, Node node,
    124               AbstractStructure structure, StringBuffer buffer)
     136              AbstractStructure structure, StringBuffer buffer,
     137              String namespace, String field)
    125138  {
    126139    // send out the ctrl-c...if this is
     
    146159      buffer.append((char) 3);
    147160      if (this.level != null &&
    148       this.level.equals("section")) {
     161      this.level.equals(IndexerInterface.SECTION_LEVEL)) {
    149162    buffer.append((char) 2);
    150163      }
     
    152165    }
    153166
    154     // go through our children as required...
     167    // go through our children if required...
    155168    Iterator children = structure.getChildIterator();
    156169    while (children.hasNext()) {
    157170      AbstractStructure child = (AbstractStructure) children.next();
    158 
     171     
    159172      // get xpointer for child
    160173      // get start position node
    161174      Node startNode = ((HTMLDocument) metsDoc).getSectionStartNode((METSDivision) child);
    162 
    163       // while this node isn't the child's start node, produce the node
    164       while (node != startNode) {
    165     XPointer.printNode(node, buffer, false);
    166     // print buffer to node
    167     node = XPointer.getNextNode(node, buffer);
    168       }
    169 
     175     
     176      // while this node isn't the child's start node, produce the node text
     177      if (field.equals("text")) {
     178    while (node != startNode) {
     179      XPointer.printNode(node, buffer, false);
     180
     181      // print buffer to node
     182      node = XPointer.getNextNode(node, (field.equals("text") ? buffer : null));
     183    }
     184      }
     185     
    170186      // recurse to child
    171       this.recurseDOM(metsDoc, node, child, buffer);
     187      this.recurseDOM(metsDoc, node, child, buffer, namespace, field);
    172188    }
    173189
     
    176192    if (structure.getStructureType().equals(METSStructure.STRUCTURE_TYPE)) {
    177193      while (node != null) {
    178     XPointer.printNode(node, buffer, false);
    179     node = XPointer.getNextNode(node, buffer);
     194    if (field.equals("text")) {
     195      XPointer.printNode(node, buffer, false);
     196    }
     197    else {
     198      METSDescriptive descriptive;
     199
     200      if (structure.getStructureType().equals(METSDivision.DIVISION_TYPE)) {
     201        METSDivision division = (METSDivision) structure;
     202
     203        String metadataId = division.getDefaultMetadataReference();
     204       
     205        descriptive = metsDoc.getDocumentMetadata().getDescriptiveById(metadataId);
     206        if (descriptive != null) {
     207          List values = descriptive.getMetadata(namespace, field);
     208         
     209          Iterator valueIter = values.iterator();
     210          while (valueIter.hasNext()) {
     211        String value = valueIter.next().toString();
     212       
     213        buffer.append(value);
     214        if (valueIter.hasNext()) {
     215          buffer.append((char) 3);
     216        }
     217          }
     218        }
     219      }
     220    }
     221    node = XPointer.getNextNode(node, (field.equals("text") ? buffer : null));
    180222      }
    181223      buffer.append((char) 3);
     
    185227  }
    186228
    187   private String prepareDOM(DocumentInterface metsDoc, Document document, METSStructure structure)
     229  private String prepareDOM(DocumentInterface metsDoc, Document document, METSStructure structure, String namespace, String field)
    188230  { Node node = document.getDocumentElement();
    189231    StringBuffer textBuffer = new StringBuffer();
    190232   
    191     this.recurseDOM(metsDoc, node, structure, textBuffer);
     233    this.recurseDOM(metsDoc, node, structure, textBuffer, namespace, field);
    192234    return textBuffer.toString();
    193235  }
     
    217259      METSStructure sections = document.getDocumentStructure().getStructure("Section");
    218260      if (sections != null) {
    219     docText = this.prepareDOM(document, domDocument, sections);
     261    docText = this.prepareDOM(document, domDocument, sections, "gsdl3", this.field);
    220262    //  System.out.println(docText);
    221263      }
     
    316358
    317359    this.indexStem = this.outputDirectory + File.separatorChar +
    318       this.getIndexDirectory("document", "text") +
     360      this.getIndexDirectory(index.getLevel(), index.getField()) +
    319361      File.separatorChar + "index"; // TODO: modify for index
    320362    this.level = index.getLevel();
     363    this.field = index.getField();
     364      }
     365      else {
     366    this.field = "text";
    321367      }
    322368     
     
    343389        Process p = Runtime.getRuntime().exec("mg_perf_hash_build -f index -d " + this.indexDirectory.toString());
    344390        p.waitFor();
    345         System.out.println(p.exitValue());
     391        if (p.exitValue() == 0) {
     392          System.out.println("Perfect hashes completed");
     393        }
    346394       
    347395        mg_passes = Runtime.getRuntime().exec("mg_passes " + pathParams +" -b 100000 -2 -c 3 -G -t 10 -N2");
     
    402450      try {
    403451    switch (mgPass)
    404     {                   
     452    { 
    405453      case 0:
    406454        System.out.println("Compressing dictionary");
     
    413461
    414462      case 3:
     463        System.out.println("Writing weights file");
    415464        p = Runtime.getRuntime().exec("mg_weights_build -f " + this.indexStem + " -t " + this.textStem + " -d /");
    416465        p.waitFor();
    417         System.out.println(p.exitValue());
     466        if (p.exitValue() == 0) {
     467          System.out.println("Weights file successfully written");
     468        }
     469        else {
     470          System.out.println("Unable to create weights file");
     471        }
    418472
    419473        p = Runtime.getRuntime().exec("mg_invf_dict -f index -d " + this.indexDirectory.toString());
    420474        p.waitFor();
    421         System.out.println(p.exitValue());
     475        if (p.exitValue() == 0) {
     476          System.out.println("Inverted dictionary file successfully written");
     477        }
     478        else {
     479          System.out.println("Unable to create inverted dictionary file");
     480        }
    422481       
    423482        p = Runtime.getRuntime().exec("mg_stem_idx -b 4096 -s1 -f index -d " + this.indexDirectory.toString());
    424483        p.waitFor();
    425         System.out.println(p.exitValue());
     484        if (p.exitValue() == 0) {
     485          System.out.println("Stemmed index successfully written");
     486        }
     487        else {
     488          System.out.println("Unable to create stemmed index");
     489        }
     490
    426491        p = Runtime.getRuntime().exec("mg_stem_idx -b 4096 -s2 -f index -d " + this.indexDirectory.toString());
    427492        p.waitFor();
    428         System.out.println(p.exitValue());
     493        if (p.exitValue() == 0) {
     494          System.out.println("Stemmed index successfully written");
     495        }
     496        else {
     497          System.out.println("Unable to create stemmed index");
     498        }
     499
    429500        p = Runtime.getRuntime().exec("mg_stem_idx -b 4096 -s3 -f index -d " + this.indexDirectory.toString());
    430501        p.waitFor();
    431         System.out.println(p.exitValue());
     502        if (p.exitValue() == 0) {
     503          System.out.println("Stemmed index successfully written");
     504        }
     505        else {
     506          System.out.println("Unable to create stemmed index");
     507        }
    432508      break;
    433509    }
Note: See TracChangeset for help on using the changeset viewer.