在 GATE 的 JAPE 规则中使用地名词典作为字典
Use gazetteer as dictionary within JAPE rule in GATE
我有这种情况:
我有一个键值对列表(例如)
000.000.0001.000 VALUE1
000.000.0002.000 VALUE2
...
000.010.0001.000 VALUE254
文档使用 table 表示信息如下:
SK1 | SK2 | SK3 | SK4
000 | 000 | 0001 | 000
问题是在处理这个table的时候,变成了
000
000
0001
000
所以地名词典不会匹配它。我想构建一个 JAPE 规则来匹配它,并且它可以正确匹配 4 个关键部分。
现在我需要使用我的 JAPE 规则在一个结构(例如,哈希图)中加载地名词典,这样我就可以查找这 4 个关键部分的串联并获得(例如)"VALUE1" .是否可以从 JAPE 文件中加载地名词典并将其用作字典?
有没有其他(更好的)方法来完成我需要做的事情?
非常感谢。
我使用 GazetteerList class 和下一个片段找到了问题的解决方案:
//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);
}
然后,你可以在map中查找匹配的key,得到它的特征:
for(Integer index : keyMap.get(key)){
FeatureMap fmap = toFeatureMap(gazList.get(index).getFeatureMap());
fmap.put("additionalFeature", "feature");
outputAS.add(startOffset, endOffset, "Lookup", fmap);
}
我有这种情况:
我有一个键值对列表(例如)
000.000.0001.000 VALUE1
000.000.0002.000 VALUE2
...
000.010.0001.000 VALUE254
文档使用 table 表示信息如下:
SK1 | SK2 | SK3 | SK4
000 | 000 | 0001 | 000
问题是在处理这个table的时候,变成了
000
000
0001
000
所以地名词典不会匹配它。我想构建一个 JAPE 规则来匹配它,并且它可以正确匹配 4 个关键部分。
现在我需要使用我的 JAPE 规则在一个结构(例如,哈希图)中加载地名词典,这样我就可以查找这 4 个关键部分的串联并获得(例如)"VALUE1" .是否可以从 JAPE 文件中加载地名词典并将其用作字典?
有没有其他(更好的)方法来完成我需要做的事情?
非常感谢。
我使用 GazetteerList class 和下一个片段找到了问题的解决方案:
//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);
}
然后,你可以在map中查找匹配的key,得到它的特征:
for(Integer index : keyMap.get(key)){
FeatureMap fmap = toFeatureMap(gazList.get(index).getFeatureMap());
fmap.put("additionalFeature", "feature");
outputAS.add(startOffset, endOffset, "Lookup", fmap);
}