Question about comparing an array of names to a hash table

I'm still learning Powershell but feel like I have the basics now. I have a new project I'm working on and want some input as the best way to do this:
The Problem:
Let's say you have a list of several hundred video game titles and the dollar value of each in a text or two column CSV file.
The example CSV file looks likes this:
Game, Price
Metroid, $15.00
The Legend of Zelda!, $12.00
Mike Tyson's Punch-Out!, $18.00
Super Mario Bros., $16.00
Kung Fu, $7.00
You have another list of just the video game titles, this most likely is just a text file with each title listed on its own line.
The example text file looks like this:
Kung Fu
Metroid
Mike Tysons Punch-Out
Legend of Zelda
What I think would happen in the Script:
Use import-csv and create a hash table that will contain a key = Title and the value = the price.
Use import-csv and create an array for the title names.
Foreach loop through each Game Title and match the value against the Hash Table, if there's a match found, put that into another array that will later add all prices of each item and give you a total sum.
The challenge:
So far when I try and do one line examples of comparing names against the hash table it seems to only work with exact name matches. In the above example I've purposely made the game titles slightly different because in the real world people just write things
differently.
With that said, I've tried using the following single line to match things up and it only seems to work if the values match exactly.
$hash_table.ContainsKey("Game Title")
Is there a regex I should use to change the input of the game titles before creating the hash table or doing the compare? Is there another matching operator that is better and matching with String values that have slightly different grammar. An example would
be the game "The Legend of Zelda". Sometimes people just put "Legend of Zelda", that's close but not exact. I think using a regex to remove extra spaces and symbols would work, but what about for matching of words or letters??
Any ideas would be very helpful and thanks!

There's no pat answer for this.
You can create an array from the hash table keys:
$hashtable = @{"The Legend of Zelda" = 15.00}
$titles = $hashtable.getenumerator() | select -ExpandProperty Name
And then test that using a wildcard match:
$titles -like "*Game Title*"
and see if it returns just one match.  If it does then use that match to do your lookup in the hash table.  If it returns 0, or more than one match then you need to check the spelling or qualify the title search some more.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

Similar Messages

  • Comparing String values against a collection of Names in a Hash Table

    Objective:
    Is to make a script that will import a csv file containing two values: "Name" and "Price". This would ideally be stored in a hash table with the key name of "Name" and the value being "Price". The second part would be
    importing a second csv file that has a list of names to compare too. If it finds a similar match to a key name in the hash table and then it will add that to a new array with the price. At the end it would add all the prices and give you a total value.
    The Problem to Solve:
    In the real world people have a tendency to not write names exactly the same way, for example I am looking at a list of books to buy in an eBay auction. In the auction they provide a text list of all the names of books for sale. In my price guide it has all
    the names and dollar values of each book. The wording of the way each book is named could differ from the person who writes it and what is actually in my reference pricing list. An example might be "The Black Sheep" vs "Black Sheep" or
    "Moby-Dick" vs "Moby Dick".
    I've tried making a script and comparing these values using the -like operator and have only had about 70% accuracy. Is there a way to increase that by 
    comparing the characters instead of likeness of words? I'm not really sure how to solve this issue as it's very hard to do quality check on the input when your talking about hundreds of names in the list. Is there a better way to compare values in power-shell
    then the "like" operator? Do I need to use a database instead of a hash table? In the real world I feel like a search engine would know the differences in these variations and still provide the desired results so why not for this type of application?
    In other words, create a bit more intelligence to say well it's not a 100% match but 90% so that is close enough, add it to the array as a match and add the price etc..
    I'd be curious as to any thoughts on this? Maybe a scripting language with better matching for text?

    Have you considered setting up a manual correction process that "learns" as you make corrections, automatically building a look up table of possible spellings of each Name?  If you get an exact match, use it.  If not, go to the look up
    table and see if there's been a previous entry with the same spelling and what it was corrected to.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How about use partial key to loop at a hashed table?

    Such as I want to loop a Internal table of BSID according to BKPF.
    data itab_bsid type hashed table of BSID with unique key bukrs belnr gjahr buzid.
    Loop at itab_bsid where bukrs = wa_bkpf-bukrs
                              and    belnr  = wa_bkpf-belnr
                              and    gjahr  = wa_bkpf-gjahr.
    endloop.
    I know if you use all key to access this hashed table ,it is certainly quick, and my question is when i use partial key of this internal hashed table to loop it, how about its performance.
    Another question is in this case(BSID have many many record) , Sorted table and Hashed table , Which is better in performance.

    You can't cast b/w data reference which l_tax is and object reference which l_o_tax_code is.
    osref is a generic object type and you store a reference to some object in it, right? So the question is: what kind of object you store there? Please note - this must be an object reference , not data reference .
    i.e
    "here goes some class
    class zcl_spfli definition.
    endclass.
    class zcl_spfli implementation.
    endclass.
    "here is an OBJECT REFERENCE for it, (so I refer to a class) i.e persistent object to table SPFLI
    data oref_spfli type ref to zcl_spfli.
    "but here I have a DATA REFERENCE (so I refer to some data object) i.e DDIC structure SPFLI
    data dref_spfli type ref to spfli.
    So my OSREF can hold only oref_spfli but it not intended for dref_spfli . That's why you get this syntax error. Once you have stored reference to zcl_spfli in osref then you will be able to dereference it and access this object's attributes.
    data: osref type osref.
    create object osref_spfli.
    osref = osref_spfli.
    "now osref holds reference to object, you can deference it
    oref_spfli ?= osref.
    osref_spfli->some_attribute = ....
    OSREFTAB is just a table whose line is of type OSREF (so can hold multiple object references - one in each line).
    Regards
    Marcin

  • Question about Contact Sheets and Version name.

    When making a contact sheet, is it possible to just have the image number under each photo and NOT the words "Version Name" in front of each number?
    Thanks for any help.

    Hi John Cardamone;
    When I saw your question I had thought I had seen it before and was wondering if there was an answer on the other posting. So I did a search which brought up your seven posting of the same question that is all.
    Allan

  • Question about Mail app and domain name please help

    Hi,
    I wasn't sure where to post this question so figured this would be the best area. I have a website which uses bluehost as it's web hoster. My email is set up through them, such as [email protected]
    In my Mail app, I have the POP thing set up so when ever someone emails me it goes right to the Mail app. It works great for my personal computer, but when I go to work and go on other computers is where the problem is.
    When I am on a random computer at work, I have to sign onto my webhosting site and then use squirrel mail. It is quite a hastle and is not the best. I would love to use gmail, but still keep my domain name I have.
    One co-worker mentioned just forwarding all my [email protected] emails to my new gmail email. There are issue's with doing this because if I'm at work and email someone with gmail it will use that email address. Also, I want to be able to read all my sent messages from any computer including the sent messages that were within my Mail app. Is this possible?
    Besides forwarding is there a better solution? It is sort of hard to explain. Basically I want my [email protected] address to be run through gmail, be able to access on any computer, have it be the only address in my mail app, and most importantly have the sent messages from mail app to be able to be read on all computers.
    I think gmail lets you make a domain name email, without gmail being included at the end. But I already have the email address made...am I able to just swap it? And keep all my mail inbox info?
    What's the best sollution for my problem?
    Thanks

    You would need to login to your web mail account to reply so that the email came from "[email protected]"
    I try to get a gmail address that is close to the domain name like - [email protected] - so that I don't have to bother opening web mail as it is a pain.
    I forward to Gmail and then Mac Mail because their spam blocker is the best.
    A lot of web mail addresses bounce mail because the capacity is limited and the owners don't go into their control panel to launch their web mail and clear out the old stuff. Lawyers, in particular, are famous for this. For this reason I don't set web mail to keep a copy of the forwarded mail. If my web mail gets full of spam and they start bouncing then its not my problem!

  • Question about very big arrays

    if i want to make a 2dimentional aray that maybe very
    large it may get up to 1000 elements or even more and its size
    may vary at runtime
    question
    1)what do i need to use[b] ?
    2)does anyone have a example code they could post[b] ?
    3)if their isnt a way to do a 2darray at runtime
    how would i do i 1dimentional array that will vary in size at runtime[b] ?
    my goal at this time (for example) is to make a 2dimentional array
    called say RTarray [] []
    during runtime it will increment the size of the array
    from [1 to 1000] ,[2] then decrement it back down to 1
    ...(each of the array elements might be set to 1 or)
    ...(anything thats not really whats important )
    thanks in advance lightwave

    You can try using a variable to set the array at runtime,
    one that varies depending on incoming data:
    protected int DATA_FIELD = IncomingData.length();
    protected int[][] array = new array[DATA_FIELD ][2];Don't know if that's what your looking for?

  • Question about problem using arrays...

    Hey guys, thanks a bunch for the help - I always really appreciate how you guys can take the time to help us people still learning about this amazing language. Anyway the problem goes like this:
    Given an int array, return a new array with double the length where its last element is the same as the original array, and all the other elements are 0. The original array will be length 1 or more. Note: by default, a new int array contains all 0's.
    makeLast({4, 5, 6}) ?? {0, 0, 0, 0, 0, 6}
    makeLast({1, 2}) ?? {0, 0, 0, 2}
    makeLast({3}) ?? {0, 3}//this is basically what it's supposed to do
    public int[] makeLast (int[] nums)
    So I'm just wonder on how the implementation would be like. I know that I would first want to double the array length. After that, I would want to replace every element of the original array with 0's but keep the last element the same. Any suggestions guys?

    So I'm just wonder on how the implementation would be like. I know that I would first want to double the array length.Well, you can't double the length per se. You can't dynamically change the size of an array. Rather, you'll need to create a new array with the size as specified by the homework assignment.
    After that, I would want to replace every element of the original array with 0's but keep the last element the same.Since it's a new array, you wouldn't actually replace anything.
    Any suggestions guys?Hint: the default value, in an array of numbers, is zero.

  • Another question about problem using arrays

    Hey guys, if you helped me answer my other problems thanks a bunch and again thank you to all the people who try to help us learn the unique language of Java. Anyway the other problem goes like this:
    Return the number of even ints in the given array. Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1.
    countEvens({2, 1, 2, 3, 4}) ?? 3
    countEvens({2, 2, 2}) ?? 3
    countEvens({1, 3, 5}) ?? 0
    Ok so basically I would want to count all the evens in an array and basically if I use the module operator I can figure out whether something is even or not if it returns me a 0. So I know there will be an if statement there. I'm wondering if I would have to also use a "for each" statement to check every element. I would also need a variable to keep count of the number of elements that are even. Any suggestions on how the implementation of this method should be like?

    Hey thanks a bunch actually, I just pretty much reasoned it out and ended up with this:
    public int countEvens(int[] nums) {
    int count = 0;
    for (int e:nums)
         if ((e%2)==0)
            count++;
       return count;      
    }Really appreciate the help.

  • Question about using pl/sql to mark records in a table

    I have a table where I have stored college course's details,
    the pertinent for this questions are the fields:
    course_number,
    alt_id1,
    alt_id2,
    cross_relation,
    What I need to do is to identify cross-listed courses (those that have an alt_id1 not null) and set the first one found to be parent in the cross_relation column, then read alt_id1 and alt_id2 and set them as children in the cross_relation column.
    example: what I have (these are in no particular order)
    course_number alt_id1 alt_id2 cross_relation
    en101 | mu101 | hs101 |
    mu101 | en101 | hs101 |
    hs101 | en101 | mu101 |
    what I want: Finds cross listed set it as P for parent and then finds its children an marks them as its children C.
    course_number | alt_id1 | alt_id2 | cross_relation
    en101 | mu101 | hs101 | P
    mu101 | en101 | hs101 | C
    hs101 | en101 | mu101 | C
    I have tried different things with different results but not the one desired,
    Please, I just need some idea on how to accomplish this.
    Thank you

    Sniff... sniff... sure smells like homework to me.
    You're likely looking for a hierachical SQL to determine the parent-child hierachy.
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns001.htm#i1009313

  • Question about how to create FORIGEN KEY constraints against XMLTYPE table

    Hi,
    1.I have a table called SNPLEX_DESIGN which is created as XMLTYPE, the XMLTYPE is refered to a registered XMLschema. The XMLschema has a data element called BATCH_ID, and I create a primary key for the SNPLEX_DESIGN table on the BATCH_ID. The SQL staement as
    ALTER TABLE SNPLEX.SNPLEX_DESIGN ADD (CONSTRAINT "BATCH_ID_PK" PRIMARY KEY(xmldata."BATCH_ID"))
    2. I have another table call SNPLEX_PROCESS which is a regual relational table with a column TOKENID. I would like to create a forign key on TOKENID which needs to refer to the SNPLEX_DESIGN table BATCH_ID_PK primary key.
    But I got error when I try to alter the SNPLEX_PROCESS table.
    SQL> ALTER TABLE "SNPLEX"."SNPLEX_PROCESS" ADD (CONSTRAINT "BATCH_ID_FK" FOREIGN KEY("TOKENID") RE
    FERENCES "SNPLEX"."SNPLEX_DESIGN"(xmldata."BATCH_ID"));
    ERROR at line 1:
    ORA-02298: cannot validate (SNPLEX.BATCH_ID_FK) - parent keys not found
    3. Can someone helps me on this.. I have no problem to create a foreign key in SNPLEX_DESIGN to refere primary key in relational table. But Why I can not do the other way around.
    Any assistances will be appreciated..
    Jinsen

    Hi Jinsen
    As mentioned in the error message not all rows in PROCESS have a corresponding value in DESIGN.
    To find out which are missing do some selects to compare your data or use the exception clause in the ALTER TABLE statement.
    e.g.: ALTER TABLE "SNPLEX"."SNPLEX_PROCESS" ADD (CONSTRAINT "BATCH_ID_FK" FOREIGN KEY("TOKENID") RE
    FERENCES "SNPLEX"."SNPLEX_DESIGN"(xmldata."BATCH_ID")) EXCEPTIONS INTO <exception table>
    Notice that you have to create the <exception table> with the script $ORACLE_HOME/rdbms/admin/utlexcpt.sql.
    Chris

  • Very simple question about how to change a specific field in a table

    Hi,
    I'm working with a simple JSF web application, I have just drag a table, the "travel" standard example, and I just had 3 columns, one with a drop down list, other with a static text field and a Button.
    Then I introduced the following java code in the Button:
    public String button1_action() {
    int quantity=Integer.parseInt(dropMenu.getValue().toString());
    quantityChosen.setValue(quantity);
    When the button is pressed, I can print and check that the value obtained is the one selected in the drop down list, of the respective row.
    The problem that I would like to write it in the respective static text field (in the same row) where the button was pressed.
    What happens is that it write the value in all the column. So it reads from the write place and then write in every column?
    How to write in the respective row?
    Thanks in advance, Junkeira

    Hi,
    I'm working with a simple JSF web application, I have just drag a table, the "travel" standard example, and I just had 3 columns, one with a drop down list, other with a static text field and a Button.
    Then I introduced the following java code in the Button:
    public String button1_action() {
    int quantity=Integer.parseInt(dropMenu.getValue().toString());
    quantityChosen.setValue(quantity);
    When the button is pressed, I can print and check that the value obtained is the one selected in the drop down list, of the respective row.
    The problem that I would like to write it in the respective static text field (in the same row) where the button was pressed.
    What happens is that it write the value in all the column. So it reads from the write place and then write in every column?
    How to write in the respective row?
    Thanks in advance, Junkeira

  • Questions about shared maps

    Hi,
    I have some questions about shared maps. Our Olite Applications has 96 tables. On these 96 tables, 54 tables are tables with DISABLED DML = UID. So, change on the client database are not uploaded to the server. Some of those tables have no where clause and some have a where clause which is the same where clause for all.
    Is it true to say I could put all those tables as shared maps?
    Are they automatically shared because DISABLED DML = UID?
    What would be the advantages of putting those publications items as shared maps?
    Thanks for your help.

    Thanks for your help.
    I looked into CMP$ tables and CLID$$CS is not 0 but egal to my usersnames. I use a java program to create my items and publications.
    I also found in the table C$ALL_TEMPLATE_ITEMS a COLUMN named SHARED and they are all with the value N. So I think they are not shared.
    I think I found where in the API I should make the table shared. It is in the addPublicationItem procedure of the Class ConsolidatorManager. I will try it.
    If we want all users to have all the table data, must we use the groups you talked about?
    If yes, how do i define those groups?
    Thanks

  • Had to change my Apple ID because the original email address is no longer valid.  How do I change the iCloud user name on iMac?  I found instructions about signing out of iCloud and signing back end.  It asks questions about contact, etc.

    Had to change Apple ID due to email address no longer valid.  Trying to change id for icloud...saw direction online about signing out of icloud and signing back in...when it ask questions about contacts, photos, etc. being deleted how do I answer those?  That just sort of freaks me out.

    For the ones that give you an option, select the option you want (keep on the Mac or Delete). For the ones that are simply warning you, click on Delete from Mac.
    They will all come back when you sign back on, since all you did was change your existing Apple ID to a new email address. It's the same iCloud account, just with a different name.
    It's the only way to get your updated ID signed onto iCloud.
    Cheers,
    GB

  • I have a question about extracting pages.  When I do the function, adobe saves the individual files as " file name space page number ", so the files look like this "filename 1.pdf", "filename 2.pdf", "filename 3.pdf".  Without too many gory details, I a

    I have a question about extracting pages.  When I do the function, adobe saves the individual files as "<file name><space><page number>", so the files look like this "filename 1.pdf", "filename 2.pdf", "filename 3.pdf".  Without too many gory details, I am using excel to concatenate some data to dynamically build a hyperlink to these extraced files.  It casues me problems, however, for the space to be the the file name.  Is there any way to change the default behavoir of this function to perhaps use a dash or underscore instead of a space?

    No, you can't change the default naming scheme. You can do it yourself if you extract the pages using a script instead of using the built-in command.

  • Question about the chain step name in DEFINE_CHAIN_STEP

    I have questions about the chain step name in DEFINE_CHAIN_STEP:
    1. Can the step name be a number (e.g. "8")?
    2. Should the step name be unique within a chain or across all chains?
    I am having this exception:
    ORA-25448: rule DMUSER.RULE_6_3707 has errors
    ORA-22806: not an object or REF
    After I changed the step names (in DEFINE_CHAIN_STEP), the chain seems to run fine.
    Thanks,
    Denny

    The reason I asked about the step name is to confirm it can handle numbers (it looks it can handle it from the doc).
    Why I changed the step names say from "11" to "21", the error goes away, that puzzled me. Because the way I defined steps and the rules for the steps were exactly the same. Just changing the step names made the error goes away?!
    Thanks.

Maybe you are looking for

  • MATMAS idoc with classification details - reg

    Hi, I am working in a project related to the transfer of Material Master from one system to another ( Both are R/3 systems). I am currently  using the message type MATMAS with basic type MATMAS05. With the above message type i am able to generate an

  • Look-up error after Upgrade

    Hi, The R/3 system  in our project was upgraded from 4.6 c to ECC 6. After the upgrade we are facing issues with the lmapping look -up. We have used RFC channel to  do look up and and java codes which calls the RFC and dose parsing. Right now after u

  • Creating a Verticle Report

    I need to create a Verticle Report, generally by default all reports in APEX are Horizontal report. Need to know what are the steps involved, I am new to Template modification so if I can get details about the process that will be great...what Templa

  • Web based mail program like hotmail or yahoo

    Hi All, How do I create a web based mail program like yahoo or hotmail using Java Mail API? If any one knows please let me know. my email id: [email protected] Thanks and Regards, Sarat

  • Ios 8.1.2 ipod touch not syncing with computer.

    it is saying i have to authorize the computer and i did. but still didnt work. i then deotherized and otherized again like 5 times still no. somebody help