aquafatz's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
19 (0.03 per day)
Joined:
23-September 12
Profile Views:
492
Last Active:
User is offline May 27 2013 02:18 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   aquafatz has not set their status

Posts I've Made

  1. In Topic: Win32 Programming Introduction

    Posted 24 May 2013

    Very helpful tutorials!! Thanks!! :)
  2. In Topic: Netbeans-generate number of radio buttons dynamically

    Posted 8 Dec 2012

    Oh ok. Sure...I'll work on that. Thanks!
  3. In Topic: Building an inverted index-logic

    Posted 27 Oct 2012

    Thank you!!
    @baavgai What is String path? I didn't understand that. Could you please give an example.

    @CasiOo I'll start working on the array concept and get back with what I could manage.
  4. In Topic: Sort the values in a map-Sorting incorrectly

    Posted 2 Oct 2012

    I found my mistake. I've made the changes.
    But I think there is something wrong with my logic.
    Because the 'sorted map' is empty {}. Whereas it should contain the elements of 'map' sorted in decreasing order by the values.
    Thanks!

    package FirstTry;
    
    import java.io.FileInputStream;
    import java.util.Comparator;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.TreeMap;
    import java.io.*;
    
    public class FirstTry3
    {
    	public static void main(String[] args)
    	{
    		try
    		{
    			double nowords = 0;
    			Integer ONE = new Integer(1);
    
    			HashMap<String, Integer> map = new HashMap<String, Integer>();
    		
    			File dir = new File(
    					"\\\\FATTU-PC\\Users\\Fattu\\workspace\\Tokenization\\Cranfieldtrial");
    			for (File fn : dir.listFiles())
    			{
    				FileInputStream fstream = new FileInputStream(fn);
    				DataInputStream in = new DataInputStream(fstream);
    				BufferedReader br = new BufferedReader(new InputStreamReader(in));
    				String strLine;
    				while ((strLine = br.readLine()) != null)
    				{
    					String[] words = strLine.split("\\s+");
    					for (int i = 0; i < words.length; i++)
    					{
    							//operations on words[]
    							//add to map
    							map.put(words[i], frequency);
    					
    
    					}// for i
    
    				}// while
    				br.close();
    				in.close();
    			}// for files
    			System.out.println("Unsorted map");
    			System.out.println(map);
    			
    			ValueComparator bvc = new ValueComparator(map);
    			TreeMap<String, Integer> sorted_map = new TreeMap<String,Integer>(bvc);
    			
    			System.out.println("sorted map");
    			System.out.println(sorted_map);
    
    		}//try
    		catch (FileNotFoundException e)
    		{
    			e.printStackTrace();
    		}
    		catch (IOException e)
    		{
    			e.printStackTrace();
    		}
    	}//main
    }//class
    
    class ValueComparator implements Comparator<String> 
    {
      
      Map<String, Integer> base;
      
      public ValueComparator(HashMap<String, Integer> map) 
      { 
      	this.base = map; 
      }
      
      public int compare(String a, String B)/> 
      { 
      	if (base.get(a) >= base.get(B)/>) 
      	{
      		return -1;  
      	}
      	else 
      	{ 
      		return 1;  // returning 0 would merge keys }
      	}
      }
    }
     
    
    
    
    
  5. In Topic: Sort the values in a map-Sorting incorrectly

    Posted 2 Oct 2012

    @pbl....thanks! ;) But for what I want, my logic is wrong.

    I changed the logic but I am getting this error. Can't understand the mistake. Could you please guide me?

    Error:
    No enclosing instance of type FirstTry3 is accessible. Must qualify the allocation with an enclosing instance of type FirstTry3 (e.g. x.new A() where x is an instance of FirstTry3).

    P.S. I have just included the code I think might be needed and not the entire code.

    package FirstTry;
    
    /*import*/
    
    public class FirstTry3
    {
    	public static void main(String[] args)
    	{
    		try
    		{
    			double nowords = 0;
    			Integer ONE = new Integer(1);
    
    			HashMap<String, Integer> map = new HashMap<String, Integer>();
    			ValueComparator bvc = new ValueComparator(map);
    			TreeMap<String, Integer> sorted_map = new TreeMap<String, Integer>(bvc);
    
    			File dir = new File(
    					"name of dir");
    			for (File fn : dir.listFiles())
    			{
    				FileInputStream fstream = new FileInputStream(fn);
    				DataInputStream in = new DataInputStream(fstream);
    				BufferedReader br = new BufferedReader(new InputStreamReader(in));
    				String strLine;
    				while ((strLine = br.readLine()) != null)
    				{
    					/*operations on words[]*/
    						
    							map.put(words[i], frequency);
    				}
    
    					
    
    
    				}
    				// System.out.println(map);
    				br.close();
    				in.close();
    			}
    			System.out.println(map);
    			System.out.println(sorted_map);
    			System.out.println(nowords + " total words were found.");
    			System.out.println(map.size() + " distinct words were found.");
    
    		}
    		catch (FileNotFoundException e)
    		{
    			e.printStackTrace();
    		}
    		catch (IOException e)
    		{
    			e.printStackTrace();
    		}
    	}
    
    	class ValueComparator implements Comparator<String>
    	{
    
    		Map<String, Integer> base;
    
    		public ValueComparator(HashMap<String, Integer> map)
    		{
    			this.base = map;
    		}
    
    	
    		public int compare(String a, String B)/>
    		{
    			if (base.get(a) >= base.get(B)/>)
    			{
    				return -1;
    			}
    			else
    			{
    				return 1;
    			} // returning 0 would merge keys
    		}
    	}
    }
    
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

aquafatz hasn't added any friends yet.

Comments

aquafatz has no profile comments yet. Why not say hello?