1

I have this scenario:

I have a list of key-value pairs in the form of (for instance)

000.000.0001.000 VALUE1

000.000.0002.000 VALUE2

...

000.010.0001.000 VALUE254

The documents presents the information using a table as follows:

SK1 | SK2 | SK3 | SK4

000  | 000 | 0001 | 000

The problem is that when processing this table, it turns to

000

000

0001

000

So a gazetteer wont match it. I figured constructing a JAPE rule to match this, and it works properly matching the 4 key parts.

Now I would need to load the gazetteer from withing my JAPE rule in a structure (for instance, a hashmap) so I can lookup the concatenation of these 4 key parts and get (for example) "VALUE1". Is it possible to load a gazetteer from within a JAPE file and use it as a dictionary?

Is there any other (better) way to do what I need to?

Thanks a lot.

antorqs
  • 619
  • 3
  • 18

1 Answers1

1

I found the solution to my problem using GazetteerList class with the next snippet:

//Gazetteer object
GazetteerList gazList = new GazetteerList() ;
//Object to map gazetteers entries and their positions in the list
//i.e.: 000.000.0001.000 -> 1,3
//This is because, in my case, the same key 
//can appear more than once in the gazetteer
HashMap<String, ArrayList<Integer>> keyMap = 
                                   new HashMap<String, ArrayList<Integer>>();
  try{
    gazList.setMode(GazetteerList.LIST_MODE);
    gazList.setSeparator("\t");
    gazList.setURL(
        new URL("file:/path/to/gazetteer/gazetteer_list_file.lst"));
    gazList.load();

    //Here is the mapping between the keys and their position
    int pos = 0;
    for( GazetteerNode gazNode : gazList){
      if(keyMap.get(gazNode.getEntry()) == null)
        keyMap.put(gazNode.getEntry(), new ArrayList<Integer>());

      keyMap.get(gazNode.getEntry()).add(pos);
      pos++;
    }

  } catch (MalformedURLException ex){
    System.out.println(ex);
  } catch (ResourceInstantiationException ex){
    System.out.println(ex);
  }

Then, you can lookup the matched key in the map and get its features:

  for(Integer index : keyMap.get(key)){
      FeatureMap fmap = toFeatureMap(gazList.get(index).getFeatureMap());
      fmap.put("additionalFeature", "feature");
      outputAS.add(startOffset, endOffset, "Lookup", fmap);
  }
antorqs
  • 619
  • 3
  • 18