2016-10-10 35 views
0

戲言規則中的字典我有這樣的場景:使用地名作爲GATE

我在(例如)

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規則(例如hashmap)來加載地名詞典,以便查找這4個關鍵部分的連接並獲得(例如)「VALUE1」。是否可以從JAPE文件中加載地名詞典並將其用作字典?

有沒有其他(更好)的方法來做我需要的?

非常感謝。

回答

0

我發現使用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); 
    }