当前位置: 首页 > 知识库问答 >
问题:

在GATE中JAPE规则内使用地名录作为词典

皇甫智明
2023-03-14

我有这样的场景:

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

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

多谢.

共有1个答案

傅志用
2023-03-14

我使用GazetteerList类找到了解决问题的方法,下面是以下代码片段:

//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);
  }
 类似资料:
  • 在输出中它只给了令牌,空间令牌有人能帮我解决问题吗?

  • 我正在学习使用Gate从文档中检索信息。谁能给我解释一下我要做什么才能让我的语法规则发挥作用。我已经检查了大多数教程和大门手册,但我仍然没有得到重点。我想提取人,地点和日期作为我命名的实体。 所以我所做的是:1。在文档中确定了我的日期模式2。为每个模式3创建JAPE语法规则。加载。jape文件作为一种新的jape传感器 我的约会模式如下:1。DateMonthYear 2。每月 因此,如果我理解正

  • 嗨,我正试图解析文档或pdf文件中的文本。每当我尝试使用:

  • 我想在安妮地名录中添加一个新的查找列表。一些应该被发现的单词包含冒号;注释中的一个特性(在新的MyLookup.List中定义)也包含冒号,例如: 我已经尝试用“转义”MyLookup.lst中的冒号,但没有成功。因为我还想使用其他默认的查找列表(它们都是用冒号分隔的),所以我不能仅仅定义一个其他的分隔符。那么,我如何告诉地名录查找和注释包含冒号的单词呢?

  • 当我试图用或运算符创建“句子包含”jape规则时,即当一个句子包含1或2和3或4时,我会得到错误: 有人能建议一下正确的语法吗?