Revision: 16607
          http://sourceforge.net/p/gate/code/16607
Author:   johann_p
Date:     2013-03-20 11:45:00 +0000 (Wed, 20 Mar 2013)
Log Message:
-----------
If using LST files, allow features inst and/or class to be set
from the LST file feares, if a gazetteerFeatureSeparator is 
specified in the config.ttl file. Default is no separator and
behavior as before.

Modified Paths:
--------------
    
gate/trunk/plugins/Gazetteer_LKB/samples/dictionary_from_gazetteer/config.ttl
    
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/model/DataFeedFactory.java
    gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/model/Options.java
    
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/util/datastore/GazetteerListFeed.java

Modified: 
gate/trunk/plugins/Gazetteer_LKB/samples/dictionary_from_gazetteer/config.ttl
===================================================================
--- 
gate/trunk/plugins/Gazetteer_LKB/samples/dictionary_from_gazetteer/config.ttl   
    2013-03-20 02:20:30 UTC (rev 16606)
+++ 
gate/trunk/plugins/Gazetteer_LKB/samples/dictionary_from_gazetteer/config.ttl   
    2013-03-20 11:45:00 UTC (rev 16607)
@@ -1,22 +1,31 @@
-# Gazetteer_LKB dictionary configuration file.
-@prefix lkbg: <http://www.ontotext.com/lkb_gazetteer#>.
-
-# The gazetteer-specific options follow.
-lkbg:DictionaryConfiguration 
-
-   # Whether the gazeetteer will be sensitive to case.
-   # Possible values: caseinsensitive, casesensitive, casesensitiveAllUpper
-   lkbg:caseSensitivity "caseinsensitive" ;
-   
-   # Whether the gazetteer will cache the dictionary after loading it from the 
data source.   
-   # Put "enabled" to enable the cache, any other values will disable it.
-   lkbg:caching "enabled" ;
-   
-   # The cache will be automatically reloaded on initialization if the 
configuration have been    
-   # modified since the last initialization. However, changes in the 
underlying datastore 
-   # can't be detected and the cache will not be automatically reloaded in 
that case. 
-   # Thus, if you expect changes in your datastore, disable the cache, or make 
use
-   # of the modifications API.
-   
-   #A list of labels to be ignored, one per line.
-   lkbg:ignoreList "ignoreList.txt" .
+# Gazetteer_LKB dictionary configuration file.
+@prefix lkbg: <http://www.ontotext.com/lkb_gazetteer#>.
+
+# The gazetteer-specific options follow.
+lkbg:DictionaryConfiguration 
+
+   # Whether the gazeetteer will be sensitive to case.
+   # Possible values: caseinsensitive, casesensitive, casesensitiveAllUpper
+   lkbg:caseSensitivity "caseinsensitive" ;
+   
+   # Whether the gazetteer will cache the dictionary after loading it from the 
data source.   
+   # Put "enabled" to enable the cache, any other values will disable it.
+   lkbg:caching "enabled" ;
+   
+   # The cache will be automatically reloaded on initialization if the 
configuration have been    
+   # modified since the last initialization. However, changes in the 
underlying datastore 
+   # can't be detected and the cache will not be automatically reloaded in 
that case. 
+   # Thus, if you expect changes in your datastore, disable the cache, or make 
use
+   # of the modifications API.
+   
+   #A list of labels to be ignored, one per line.
+   lkbg:ignoreList "ignoreList.txt" ;
+
+   # if the cache is loaded from a gazetteer list file, the separator 
character to use
+   # to split each line into entry, inst and class feature. If this is set to
+   # the empty string or not set, no splitting is done. Otherwise the string 
is split]
+   # and the first part is taken to be the gazetteer entry. The remaining 
parts are
+   # checked to see if they have the form "inst=URI" or "class=URI" and if 
yes, are
+   # the URI is used to set the inst or class feature for that entry.
+   lkbg:gazetteerFeatureSeparator "" .
+

Modified: 
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/model/DataFeedFactory.java
===================================================================
--- 
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/model/DataFeedFactory.java
    2013-03-20 02:20:30 UTC (rev 16606)
+++ 
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/model/DataFeedFactory.java
    2013-03-20 11:45:00 UTC (rev 16607)
@@ -62,7 +62,7 @@
                }
     
                if (result == null && !FileUtils.listFiles(dictionaryPath, new 
String[]{"def"}, false).isEmpty()) {
-                 result = new GazetteerListFeed(dictionaryPath);
+                 result = new GazetteerListFeed(dictionaryPath,opt);
                }
                if (result == null) {
                        result = new DummyFeed(dictionaryPath);

Modified: 
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/model/Options.java
===================================================================
--- gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/model/Options.java    
2013-03-20 02:20:30 UTC (rev 16606)
+++ gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/model/Options.java    
2013-03-20 11:45:00 UTC (rev 16607)
@@ -1,5 +1,7 @@
 package com.ontotext.kim.model;
 
+import gate.util.Strings;
+
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
@@ -91,6 +93,12 @@
     return res != null ? res : INSENSITIVE;
   }
   
+  public String getSeparator() {
+    String ret = opts.get("gazetteerfeatureseparator");
+    if(ret == null) { ret = ""; }
+    return Strings.unescape(ret);
+  }
+  
   public Map<String, String> getMap() {
     return opts; // unmodifiable
   }

Modified: 
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/util/datastore/GazetteerListFeed.java
===================================================================
--- 
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/util/datastore/GazetteerListFeed.java
 2013-03-20 02:20:30 UTC (rev 16606)
+++ 
gate/trunk/plugins/Gazetteer_LKB/src/com/ontotext/kim/util/datastore/GazetteerListFeed.java
 2013-03-20 11:45:00 UTC (rev 16607)
@@ -21,6 +21,7 @@
 import com.ontotext.kim.client.query.KIMQueryException;
 import com.ontotext.kim.client.semanticrepository.QueryResultListener;
 import com.ontotext.kim.client.semanticrepository.QueryResultListener.Feed;
+import com.ontotext.kim.model.Options;
 
 /**
  * @author mnozchev
@@ -33,9 +34,11 @@
   private static Logger log = Logger.getLogger(GazetteerListFeed.class);
   
   private final File dictionaryPath;
+  private Options options;
 
-  public GazetteerListFeed(File dictionaryPath) {
+  public GazetteerListFeed(File dictionaryPath, Options opt) {
     this.dictionaryPath = dictionaryPath;
+    this.options = opt;
   }
 
   /**
@@ -85,6 +88,7 @@
           LinearDefinition definition) throws ResourceInstantiationException,
           IOException {
 
+    String separator = options.getSeparator();
     Map listsByNode = definition.loadLists();
     Iterator inodes = definition.iterator();
     LinearNode node;
@@ -107,19 +111,43 @@
       Iterator iline = gazList.iterator();
       while(iline.hasNext()) {
         GazetteerNode gazNode = (GazetteerNode)iline.next();
-        addEntity(listener, node.getMinorType(), node.getMajorType(),
-                gazNode.getEntry());
+        String clazz = "urn:"+node.getMajorType();
+        String inst = "urn:"+node.getMinorType();
+        String entry = gazNode.getEntry();
+        // if a separator string is set, attempt to split the gazetteer
+        // line by that separator and try to get the inst and/or class feature
+        // values.
+        if(!separator.equals("")) {
+          // If the entry contains the separator, split it up and try to find
+          // features class and inst. 
+          if(entry.contains(separator)) {
+            String fields[] = entry.split(separator);
+            entry = fields[0];
+            for(int i = 1; i<fields.length; i++) {
+              if(fields[i].startsWith("inst=")) {
+                inst = fields[i].substring(5);
+              } else if(fields[i].startsWith("class=")) {
+                clazz = fields[i].substring(6);
+              }
+            }
+          }
+        }
+        
+        addEntity(listener, inst, clazz,entry);
       }
+      
+      
+      
     }
   }
 
-  private void addEntity(QueryResultListener listener, String minorType,
-          String majorType, String label) throws IOException {
+  private void addEntity(QueryResultListener listener, String inst,
+          String clazz, String label) throws IOException {
 
     listener.startTuple();
     listener.tupleValue(new LiteralImpl(label));
-    listener.tupleValue(new URIImpl("urn:" + minorType));
-    listener.tupleValue(new URIImpl("urn:" + majorType));
+    listener.tupleValue(new URIImpl(inst));
+    listener.tupleValue(new URIImpl(clazz));
     listener.endTuple();
   }
 

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


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to