MrEdge73's PluralSingle Item Converter SAV- Convert string plural items to single

mredge73

Member
MrEdge73's PluralSingle Item Converter
Plural Single Stand Alone Version: 20090608PSSAV
Alpha Version
Created by Justin Edge (mredge73)

This script only handles items, it does spend any adventures.
It is designed to be used as a supplement to another .ash script by using:
"import<MrEdge73's PluralSingle Item Converters.ash>"

It is used to convert:
a single item to a plural item string
a plural item to a single item string
get the item ID from plural item string
get the item ID from a single item string

Use:
This Script requires 2 files in your Script or Data Folder:
MrEdge's Item Plurals.txt
MrEdge's Item Singles.txt
These files can be built by running this script directly from main or by calling "BuildSinglePluralMaps();" from another script.
These files do not need to be built very often, only when itemdescs.txt is updated.
Warning: building these files takes a while, about 2-3 minutes so don't abort early.

After building the files you can:
Code:
import<MrEdge73's PluralSingle Item Converter SAV.ash>

//To Single:
string item1="Bjorn's Hammers";
string single=MakeSingle(item1); 	//=> single= Bjorn's Hammer
int ID1=PluralID(item1);			//=> ID1= 32

//To Plural:
string item2="Bjorn's Hammer";	 			
string plural=MakePlural(item2); 	//=> plural= Bjorn's Hammers
int ID2=SingleID(item2);			//=> ID2= 32

Print(item1+"  "+single+"  "+to_string(ID1),"blue");
Print(item2+"  "+plural+"  "+to_string(ID2),"blue");

Output:
Bjorn's Hammers Bjorn's Hammer 32
Bjorn's Hammer Bjorn's Hammers 32

Special thanks to Alhifar!

Version Update:
20090608-Input is return back if nothing can be done with it
20090605-Fixed the Version Check Link
20090604-Alpha Release!
 

Attachments

  • MrEdge73's PluralSingle Item Converter SAV.ash
    6.7 KB · Views: 76
Last edited:

Bale

Minion
I hate to point out that we already have a command to_plural(item) which works fine for making singulars plural and to_int(item) will give us item IDs.

However there is currently no substitute for converting plurals to singular, so thanks for that.
 

mredge73

Member
Yea, I knew that (that is exactly the motivation to create this script)
It took a lot of work to go from plurals to singular, so adding a function to go the other way was quick and easy once that was done, a little copy/paste.
The existing mafia functions do not work with strings so maybe the new ones may find a home for somebody.
The motivation for creating this for me was for parcing the stash log so it can be converted to useful information. The items donated or taken are are usually plural and can not be used: to_item(plural item string).
 

Bale

Minion
Yay! This whole script has been rendered moot by jasonharper who has implemented:

Code:
Revision: 7365
Author: jasonharper
Date: 9:15:14 AM, Saturday, June 06, 2009
Message:
Added ASH function to_item(string, int), which behaves the same as
to_item(string) except that it will accept plural item names if the 2nd
parameter is greater than one.  (It's impossible to reliably parse items that
might be plural without some external indication of quantity, due to "evil
golden arches" which is both singular and plural.)

item to_item(string, int) will return the name of an item now, regardless of whether the input string is plural or singular based on whether the input int is a quantity of 1 or greater than 1.
 

mredge73

Member
Awesome!
Don't need this anymore, oh well, at least I learned a few things while building it.

damn, Jason's update does not work!
My script still works great, updated today.

Test Code
version r7366
Code:
Code:
import<MrEdge73's PluralSingle Item Converter SAV.ash>

//To Single:
string item1="Bjorn's Hammers";
string single=MakeSingle(item1); 	//=> single= Bjorn's Hammer
int ID1=PluralID(item1);			//=> ID1= 32
item NewUpdate1 = to_item(item1);
int ID3= to_int(NewUpdate1);

//To Plural:
string item2="Bjorn's Hammer";	 			
string plural=MakePlural(item2); 	//=> plural= Bjorn's Hammers
int ID2=SingleID(item2);			//=> ID2= 32
item NewUpdate2 = to_item(item2);
int ID4= to_int(NewUpdate2);

Print(item1+"  "+single+"  "+to_string(ID1),"blue");				// Bjorn's Hammers Bjorn's Hammer 32
Print(item2+"  "+plural+"  "+to_string(ID2),"blue");				// Bjorn's Hammer Bjorn's Hammers 32
Print(item1+"  "+to_string(NewUpdate1)+"  "+to_string(ID3),"blue");		// Bjorn's Hammers Bjorn's Hammer 32
Print(item2+"  "+to_string(NewUpdate2)+"  "+to_string(ID4),"blue");		// Bjorn's Hammer Bjorn's Hammer 32

Output:
Bjorn's Hammers Bjorn's Hammer 32
Bjorn's Hammer Bjorn's Hammers 32
Bjorn's Hammers none -1
Bjorn's Hammer Bjorn's Hammer 32
 
Last edited:

mredge73

Member
your right, missed that.
I guess I should have read it more carefully.
thanks
 
Last edited:
Top