1   /**
2    * Copyright (c) Ontos AG (http://www.ontosearch.com).
3    * This class is part of JAPE Debugger component for
4    * GATE (Copyright (c) "The University of Sheffield" see http://gate.ac.uk/) <br>
5    * @author , Oleg Mishenko, Andrey Shafirin
6    */
7   
8   package debugger.resources.lr;
9   
10  import gate.Gate;
11  import gate.LanguageResource;
12  import gate.Document;
13  import gate.Corpus;
14  
15  import java.util.*;
16  
17  /**
18   * Copyright (c) Ontos AG (http://www.ontosearch.com).
19   * This class is part of JAPE Debugger component for
20   * GATE (Copyright (c) "The University of Sheffield" see http://gate.ac.uk/) <br>
21   * @author Andrey Shafirin, Vladimir Karasev
22   */
23  
24  public class LRRoot {
25      private ArrayList corpora;
26  
27      public LRRoot() {
28          List lrInstances = Gate.getCreoleRegister().getLrInstances();
29          corpora = new ArrayList();
30          ArrayList documents = new ArrayList();
31          for (Iterator it = lrInstances.iterator(); it.hasNext();) {
32              LanguageResource currentResource = (LanguageResource) it.next();
33              if (currentResource instanceof Document) {
34                  documents.add(currentResource);
35              }
36          }
37          for (Iterator it = lrInstances.iterator(); it.hasNext();) {
38              LanguageResource currentResource = (LanguageResource) it.next();
39              if (currentResource instanceof Corpus) {
40                  ArrayList documentsInThisCorpus = new ArrayList();
41                  for (Iterator iter = documents.iterator(); iter.hasNext();) {
42                      Document currentDocument = (Document) iter.next();
43                      if (((Corpus) currentResource).getDocumentNames().contains(currentDocument.getName())) {
44                          documentsInThisCorpus.add(new LrModel(currentDocument));
45                      }
46                  }
47                  corpora.add(new CorpusModel(documentsInThisCorpus, currentResource.getName()));
48              }
49          }
50      }
51  
52      public LrModel getDocumentModel(Document doc) {
53          for (int i = 0; i < corpora.size(); i++) {
54              CorpusModel model = (CorpusModel) corpora.get(i);
55              for (Iterator iterator = model.getLrModels().iterator(); iterator.hasNext();) {
56                  LrModel docModel = (LrModel) iterator.next();
57                  if (docModel.getLr().equals(doc)) return docModel;
58              }
59          }
60          return null;
61      }
62  
63      public ArrayList getCorpora() {
64          return corpora;
65      }
66  }
67