CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: inverse index

  1. #1
    Join Date
    Aug 2013
    Posts
    6

    inverse index

    over the past week i have been trying to create a program that reads in two text files. Then the inverse index should produce the following set of key:value pairs
    {‘my’:[1,2], ‘dog’:[1,2], ‘has’:[1], ‘no’:[1,2], ‘nose’:[1], ‘wants’:[2], ‘bone’:[2]}
    i have been trying to do this with out using the container map and vector and only using the header files: iostream,fstream,cmath and string
    i know how to read and search text files and i have been been researching so much but there is no piece of code that i have been able to find to help me create this program. So if you could please help me i would really appreciate it?

  2. #2
    Join Date
    Aug 2013
    Posts
    6

    Re: inverse index

    by the way one file reads “my dog has no nose” and the other reads no dog wants my bone”

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: inverse index

    Well, how would you do it with a pencil on a paper sheet?
    Victor Nijegorodov

  4. #4
    Join Date
    Aug 2013
    Posts
    6

    Re: inverse index

    so are you saying that its not possible to create a map like function without using the container map

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: inverse index

    Quote Originally Posted by casjb View Post
    so are you saying that its not possible to create a map like function without using the container map
    Where was I saying it?
    You can. but before you will implement it in C++ code you have to understand how you will do it!
    Victor Nijegorodov

  6. #6
    Join Date
    Aug 2013
    Posts
    6

    Re: inverse index

    okay so will u be able to breakdown how to go about it please?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: inverse index

    Quote Originally Posted by casjb View Post
    okay so will u be able to breakdown how to go about it please?
    Probably. But not now.
    Victor Nijegorodov

  8. #8
    Join Date
    Aug 2013
    Posts
    6

    Re: inverse index

    is there anyone who will be able to breakdown how to create a map like function without using the container map please?

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: inverse index

    Quote Originally Posted by casjb View Post
    {‘my’:[1,2], ‘dog’:[1,2], ‘has’:[1], ‘no’:[1,2], ‘nose’:[1], ‘wants’:[2], ‘bone’:[2]}
    i have been trying to do this with out using the container map and vector and only using the header files: iostream,fstream,cmath and string
    So in other words, you're learning 'C' instead of C++.
    but there is no piece of code that i have been able to find to help me create this program.
    That is not how programming works.

    You have to first figure out logically how to solve the problem. Then you write the steps down -- then you translate those steps into a C++ program.
    So if you could please help me i would really appreciate it?
    Well, if you could use a map and vector, how would you solve it? After you answer that question, then you look at your solution and replace map and vector with your own classes that do the same thing.

    Regards,

    Paul McKenzie

  10. #10
    Join Date
    Apr 1999
    Posts
    27,449

    Re: inverse index

    Quote Originally Posted by casjb View Post
    is there anyone who will be able to breakdown how to create a map like function without using the container map please?
    Is this a homework assignment? Why can't you use map?

    Regards,

    Paul McKenzie

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: inverse index

    Quote Originally Posted by casjb View Post
    is there anyone who will be able to breakdown how to create a map like function without using the container map please?
    Anyway, have you used arrays and structs, because those are the aggregate types that wasn't on your list of banned items. If you can't use arrays and structs, then the course you're taking is a waste of your time as it is a cruel joke played on you.

    You have a string and then you have an array of integers associated with the string. This is where struct usage is done (that's how you associate) where you group the string and array in one entity. Then you need an array of these structs so that you can facilitate searching the array for a string to see if it was found, etc.

    In other words, it isn't just a map issue. You have to build the program from scratch -- create the proper data struture, then you need to parse the text and populate the structure accordingly. Just parsing the data doesn't require any map usage.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; August 13th, 2013 at 01:34 PM.

  12. #12
    Join Date
    Aug 2013
    Posts
    6

    Re: inverse index

    Thankyou very much paul

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
  •  





Click Here to Expand Forum to Full Width

Featured