Java Code Examples for gnu.trove.THashMap#get()
The following examples show how to use
gnu.trove.THashMap#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureExtractor.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
public String getLowerCaseLemma(THashMap<String,String> lemmaCache, String word, String POS, WordNetRelations wnr) { String pair = word+"_"+POS; if(lemmaCache==null) { return wnr.getLemmaForWord(word, POS).toLowerCase(); } else if(!lemmaCache.contains(pair)) { lemmaCache.put(pair, wnr.getLemmaForWord(word, POS).toLowerCase()); return wnr.getLemmaForWord(word, POS).toLowerCase(); } else { return lemmaCache.get(pair); } }
Example 2
Source File: Win32FsCache.java From consulo with Apache License 2.0 | 6 votes |
@Nullable FileAttributes getAttributes(@Nonnull VirtualFile file) { VirtualFile parent = file.getParent(); int parentId = parent instanceof VirtualFileWithId ? ((VirtualFileWithId)parent).getId() : -((VirtualFileWithId)file).getId(); TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap(); THashMap<String, FileAttributes> nestedMap = map.get(parentId); String name = file.getName(); FileAttributes attributes = nestedMap != null ? nestedMap.get(name) : null; if (attributes == null) { if (nestedMap != null && !(nestedMap instanceof IncompleteChildrenMap)) { return null; // our info from parent doesn't mention the child in this refresh session } FileInfo info = myKernel.getInfo(file.getPath()); if (info == null) { return null; } attributes = info.toFileAttributes(); if (nestedMap == null) { nestedMap = new IncompleteChildrenMap<>(FileUtil.PATH_HASHING_STRATEGY); map.put(parentId, nestedMap); } nestedMap.put(name, attributes); } return attributes; }
Example 3
Source File: FeatureExtractor.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
public Set<String> getWNRelations(THashMap<String, THashSet<String>> wnCacheMap,String sWord, String tWord, WordNetRelations wnr) { String pair = sWord.toLowerCase()+"\t"+tWord.toLowerCase(); if(wnCacheMap==null) { return wnr.getRelations(sWord.toLowerCase(), tWord.toLowerCase()); } else if(!wnCacheMap.contains(pair)) { Set<String> relations = wnr.getRelations(sWord.toLowerCase(), tWord.toLowerCase()); if(relations.contains(WordNetRelations.NO_RELATION)) return relations; else { THashSet<String> nR = new THashSet<String>(); for(String string:relations) nR.add(string); wnCacheMap.put(pair, nR); return relations; } } else { return wnCacheMap.get(pair); } }
Example 4
Source File: ProduceLargerFrameDistribution.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
public static void writeDist(THashMap<String, THashMap<String, Double>> map, String file) { try { BufferedWriter bWriter = new BufferedWriter(new FileWriter(file)); Set<String> keys = map.keySet(); for (String key: keys) { bWriter.write(key + "\t"); THashMap<String, Double> map1 = map.get(key); Set<String> keys1 = map1.keySet(); int count = 0; for (String key1: keys1) { if (count != 0) { bWriter.write(" "); } bWriter.write(key1 + " " + map1.get(key1)); count++; } bWriter.write("\n"); } bWriter.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } }
Example 5
Source File: CountNumberOfRoles.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { // String file = "/usr2/dipanjan/experiments/FramenetParsing/fndata-1.5/ACLSplits/5/framenet.frame.element.map"; String file = "/usr2/dipanjan/experiments/FramenetParsing/FrameStructureExtraction/lrdata/framenet.original.frame.elements.map"; THashMap<String, THashSet<String>> map = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject(file); Set<String> frames = map.keySet(); System.out.println("Number of frames:" + frames.size()); THashSet<String> roleSet = new THashSet<String>(); for (String frame: frames) { System.out.println(frame + "\t" + map.get(frame)); THashSet<String> roles = map.get(frame); for (String r: roles) roleSet.add(r); } System.out.println(roleSet); System.out.println("Number of unique roles:" + roleSet.size()); }
Example 6
Source File: LexicalUnitsFrameExtraction.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
public static void printMap() { String mapFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/framenet.original.map"; THashMap<String,THashSet<String>> map = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject(mapFile); Set<String> set = map.keySet(); for(String frame: set) { THashSet<String> val = map.get(frame); System.out.print(frame+": "); for(String unit: val) { System.out.print(unit+" "); } System.out.println(); } }
Example 7
Source File: Frames.java From semafor-semantic-parser with GNU General Public License v3.0 | 6 votes |
public static void getUnknownFrameNames(String file) { String mapFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/framenet.original.map"; THashMap<String, THashSet<String>> map = (THashMap<String, THashSet<String>>)SerializedObjects.readSerializedObject(mapFile); Document fDoc = XmlUtils.parseXmlFile(file, false); Element[] eList = XmlUtils.applyXPath(fDoc, FNConstants.FRAME_PATH); int len = eList.length; String[] frameNames = new String[len]; for(int i = 0; i < len; i ++) { Element e = eList[i]; frameNames[i] = e.getAttribute(FNConstants.FRAME_NAME_ATTR); } Arrays.sort(frameNames); int countUnknown = 0; for(int i = 0; i < len; i ++) { if(map.get(frameNames[i])==null) { System.out.println(frameNames[i]); countUnknown++; } } System.out.println(countUnknown); }
Example 8
Source File: GetUnseenFELines.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public static Set<String> checkPresenceOfTokensInMap(int[] intTokNums, String[][] data, THashMap<String,THashSet<String>> mHvCorrespondenceMap) { String lemmatizedTokens = ""; for(int i = 0; i < intTokNums.length; i ++) { String lexUnit = data[0][intTokNums[i]]; String pos = data[1][intTokNums[i]]; //lemmatizedTokens+=mWNR.getLemmaForWord(lexUnit, pos).toLowerCase()+" "; lemmatizedTokens+=data[5][intTokNums[i]]+" "; } lemmatizedTokens=lemmatizedTokens.trim(); return mHvCorrespondenceMap.get(lemmatizedTokens); }
Example 9
Source File: FixTokenization.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public static String replaceBritishWords(String line, THashMap<String,String> conv) { String revisedLine = ""; StringTokenizer st = new StringTokenizer(line); while(st.hasMoreTokens()) { String word = st.nextToken(); if(conv.get(word)!=null) { word = conv.get(word); } else { if(conv.get(word.toLowerCase())!=null) { String lookup = conv.get(word.toLowerCase()); if(word.charAt(0)>='A'&&word.charAt(0)<='Z') { char ch = lookup.toLowerCase().charAt(0); char ch1 = (""+ch).toUpperCase().charAt(0); word=ch1+word.substring(1); } } } revisedLine+=word+" "; } return revisedLine.trim(); }
Example 10
Source File: NormalizeLinDekNeighbors.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public static void printFinalMap(THashMap<String, TObjectDoubleHashMap<String>> finalMap, String outFile) { Set<String> keySet = finalMap.keySet(); String[] arr = new String[keySet.size()]; keySet.toArray(arr); Arrays.sort(arr); ArrayList<String> finalLines = new ArrayList<String>(); Comparator<Pair<String, Double>> c = new Comparator<Pair<String, Double>> () { public int compare(Pair<String, Double> o1, Pair<String, Double> o2) { if (o1.getSecond() > o2.getSecond()) return -1; else if (o1.getSecond() == o2.getSecond()) { return 0; } else return 1; } }; for (String unit: arr) { String line = unit + "\t"; TObjectDoubleHashMap<String> map = finalMap.get(unit); String[] keys = new String[map.size()]; map.keys(keys); Pair<String, Double>[] pArray = new Pair[map.size()]; for (int i = 0; i < keys.length; i++) { pArray[i] = new Pair<String, Double>(keys[i], map.get(keys[i])); } Arrays.sort(pArray, c); for (int i = 0; i < keys.length; i++) { line += pArray[i].getFirst() + "\t" + pArray[i].getSecond() + "\t"; } line = line.trim(); finalLines.add(line); } ParsePreparation.writeSentencesToTempFile(outFile, finalLines); }
Example 11
Source File: LexicalUnitsFrameExtraction.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
/** * Populates the given map object with frames (as keys) and sets of target words that evoke * those frames in the given corresponding sentences (as values) * @param map * @param frames * @param sentences * @author dipanjan */ public static void fillMap(THashMap<String,THashSet<String>> map, ArrayList<String> frames, ArrayList<String> sentences) { int size = frames.size(); for(int i = 0; i < size; i ++) { String line = frames.get(i); String[] toks = line.split("\t"); int sentenceNum = new Integer(toks[toks.length-1]); String storedSentence = sentences.get(sentenceNum); String frame = toks[0]; String tokenNums = toks[2]; String[] nums = tokenNums.split("_"); String lexicalUnits = getTokens(storedSentence,nums); THashSet<String> set = map.get(frame); if(set==null) { set = new THashSet<String>(); set.add(lexicalUnits); map.put(frame, set); } else { if(!set.contains(lexicalUnits)) { set.add(lexicalUnits); } } } }
Example 12
Source File: ScrapTest.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public static THashMap<String,Integer> getSpansWithHeads(String file) { THashMap<String, Integer> spans = new THashMap<String, Integer>(); THashMap<String, Integer> countMap = new THashMap<String,Integer>(); try { String line = null; BufferedReader bReader = new BufferedReader(new FileReader(file)); while((line=bReader.readLine())!=null) { String[] toks = line.trim().split("\t"); char first = toks[0].charAt(0); if((first>='a'&&first<='z')||(first>='A'&&first<='Z')||(first>='0'&&first<='9')) { String word = toks[0].trim(); int count = new Integer(toks[2].trim()); if(countMap.contains(word)) { if(countMap.get(word)<count) { countMap.put(word, count); spans.put(word, new Integer(toks[1].trim())); } } else { countMap.put(word, count); spans.put(word, new Integer(toks[1].trim())); } } } bReader.close(); } catch(Exception e) { e.printStackTrace(); } System.out.println("Size of spans:"+spans.size()); return spans; }
Example 13
Source File: FeatureExtractor.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public String getClusterMembership(String token, THashMap<String,THashSet<String>> clusterMap, int K) { THashSet<String> set = clusterMap.get(token.toLowerCase()); String k = ""+K; String tag=null; if(set!=null) { for(String string:set) { String[] arr = string.split("_"); if(arr[1].equals(k)) tag="C"+arr[2]; } } return tag; }
Example 14
Source File: RequiredDataCreation.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public static Map<String, String> getHVLemmas(FNModelOptions options) { String fmFile = options.frameNetMapFile.get(); String wnConfigFile = options.wnConfigFile.get(); String stopFile = options.stopWordsFile.get(); THashMap<String, THashSet<String>> frameMap = (THashMap<String, THashSet<String>>) SerializedObjects.readSerializedObject(fmFile); WordNetRelations wnr = new WordNetRelations(stopFile, wnConfigFile); Map<String, String> lemmaMap = new THashMap<String, String>(); Set<String> keySet = frameMap.keySet(); for(String frame: keySet) { THashSet<String> hus = frameMap.get(frame); for(String hUnit: hus) { String[] hiddenToks = hUnit.split(" "); String hiddenUnitTokens=""; String hiddenUnitLemmas=""; for(int i = 0; i < hiddenToks.length; i ++) { String[] arr = hiddenToks[i].split("_"); hiddenUnitTokens+=arr[0]+" "; String lowerCaseLemma = wnr.getLemmaForWord(arr[0], arr[1]).toLowerCase(); lemmaMap.put(arr[0] + "_" + arr[1], lowerCaseLemma); hiddenUnitLemmas+=wnr.getLemmaForWord(arr[0], arr[1]).toLowerCase()+" "; } hiddenUnitTokens=hiddenUnitTokens.trim(); hiddenUnitLemmas=hiddenUnitLemmas.trim(); System.out.println("Processed:"+hiddenUnitLemmas); } } SerializedObjects.writeSerializedObject(lemmaMap, options.lemmaCacheFile.get()); return lemmaMap; }
Example 15
Source File: FEDict.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public void merge(String filename){ THashMap<String,THashSet<String>> tempdict=(THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject(filename); for(String key : tempdict.keySet()){ THashSet newval=tempdict.get(key); if(fedict.contains(key)){ THashSet val=fedict.get(key); val.addAll(newval); } else{ fedict.put(key, newval); } } fedict.putAll(tempdict); }
Example 16
Source File: Decoding.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public static THashMap<String,String> getOnlyOverlappingFes(THashMap<String,String> map) { Set<String> keys = map.keySet(); THashMap<String,String> tempMap = new THashMap<String,String>(); for(String fe: keys) { String span = map.get(fe); if(!span.equals("-1_-1")) { tempMap.put(fe, span); } } return tempMap; }
Example 17
Source File: TIntObjectObjectHashMap.java From semafor-semantic-parser with GNU General Public License v3.0 | 5 votes |
public K get(int one, V two) { THashMap<V,K> val = map.get(one); if(val==null) return null; return val.get(two); }
Example 18
Source File: WordNetCoverageCheck.java From semafor-semantic-parser with GNU General Public License v3.0 | 4 votes |
private static int[][] getFeatures(String frame, int[] intTokNums, String[][] data, THashMap<String,THashSet<String>> mFrameMap, WordNetRelations mWnr, Map<String, Set<String>> relatedWordsForWord, Map<String, THashMap<String, Set<String>>> wordNetMap ) { THashSet<String> hiddenUnits = mFrameMap.get(frame); DependencyParse parse = DependencyParse.processFN(data, 0.0); int hSize = hiddenUnits.size(); int[][] res = new int[hSize][]; for (String unit : hiddenUnits) { // IntCounter<String> valMap1 = null; // valMap1 = FeatureExtractor.extractFeatures(frame, // intTokNums, // unit, // data, // mWnr, // "test", // null, // null, // parse); // Set<String> features1 = valMap1.keySet(); IntCounter<String> valMap2 = null; FeatureExtractor featex = new FeatureExtractor(); valMap2 = featex.extractFeaturesLessMemory( frame, intTokNums, unit, data, "test", relatedWordsForWord, null, null, parse); // Set<String> features2 = valMap2.keySet(); // if (features1.size() != features2.size()) { // System.out.println("Problem with the two feature sets."); // String[] arr1 = new String[features1.size()]; // features1.toArray(arr1); // Arrays.sort(arr1); // System.out.println("Feature set 1:"); // for (String feat:arr1) System.out.println(feat); // String[] arr2 = new String[features2.size()]; // features2.toArray(arr2); // Arrays.sort(arr2); // System.out.println("\nFeature set 2:"); // for (String feat:arr2) System.out.println(feat); // System.exit(-1); // } // features2.removeAll(features1); // if (features2.size() > 0) { // System.out.println("Problem with second features set:"); // for (String feat: features2) { // System.out.println(feat); // } // System.exit(-1); // } } return res; }
Example 19
Source File: WordNetRelationsCache.java From semafor-semantic-parser with GNU General Public License v3.0 | 4 votes |
private static void findRelationsForFrame(THashMap<String,THashSet<String>> mFrameMap, String frame, int[] tokenNums, String[][] pData, WordNetRelations wnr, THashMap<String,THashSet<String>> wnCacheMap) { THashSet<String> hiddenUnits = mFrameMap.get(frame); Iterator<String> itr = hiddenUnits.iterator(); while(itr.hasNext()) { String unit = itr.next(); String[] hiddenToks = unit.split(" "); String hiddenUnitTokens = ""; for(int i = 0; i < hiddenToks.length; i ++) { String[] arr = hiddenToks[i].split("_"); hiddenUnitTokens+=arr[0]+" "; } hiddenUnitTokens=hiddenUnitTokens.trim().toLowerCase(); String actualTokens = ""; for(int i = 0; i < tokenNums.length; i ++) { String lexUnit = pData[0][tokenNums[i]]; actualTokens+=lexUnit+" "; } actualTokens = actualTokens.trim().toLowerCase(); String pair = hiddenUnitTokens+"\t"+actualTokens; if(!wnCacheMap.contains(pair)) { Set<String> relations = wnr.getRelations(hiddenUnitTokens, actualTokens); if(!relations.contains(WordNetRelations.NO_RELATION)) { System.out.println("Problem with pair:"+pair); System.exit(0); } } else { System.out.println("Found relation"); Set<String> set1 = wnCacheMap.get(pair); Set<String> set2 = wnr.getRelations(hiddenUnitTokens, actualTokens); if(!set1.equals(set2)) { System.out.println("Problem with pair 2:"+pair); System.exit(0); } System.out.println(pair); for(String string:set2) { System.out.print(string+" "); } System.out.println(); } } }
Example 20
Source File: RequiredDataCreation.java From semafor-semantic-parser with GNU General Public License v3.0 | 4 votes |
public static THashMap<String,THashSet<String>> getHVCorrespondence(FNModelOptions options) { String fmFile = options.frameNetMapFile.get(); String wnConfigFile = options.wnConfigFile.get(); String stopFile = options.stopWordsFile.get(); String hvCorrespondenceFile = options.hvCorrespondenceFile.get(); THashMap<String, THashSet<String>> frameMap = (THashMap<String, THashSet<String>>) SerializedObjects.readSerializedObject(fmFile); WordNetRelations wnr = new WordNetRelations(stopFile, wnConfigFile); THashMap<String,THashSet<String>> cMap = new THashMap<String,THashSet<String>>(); Set<String> keySet = frameMap.keySet(); for(String frame: keySet) { THashSet<String> hus = frameMap.get(frame); for(String hUnit: hus) { String[] hiddenToks = hUnit.split(" "); String hiddenUnitTokens=""; String hiddenUnitLemmas=""; for(int i = 0; i < hiddenToks.length; i ++) { String[] arr = hiddenToks[i].split("_"); hiddenUnitTokens+=arr[0]+" "; hiddenUnitLemmas+=wnr.getLemmaForWord(arr[0], arr[1]).toLowerCase()+" "; } hiddenUnitTokens=hiddenUnitTokens.trim(); hiddenUnitLemmas=hiddenUnitLemmas.trim(); THashSet<String> frames = cMap.get(hiddenUnitLemmas); if(frames==null) { frames = new THashSet<String>(); frames.add(frame); cMap.put(hiddenUnitLemmas, frames); } else { frames.add(frame); } System.out.println("Processed:"+hiddenUnitLemmas); } } SerializedObjects.writeSerializedObject(cMap,hvCorrespondenceFile); return cMap; }