Java Code Examples for gnu.trove.THashMap#keySet()

The following examples show how to use gnu.trove.THashMap#keySet() . 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: LexicalUnitsFrameExtraction.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
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 2
Source File: OptimizeMapReduce.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public void setValues(double[] values, THashMap<String,Double> paramList, String file)
  {
  	ArrayList<String> keys = new ArrayList<String>(paramList.keySet());
  	int size = keys.size();
  	String[] keyArray = new String[size];
  	keys.toArray(keyArray);
  	Arrays.sort(keyArray);
  	try {
	BufferedWriter bWriter = new BufferedWriter(new FileWriter(file));
   	for(int i = 0; i < size; i ++)
   	{
   		LDouble val = LDouble.convertToLogDomain(values[i]);
   		bWriter.write(keyArray[i]+"\t"+val+"\n");
   	}
   	bWriter.close();
  	} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}    	
  	String command = HADOOP_HOME+"/bin/hadoop dfs -rmr "+intermediateDirectory+"/paramFile.txt"	;
  	ExternalCommands.runExternalCommand(command);
ExternalCommands.runExternalCommand(HADOOP_HOME+"/bin/hadoop dfs -put "+file+" "+intermediateDirectory+"/paramFile.txt");
  }
 
Example 3
Source File: CountNumberOfRoles.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
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 4
Source File: ProduceLargerFrameDistribution.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
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: NormalizeLinDekNeighbors.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: RequiredDataCreation.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: RequiredDataCreation.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
public static Set<String> getSelectedRelatedWords(THashMap<String,Set<String>> rlMap)
{
	Set<String> keys = rlMap.keySet();
	THashSet<String> result = new THashSet<String>();
	for(String key: keys)
	{
		if(key.equals("identity")/*||key.equals("synonym")||key.equals("derived-form")||key.equals("morph")*/)
			result.addAll(rlMap.get(key));
	}
	return result;
}
 
Example 8
Source File: FEDict.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: Decoding.java    From semafor-semantic-parser with GNU General Public License v3.0 5 votes vote down vote up
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 10
Source File: WordNetCoverageCheck.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
	String datadir = "/Users/dipanjand/work/spring2010/FramenetParsing/CVSplits/0";
	// WN files
	String wnConfigFile = "/Users/dipanjand/work/spring2010/FramenetParsing/SSFrameStructureExtraction/file_properties.xml";
	String stopFile = "/Users/dipanjand/work/spring2010/FramenetParsing/SSFrameStructureExtraction/lrdata/stopwords.txt";
	WordNetRelations wnr = new WordNetRelations(stopFile, wnConfigFile);
	Map<String, Set<String>> relatedWordsForWord = 
		(Map<String, Set<String>>)SerializedObjects.readSerializedObject(datadir + "/wnallrelwords.ser");
	Map<String, THashMap<String, Set<String>>> wordNetMap = 
		(Map<String, THashMap<String, Set<String>>>)SerializedObjects.readSerializedObject(datadir + "/wnMap.ser");
	THashMap<String,THashSet<String>> mFrameMap = 
		(THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject(datadir + "/framenet.original.map");		
	String frameElementsFile = 
		"/Users/dipanjand/work/spring2010/FramenetParsing/uData/0/best.frame.elements";
	String parseFile = "/Users/dipanjand/work/spring2010/FramenetParsing/uData/0/AP_1m.all.lemma.tags";
	BufferedReader bReader = new BufferedReader(new FileReader(parseFile));
	ArrayList<String> mListOfParses = getThousandLines(bReader);
	bReader.close();
	BufferedReader feReader = new BufferedReader(new FileReader(frameElementsFile));
	ArrayList<String> fes = getThousandLines(feReader);
	feReader.close();
	
	for (String line: fes) {
		String[] toks = line.split("\t");
		int sentNum = new Integer(toks[5]);
		String parseLine = mListOfParses.get(sentNum);
		String frameName = toks[1];
		String[] tokNums = toks[3].split("_");
		int[] intTokNums = new int[tokNums.length];
		for(int j = 0; j < tokNums.length; j ++)
			intTokNums[j] = new Integer(tokNums[j]);
		Arrays.sort(intTokNums);
		StringTokenizer st = new StringTokenizer(parseLine,"\t");
		int tokensInFirstSent = new Integer(st.nextToken());
		String[][] data = new String[6][tokensInFirstSent];
		for(int k = 0; k < 6; k ++)
		{
			data[k]=new String[tokensInFirstSent];
			for(int j = 0; j < tokensInFirstSent; j ++)
			{
				data[k][j]=""+st.nextToken().trim();
			}
		}
		Set<String> set = mFrameMap.keySet();
		int size = set.size();
		int[][][] allFeatures = new int[size][][];
		allFeatures[0]=getFeatures(frameName, 
				intTokNums, 
				data, 
				mFrameMap, 
				wnr,
				relatedWordsForWord, 
				wordNetMap);
		System.out.print(".");
		int count = 1;
		for(String f:set)
		{
			if(f.equals(frameName))
				continue;
			allFeatures[count]=getFeatures(f, 
					intTokNums, 
					data, 
					mFrameMap, 
					wnr,
					relatedWordsForWord,
					wordNetMap);
			System.out.print(".");
			count++;
		}
		System.out.println();	
	}
}
 
Example 11
Source File: WordNetRelationsCache.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
public static void verifyMap()
{
	String stopWordsFile = "/usr0/dipanjan/work/fall2008/SentenceSentence/QG4Entailment/data/stopwords.txt";
	String wordNetConfigFile = "file_properties.xml";
	WordNetRelations wnr = new WordNetRelations(stopWordsFile, wordNetConfigFile);
	String relationsMapFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/hierWnDevCacheRelations.ser";
	THashMap<String,THashSet<String>> map = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject(relationsMapFile);
	String frameFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/alldev.m45.frames";
	String parsesFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/alldev.m45.parsed";
	String frameMapFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/framenet.original.map";
	ArrayList<String> frames = ParsePreparation.readSentencesFromFile(frameFile);
	ArrayList<String> parses = ParsePreparation.readSentencesFromFile(parsesFile);
	THashMap<String,THashSet<String>> frameMap = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject(frameMapFile); 
	int size = frames.size();
	for(int i = 0; i < size; i ++)
	{
		String frameLine = frames.get(i);
		String[] toks = frameLine.split("\t");
		String frameName = toks[0];
		int sentNum = new Integer(toks[2]);
		String[] tokNums = toks[1].split("_");
		int[] intTokNums = new int[tokNums.length];
		for(int j = 0; j < tokNums.length; j ++)
			intTokNums[j] = new Integer(tokNums[j]);
		Arrays.sort(intTokNums);
		StringTokenizer st = new StringTokenizer(parses.get(sentNum),"\t");
		int tokensInFirstSent = new Integer(st.nextToken());
		String[][] data = new String[5][tokensInFirstSent];
		for(int k = 0; k < 5; k ++)
		{
			data[k]=new String[tokensInFirstSent];
			for(int j = 0; j < tokensInFirstSent; j ++)
			{
				data[k][j]=""+st.nextToken().trim();
			}
		}
		Set<String> frameSet = frameMap.keySet();
		Iterator<String> frameItr = frameSet.iterator();
		while(frameItr.hasNext())
		{
			String frameDashed = frameItr.next();
			findRelationsForFrame(frameMap, frameName, intTokNums, data, wnr, map);
		}
		
	}
}
 
Example 12
Source File: RequiredDataCreation.java    From semafor-semantic-parser with GNU General Public License v3.0 4 votes vote down vote up
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;
}