Revision: 16867
http://sourceforge.net/p/gate/code/16867
Author: ian_roberts
Date: 2013-09-09 16:55:04 +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/RussGazetteer.java
Modified:
gate/trunk/plugins/Lang_Russian/src/com/ontotext/russie/gazetteer/RussGazetteer.java
===================================================================
---
gate/trunk/plugins/Lang_Russian/src/com/ontotext/russie/gazetteer/RussGazetteer.java
2013-09-09 16:44:12 UTC (rev 16866)
+++
gate/trunk/plugins/Lang_Russian/src/com/ontotext/russie/gazetteer/RussGazetteer.java
2013-09-09 16:55:04 UTC (rev 16867)
@@ -43,6 +43,7 @@
import gate.creole.metadata.CreoleResource;
import gate.creole.metadata.HiddenCreoleParameter;
import gate.creole.metadata.RunTime;
+import gate.creole.metadata.Sharable;
import gate.util.InvalidOffsetException;
import gate.util.LuckyException;
@@ -132,7 +133,7 @@
* etc. each map's value might be an ArrayList of Lookup objects specifying
* categories tied to this word/phrase.
*/
- protected List<Map> mapsList = new ArrayList<Map>(10);
+ protected List<Map> mapsList;
/**
* size of the mapsList
@@ -159,42 +160,57 @@
* @return returns this resource
*/
public Resource init() throws ResourceInstantiationException {
+ if(mapsList != null) {
+ // this is a duplicate
+ mapsListSize = mapsList.size();
+ } else {
+ mapsList = new ArrayList<Map>(10);
+ // check if there's a list URL
+ if(listsURL == null) { throw new ResourceInstantiationException(
+ "No URL provided for gazetteer creation!"); } // if
- // check if there's a list URL
- if(listsURL == null) { throw new ResourceInstantiationException(
- "No URL provided for gazetteer creation!"); } // if
+ try {
+ definition = new LinearDefinition();
+ definition.setURL(listsURL);
+ definition.load();
+ int linesCnt = definition.size();
+ listsByNode = definition.loadLists();
- try {
- definition = new LinearDefinition();
- definition.setURL(listsURL);
- definition.load();
- int linesCnt = definition.size();
- listsByNode = definition.loadLists();
+ // allocate the hashmap for the first words from the phrases
+ mapsList.add(new HashMap(linesCnt * 10));
+ mapsListSize = mapsList.size();
- // allocate the hashmap for the first words from the phrases
- mapsList.add(new HashMap(linesCnt * 10));
- mapsListSize = mapsList.size();
+ // allocate the category Map with optimal initial capacity & load
factor
+ categoryList = new ArrayList<Lookup>(linesCnt + 1);
- // allocate the category Map with optimal initial capacity & load factor
- categoryList = new ArrayList<Lookup>(linesCnt + 1);
-
- Iterator<LinearNode> inodes = definition.iterator();
- LinearNode node;
- int nodeIdx = 0;
- while(inodes.hasNext()) {
- node = inodes.next();
- fireStatusChanged(READING + node.toString());
- fireProgressChanged(++nodeIdx * 100 / linesCnt);
- readList(node, true);
- } // while
- fireProcessFinished();
- } catch(Exception x) {
- throw new ResourceInstantiationException(x);
- } // catch
+ Iterator<LinearNode> inodes = definition.iterator();
+ LinearNode node;
+ int nodeIdx = 0;
+ while(inodes.hasNext()) {
+ node = inodes.next();
+ fireStatusChanged(READING + node.toString());
+ fireProgressChanged(++nodeIdx * 100 / linesCnt);
+ readList(node, true);
+ } // while
+ fireProcessFinished();
+ } 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;
+ categoryList = null;
+ init();
+ }
+
+
+ /**
* gets the phrases/lines of a gazetteer list stores them in the maps opposed
* to a lookup.
*
@@ -745,4 +761,33 @@
this.wholeWordsOnly = wholeWordsOnly;
}
+ /**
+ * 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 setCategoryList(ArrayList<Lookup> categoryList) {
+ this.categoryList = categoryList;
+ }
+
+ /**
+ * For internal use by the duplication mechanism.
+ */
+ public ArrayList<Lookup> getCategoryList() {
+ return categoryList;
+ }
} // class Russ Gazetteer
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