Revision: 16865
          http://sourceforge.net/p/gate/code/16865
Author:   ian_roberts
Date:     2013-09-09 15:19:40 +0000 (Mon, 09 Sep 2013)
Log Message:
-----------
The mapsList is read-only once initialized, so can be made @Sharable for
efficient duplication.

Modified Paths:
--------------
    
gate/trunk/plugins/Lang_Russian/src/com/ontotext/russie/gazetteer/InflectionalGazetteer.java

Modified: 
gate/trunk/plugins/Lang_Russian/src/com/ontotext/russie/gazetteer/InflectionalGazetteer.java
===================================================================
--- 
gate/trunk/plugins/Lang_Russian/src/com/ontotext/russie/gazetteer/InflectionalGazetteer.java
        2013-09-09 12:50:13 UTC (rev 16864)
+++ 
gate/trunk/plugins/Lang_Russian/src/com/ontotext/russie/gazetteer/InflectionalGazetteer.java
        2013-09-09 15:19:40 UTC (rev 16865)
@@ -29,6 +29,7 @@
 import gate.creole.metadata.CreoleResource;
 import gate.creole.metadata.Optional;
 import gate.creole.metadata.RunTime;
+import gate.creole.metadata.Sharable;
 import gate.util.InvalidOffsetException;
 import gate.util.LuckyException;
 import gate.util.profile.Profiler;
@@ -99,7 +100,7 @@
    * etc. each map's value might be an ArrayList of TYpe objects specifying
    * categories tied to this word/phrase.
    */
-  protected List<Map> mapsList = new ArrayList<Map>(10);
+  protected List<Map> mapsList;
 
   /**
    * size of the mapsList
@@ -141,97 +142,112 @@
    * @return returns this resource
    */
   public Resource init() throws ResourceInstantiationException {
-    Profiler profiler = null;
-    if(DEBUG) {
-      profiler = new Profiler();
-      profiler.enableGCCalling(false);
-      profiler.initRun("Inflectional Gazetteer init()");
-      profiler.checkPoint("reset");
-    }
-    // check if there's a list URL
-    if(config == null) { throw new ResourceInstantiationException(
-      "No config provided for gazetteer!"); } // if
+    if(mapsList != null) {
+      // this is a duplicate
+      mapsListSize = mapsList.size();
+    } else {
+      Profiler profiler = null;
+      if(DEBUG) {
+        profiler = new Profiler();
+        profiler.enableGCCalling(false);
+        profiler.initRun("Inflectional Gazetteer init()");
+        profiler.checkPoint("reset");
+      }
+      mapsList = new ArrayList<Map>(10);
+      // check if there's a list URL
+      if(config == null) { throw new ResourceInstantiationException(
+        "No config provided for gazetteer!"); } // if
 
-    try {
-      BufferedReader configReader =
-        new BufferedReader(new InputStreamReader(config.openStream(), 
encoding));
-      int lemmaIdx = 0;
       try {
-        // each line in config is a relative path to an .infl file
+        BufferedReader configReader =
+          new BufferedReader(new InputStreamReader(config.openStream(), 
encoding));
+        int lemmaIdx = 0;
+        try {
+          // each line in config is a relative path to an .infl file
 
-        String configLine = null;
-        while((configLine = configReader.readLine()) != null) {
-          configLine = configLine.trim();
-          // ignore blank lines and comments
-          if("".equals(configLine) || configLine.startsWith("#")) continue;
+          String configLine = null;
+          while((configLine = configReader.readLine()) != null) {
+            configLine = configLine.trim();
+            // ignore blank lines and comments
+            if("".equals(configLine) || configLine.startsWith("#")) continue;
 
-          URL fileURL = new URL(config, configLine);
+            URL fileURL = new URL(config, configLine);
 
-          InflectionalGazetteerXMLReader gazReader = getGazReader(fileURL);
-          List<Lemma> lemmas = gazReader.getLemmas();
-          Iterator<Lemma> lemmaIter = lemmas.iterator();
+            InflectionalGazetteerXMLReader gazReader = getGazReader(fileURL);
+            List<Lemma> lemmas = gazReader.getLemmas();
+            Iterator<Lemma> lemmaIter = lemmas.iterator();
 
-          int linesCnt = lemmas.size();
-          // allocate the hashmap for the first words from the phrases
-          mapsList.add(new HashMap(linesCnt));
-          mapsListSize = mapsList.size();
+            int linesCnt = lemmas.size();
+            // allocate the hashmap for the first words from the phrases
+            mapsList.add(new HashMap(linesCnt));
+            mapsListSize = mapsList.size();
 
-          // allocate the category Map with optimal initial capacity & load
-          // factor
-          msTypeSet = new HashSet<SuffixNest>();
+            // allocate the category Map with optimal initial capacity & load
+            // factor
+            msTypeSet = new HashSet<SuffixNest>();
 
-          Lemma lemma;
-          fireStatusChanged(READING + configLine);
-          while(lemmaIter.hasNext()) {
-            lemma = lemmaIter.next();
-            fireProgressChanged(++lemmaIdx * 100 / linesCnt);
-            this.add(lemma);
-          } // while
+            Lemma lemma;
+            fireStatusChanged(READING + configLine);
+            while(lemmaIter.hasNext()) {
+              lemma = lemmaIter.next();
+              fireProgressChanged(++lemmaIdx * 100 / linesCnt);
+              this.add(lemma);
+            } // while
+          }
+
+        } finally {
+          configReader.close();
         }
 
-      } finally {
-        configReader.close();
-      }
+        fireProcessFinished();
 
-      fireProcessFinished();
+        if(DEBUG) {
+          System.out.println("Infl. Gaz. Is GC Enabled ? = " +
+            profiler.isGCCallingEnabled());
+          profiler.checkPoint("Infl. Gaz. init completed.");
+        } // DEBUG
 
-      if(DEBUG) {
-        System.out.println("Infl. Gaz. Is GC Enabled ? = " +
-          profiler.isGCCallingEnabled());
-        profiler.checkPoint("Infl. Gaz. init completed.");
-      } // DEBUG
+        if(DEBUG) {
+          System.out.println("Starting Garbage Collection ...");
+          System.gc();
+          profiler.checkPoint("Garbage Collection finished");
+        }
 
-      if(DEBUG) {
-        System.out.println("Starting Garbage Collection ...");
-        System.gc();
-        profiler.checkPoint("Garbage Collection finished");
-      }
+        if(DEBUG) {
+          System.out.println("\nLEMMAs COUNT -> ");
+          System.out.println(lemmaIdx);
+          System.out.println("\nTYPE POOL SIZE -> ");
+          System.out.println(TypePool.size());
+          System.out.println("\nSUFFIX POOL SIZE -> ");
+          System.out.println(SuffixPool.size());
+        }
+        if(DETAILED_DEBUG) {
+          // dump distinct types
+          System.out.println("\nTYPE POOL ->");
+          System.out.println(TypePool.getString());
+          System.out.println("\nSUFFIX POOL ->");
+          System.out.println(SuffixPool.getString());
 
-      if(DEBUG) {
-        System.out.println("\nLEMMAs COUNT -> ");
-        System.out.println(lemmaIdx);
-        System.out.println("\nTYPE POOL SIZE -> ");
-        System.out.println(TypePool.size());
-        System.out.println("\nSUFFIX POOL SIZE -> ");
-        System.out.println(SuffixPool.size());
-      }
-      if(DETAILED_DEBUG) {
-        // dump distinct types
-        System.out.println("\nTYPE POOL ->");
-        System.out.println(TypePool.getString());
-        System.out.println("\nSUFFIX POOL ->");
-        System.out.println(SuffixPool.getString());
+        }
 
-      }
+      } catch(Exception x) {
+        throw new ResourceInstantiationException(x);
+      } // catch
+    }
 
-    } catch(Exception x) {
-      throw new ResourceInstantiationException(x);
-    } // catch
-
     return this;
   } // Resource init() throws ResourceInstantiationException
 
   /**
+   * Re-initialize this gazetteer by re-loading the configuration.
+   */
+  public void reInit() throws ResourceInstantiationException {
+    mapsList = null;
+    msTypeSet = null;
+    init();
+  }
+
+  /**
    * This method runs the gazetteer. It parses the document and looks-up the
    * parsed phrases from the maps, in which the phrases vs. annotations are 
set,
    * in order to generate an annotation set. It assumes that all the needed
@@ -764,4 +780,34 @@
     return caseSensitive;
   }
 
+
+  /**
+   * For internal use by the duplication mechanism.
+   */
+  @Sharable
+  public void setMapsList(List<Map> mapsList) {
+    this.mapsList = mapsList;
+  }
+
+  /**
+   * For internal use by the duplication mechanism.
+   */
+  public List<Map> getMapsList() {
+    return mapsList;
+  }
+
+  /**
+   * For internal use by the duplication mechanism.
+   */
+  @Sharable
+  public void setMsTypeSet(Set<SuffixNest> msTypeSet) {
+    this.msTypeSet = msTypeSet;
+  }
+
+  /**
+   * For internal use by the duplication mechanism.
+   */
+  public Set<SuffixNest> getMsTypeSet() {
+    return msTypeSet;
+  }
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to