Results 1 to 7 of 7
  1. #1
    Lmadahali is offline Member
    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Default replacing names with numbers

    Hello everyone.
    I have a coauthorship network and I want to replace the authors names with numbers.Part of my datadet:
    1992,M_DINE,R_LEIGH,P_HUET,A_LINDE,D_LINDE
    1992,C_BURGESS,J_CLINE,M_LUTY
    1992,M_DINE,R_LEIGH,P_HUET,A_LINDE,D_LINDE
    1992,F_ZWIRNER
    1992,O_HERNANDEZ
    ...
    I want the result to be sth like this:
    1992 1,2,3,4
    1992 5,67
    ....
    and a table of mappings
    M_DINE 1
    R_LEIGH 2
    P_HUET 3
    ....

    I give my dataset in csv (or text) format to my program but it says "(The system cannot find the file specified)" even though the file exists.
    what should I do?
    here is my code:
    Java Code:
    public class ReadCSV { 
    	
    	HashMap<String, Integer> authorList = new HashMap<>();
    	File file = new File("d:/Course/thesis/predict/whole.scv");
    	int authorCounter = 0;
    
      public static void main(String[] args) {
    	
    	  ReadCSV obj = new ReadCSV();
    		obj.run();  		
      } 
        public void run(){
    	  
    	  try{
    		  Scanner in=new Scanner(file);
    		  String input = in.next();
    		  String[] authors = input.split(",");
    		  for(int i = 1; i < authors.length; i++)
    		        { //skip index 0 because that's the year
    			       addAuthor(authors[i]);
    	            }
    	  }
    	  catch (IOException e) {
    			e.printStackTrace();
    	  }
      }
      
      
      void addAuthor(String s){
    	  
    	  if(authorList.get(s) == null)
    	        authorList.put(s, ++authorCounter);
    	  
      }
    }
    Last edited by Lmadahali; 11-05-2014 at 07:58 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: replacing names with numbers

    Please edit your post and wrap your code with highlight tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    The system cannot find the file specified)" even though the file exists.
    Is the path spelled correctly?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Lmadahali is offline Member
    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Default Re: replacing names with numbers

    Yes spelling is correct.and when I write file.exists() it says the file doesnot exist.but the file exists

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: replacing names with numbers

    Do a sysout of file.getAbsolutePath(). Does it match?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Lmadahali is offline Member
    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Default Re: replacing names with numbers

    I was doing something else wrong.Thanks guys.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: replacing names with numbers

    File file = new File("d:/Course/thesis/predict/whole.scv");
    I give my dataset in csv
    Those extensions are different.
    Last edited by Norm; 11-05-2014 at 04:52 PM.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Lmadahali is offline Member
    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Default Re: replacing names with numbers

    That's right.I found my mistake.
    Thank you

Similar Threads

  1. Replies: 0
    Last Post: 07-27-2014, 03:10 PM
  2. Replacing Containers?
    By IndiDev in forum AWT / Swing
    Replies: 2
    Last Post: 01-24-2012, 06:50 PM
  3. Replies: 11
    Last Post: 01-14-2011, 07:36 PM
  4. Replacing Else If
    By jingly99 in forum Advanced Java
    Replies: 5
    Last Post: 12-29-2009, 12:06 AM
  5. printing two smallest numbers from a series of numbers
    By trofyscarz in forum New To Java
    Replies: 2
    Last Post: 10-15-2008, 12:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •