You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2015/01/31 19:00:44 UTC

svn commit: r1656227 - /opennlp/addons/geoentitylinker-addon/src/main/java/opennlp/addons/geoentitylinker/AdminBoundaryContextGenerator.java

Author: markg
Date: Sat Jan 31 18:00:43 2015
New Revision: 1656227

URL: http://svn.apache.org/r1656227
Log:
OPENNLP-750
Now the constructor of the AdminBoundaryContextGenerator will throw an IOException out to the GeoEntityLinker's init method if any of the following conditions are met:
the path to the file is empty or null
the file specified is not there
the file has no data in it resulting in an empty set of AdminBoundary data
This will force the EntityLinkerFactory to throw an ioexception when it calls the init method when instantiating the geoentitylinker

Modified:
    opennlp/addons/geoentitylinker-addon/src/main/java/opennlp/addons/geoentitylinker/AdminBoundaryContextGenerator.java

Modified: opennlp/addons/geoentitylinker-addon/src/main/java/opennlp/addons/geoentitylinker/AdminBoundaryContextGenerator.java
URL: http://svn.apache.org/viewvc/opennlp/addons/geoentitylinker-addon/src/main/java/opennlp/addons/geoentitylinker/AdminBoundaryContextGenerator.java?rev=1656227&r1=1656226&r2=1656227&view=diff
==============================================================================
--- opennlp/addons/geoentitylinker-addon/src/main/java/opennlp/addons/geoentitylinker/AdminBoundaryContextGenerator.java (original)
+++ opennlp/addons/geoentitylinker-addon/src/main/java/opennlp/addons/geoentitylinker/AdminBoundaryContextGenerator.java Sat Jan 31 18:00:43 2015
@@ -81,14 +81,22 @@ public class AdminBoundaryContextGenerat
     }
   }
 
-  public AdminBoundaryContextGenerator(EntityLinkerProperties properties) throws Exception {
+  public AdminBoundaryContextGenerator(EntityLinkerProperties properties) throws IOException{
     this.properties = properties;
     if (countrydata == null) {
       String path = this.properties.getProperty("opennlp.geoentitylinker.countrycontext.filepath", "");
-
+      if (path == null || path.trim().isEmpty()) {
+        throw new IOException("missing country context data configuration. Property opennlp.geoentitylinker.countrycontext.filepath must have a valid path value in entitylinker properties file");
+      }
       File countryContextFile = new File(path);
+      if (countryContextFile == null || !countryContextFile.exists()) {
+        throw new IOException("missing country context file");
+      }
       //countrydata = getCountryContextFromFile(countryContextFile);
       adminBoundaryData = getContextFromFile(countryContextFile);
+      if (adminBoundaryData.isEmpty()) {
+        throw new IOException("missing country context data");
+      }
     }
   }
 
@@ -140,7 +148,7 @@ public class AdminBoundaryContextGenerat
    */
   private AdminBoundaryContext process(String text) {
     try {
-    
+
       reset();
       Map<String, Set<Integer>> countryhitMap = regexfind(text, countryMap, countryHitSet);
       if (!countryhitMap.isEmpty()) {