【问题标题】:Use gazetteer as dictionary within JAPE rule in GATE在 GATE 的 JAPE 规则中使用地名词典作为字典
【发布时间】:2016-10-10 10:19:04
【问题描述】:

我有这种情况:

我有一个键值对列表,格式为(例如)

000.000.0001.000 VALUE1

000.000.0002.000 VALUE2

...

000.010.0001.000 VALUE254

文档使用如下表格显示信息:

SK1 | SK2 | SK3 | SK4

000  | 000 | 0001 | 000

问题是在处理这张表的时候,变成了

000

000

0001

000

所以地名录不会匹配它。我想构建一个 JAPE 规则来匹配这个,它可以正确匹配 4 个关键部分。

现在我需要将地名词典从我的 JAPE 规则加载到一个结构中(例如,哈希图),这样我就可以查找这 4 个关键部分的串联并获取(例如)“VALUE1”。是否可以从 JAPE 文件中加载地名词典并将其用作字典?

还有其他(更好的)方法可以做我需要做的事情吗?

非常感谢。

【问题讨论】:

    标签: gate information-extraction


    【解决方案1】:

    我使用 GazetteerList 类和下一个 sn-p 找到了我的问题的解决方案:

    //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);
      }
    

    然后,您可以在地图中查找匹配的键并获取其特征:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      相关资源
      最近更新 更多