Using this help page: How To: Group unique values from multiple attribute fields in ArcGIS Pro
This little Arcade script groups unique values from multiple attribute fields. I created two variables, one for each attribute field. I then grouped unique values from each of the two fields and named it Batteries. It works fine.
var cat = $feature.USER_Categ
var key = $feature.USER_Keywo
if (cat == "Batteries;"){
if (key == "Lead-Acid Batteries;"){
return "Batteries"}
}
How would I group multiple unique values? I've tried using multiple if statements, but that didn't seem to work.
Solved! Go to Solution.
Hi Jared Pilbeam ,
In the middle of the expression you would not put a string test value, but connect directly to the attribute you want to evaluate:
When you run it, the output field will be classified:
You will still end up with 52 categories at the moment:
Expression used for this calculation:
function GetGroup(keyword) {
var dct_groups = {'Appliance Recycling': 'Air Conditioner;Appliance;Refrigerator;Dishwasher;Dryer;Oven;Stove;Washer;Water Heater',
'Asbestos Info / Removal Service': 'Asbestos',
'Automobile & Boat Reuse Recycling': 'Airplane; Automobile;Boat;Car;Recreation Vehicle;RV;Truck',
'Awards & Recognition': 'Awards (Eco-Award)',
'Batteries': 'Lead-Acid Batteries;Single Use AA, AAA, C, D, 9-Volt;Batteries - Rechargeable, BackUp;Lead-Acid Batteries;Rechargebale;Disposable Batteries;Rechargeable;Automotive Batteries;Boat Batteries;Lithium Batteries;Button Batteries',
'Bicycle Reuse Donation': 'Bicycles',
'Book Recycling': 'Books - Hardcover Recycling;Books - Softcover Recycling',
'Cellular Telephone Reuse & Recycling': 'Cell Phone - Retail Drop-Off;Cell Phone - Electronic Drop Off',
'Clean - Up Services': 'Clean-Up of Properties;',
'Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations': 'Clothing;Gym Shoes / Sneakers / HighTops;Linens / Blankets / Tableclothes / Towels;Textile / Fabrics / Drapes / Curtains;Shoes / Boots;Purse or Handbag',
'Commercial Hazardous Waste': 'Hazardous Waste Services;Chemical Business Waste',
'Composting Facilities/Landscape Waste transfer Stations': 'Composting Facilities/Landscape Waste transfer Stations;Landscape Material Recycling',
'Computer Reuse & Recycling': 'Business Electronic Devices',
'Construction & Demolition Recycling': 'Asphalt;Brick;Building Construction & Demolition Debris;Carpet;Carpet Padding;Concrete;Dirt;Drywall;Gravel;Padding;Roofing Materials;Shingles;Soil;Stone;Vinyl Siding;Windows;Wood-Untreated;Pallets',
'Cooking Oil/Grease Recycling & Trap Service': 'Cooking Oil;Grease Recycling;Grease Trap Services',
'Crayon Recycling': 'Crayons',
'Curbside Recycling': 'Aerosol Cans (empty) Curbside;Aluminum Can Curbside;Aluminum Foil Curbside;Cardboard & Chipboard Curbside;Curbside Recycling;Glass Bottles & Jars Curbside;Juice Boxes/Drink Pouches Curbside;Paper (magazines, phone bks, etc) Curbside;Plastic #1 (PET) & #2 (HDPE) Containers;Plastic #3, #4, #5, #7, Containers Curbside;Six-Pack Rings Curbside;Tin / Steel Cans (soup,cofffee, etc) Curbside',
'Demolition Material Recycling & Disposal': 'Construction Material Reuse;Demolition Material Reuse / Recycling',
'Disposable Batteries': 'Batteries - Single Use AA, AAA, C, D, 9-Volt',
'Donation': 'Books - Hardcover;Computer Reuse/Donation;Couch;Sofa;Toys',
'Drum & Cylinder Disposal or Recycling': 'Cylinders;Drums',
'Dry Cleaners (Green)': 'Dry Cleaning',
'Electronics': 'Adding Machines;Answering Machines;Calculators;Cameras;Cassettes;CB\'s/Two-way radios;CD Players / Laser Disc Players;CD ROM Drives;CDs, DVDs;Cell Phone - Electronic Drop-Off;Computer Recycling;Computer Recycling Drop-Off;Copy Machine;Cords & Cables;Digital Clocks;DVD Machine;Electronic Mice;Electronics;Fax Machines;Floppy Disks;Hand Held Games;Hard Drives;Joysticks/Game controls;Keyboards;Microwaves;Modems;Monitors;Pagers;Palm Organizers;Paper shredders;Portable Radio; Postage Machines;Printers;Scanner Machines;Speakers/Stereo Systems;String Lights / Holiday String Lights;Sump Pump;Tape Drives;Telephone;Televisions;Thermometers (digital);Typewriters/Word Processors;UPS Battery Backups;VCR Machine;VHS Tapes;Video Game Players; Zip Drives',
'Eye Glass Reuse': 'Eye Glasses',
'Fire Extinguisher Refilling or Recycling': 'Fire Extinguishers',
'Fluorescent Lights': 'CFLs;Compact Fluorescent Light Bulbs;Fluorescent Lights',
'Food Donation': 'Food Donation',
'Furniture & Office Equipment ': 'Book Cases;Cubical Walls;Desks;File Cabinets;Furniture & Office Equipment;Office Chairs',
'Geothermal Energy': 'Geothermal',
'Gift Cards': 'Gift Cards (merchant plastic money card)',
'Green Energy Supplier': 'Energy Supplier',
'Grocery Bag': 'Grocery Bags',
'Heating Oil Tank Removal': 'Heating Oil Tank Removal',
'Household Hazardous Waste (HHW)': 'Aerosol Products;Antifreeze;Automotive Batteries;Automotive Fluid;Boat Batteries;Button Batteries;Cleaning Chemicals;Compact Fluorescent Light Bulbs - HHW Drop-Off;Drain Cleaners;Driveway Sealer;Fertilizers;Fluorescent Light Bulbs;Gasoline-Oil Mix;Hazardous Household Materials;HHW;Household Chemicals;Lawn & garden chemicals;Lithium Batteries;Medication (old or unwanted);Mercury / Mercury Products;Motor Oil;Nail Polish Remover;Oil Filters;Oil-based Paint / Stain / Varnish;Old Gasoline;Paint Thinners;Pesticides;Pool Chemicals;Rechargeable Batteries;Solvents;Thermometers (glass);Used Oil;Medication (old or unwanted);Thermometers (glass);Cough Medicine;Inhalers;Medicated Shampoo;Ointment / Medicated Ointment;Over-the-Counter Medication;Pills, Pharmaceuticals, Medication;Prescription Medication;Sunscreen;Vitamins',
'Landfill & Transfer Stations': 'Landfills & Transfer Stations;Beverage Carrier Straps;Six-Pack Rings;Plastic #1, PET;Plastic #2, HDPE;Plastic #3, PVC;Plastic #4, LDPE;Plastic #5, PP;Plastic #7, Other Container;Aerosol Cans (empty) Drop-Off;Aluminum Can Recycling Drop-Off ;Aluminum Foil Recycling Drop-Off;Glass Bottles and Jars Drop-Off;Juice Boxes / Drink Pouches Drop-Off;Tin / Steel Cans (soup, coffee, etc) Drop-Off;',
'Latex Paint': 'Latex Paint',
'Lead-base Paint Concerns': 'Lead Paint',
'Manure': 'Manure',
'Matress Recycling': 'Matress & Box Springs',
'Medical Equipment (durable)': 'Canes;Crutches;Portable Toliets;Shower Chairs;Wheelchairs',
'Medication Drop-Off': 'Cough Medicine;Inhalers;Medicated Shampoo;Ointment / Medicated Ointment;Over-the-Counter Medication;Pills, Pharmaceuticals,Medication;Prescription Medication;Sunscreen;Vitamins',
'Metal Recycling': 'Scrap Metal;Aluminum / Aluminum Can Scrap;Brass;Copper;Iron;Steel Scrap;',
'Motor Oil - Bulk': 'Motor Oil in Buk Drums',
'Motor Oil Recycling (DIY)': 'Motor Oil - DIY',
'Packaging Materials': 'Packing Peanut ;Styrofoam Peanuts;Cardboard Boxes',
'Pallet Reuse or Recycling': 'Pallets',
'Paper Recycling': 'Cardboard;Chipboard;Colored Paper;Construction Paper;Junk Mail;Magazines;Newspaper;Office Paper;Paper Recycling;Shredding Services;Clored Paper',
'Plastic Carrier Strap Recycling': 'Beverage Carrier Straps;Six-Pack Rings',
'Plastic Container Recycling': 'Plastic #1, PET;Plastic #2, HDPE;Plastic #3 PVC;Plastic #4, LDPE;Plastic #5, PP;Plastic #7, Other Container',
'Pop-Tab Recycling': 'Pop-Tab',
'Printer/Toner Cartridge & Ribbon Recycling': 'Inkjets (Ribbons);Printer/Toner Cartridges',
'Propane Tank Disposal or Recycling': 'Propane Tanks',
'Rechargeable Battery': 'Batteries - Rechargeable, BackUp, Lead-Acid;Rechargeable',
'Recycling and Waste Collection Companies': 'Recycling Collection Company;Garbage Collection Company;Waste Collection Company',
'Repair Services': 'Sharpening Services',
'Reuse & Resale Shops': 'Reuse/Resale',
'Smoke Detectors ': 'Smoke Detectors ',
'Solar Energy': 'Solar Energy',
'Styrofoam or Polystyrene Recycling': 'Plastic #6, PS, Polystyrene;Styrofoam',
'Tire Recycling': 'Tire',
'Water Conservation': 'Rain Barrels;Rain Garden',
'Wind Energy': 'Small Wind'}
for (var group in dct_groups) {
var keywords = dct_groups[group];
if (Find(keyword, keywords)>-1) {
return group;
}
}
return null;
}
// the value you want to evaluate
var test = $feature["USER_Keywo"];
var lst = Split(test, ";");
var groups = [];
for (var i in lst) {
Console(i)
var kw = lst[i];
if (!IsEmpty(kw)) {
Console(" - kw:" + kw);
var group = GetGroup(kw);
if (!IsEmpty(group)) {
Console(" - group:" + group);
groups[Count(groups)] = group;
}
} else {
Console(" - item is empty");
}
}
Console("groups:" + groups);
var dct_groups = {};
for (var i in groups) {
var group = groups[i];
if (HasKey(dct_groups, group)) {
dct_groups[group] += 1;
} else {
dct_groups[group] = 1;
}
}
Console("dct_groups:" + dct_groups);
var cntmax = 0;
var finalgroup = "";
for (var group in dct_groups) {
var cnt = dct_groups[group];
if (cnt > cntmax) {
finalgroup = group;
cntmax = cnt;
}
}
Console("finalgroup: " + finalgroup);
return finalgroup;
Hey Jared Pilbeam,
I'm not sure I fully understand but you could try using the split function (Text Functions | ArcGIS for Developers ) to split the values by ";" and then loop through each one?
Thanks,
Ben
If this answer has helpful please mark it as helpful. If this answer solved your question please mark it as the answer to help others who have the same question.
Hi Ben,
I won't have time to work on this for a few days, but I wanted to try and clarify my question. I've tried using the same variable to get more of the unique values from the table, for example, and it verified as valid. But, there were no results.
if (cat == "Batteries;"){
if (cat == "Batteries;Disposable Batteries;Household Hazardous Waste (HHW);Rechargeable Battery;")
if (key == "Lead-Acid Batteries;"){
if (key == "Lead-Acid Batteries;Batteries - Single Use AA, AAA, C, D, 9-Volt;Automotive Batteries;Boat Batteries;Button Batteries;Lithium Batteries;Rechargeable Batteries;Batteries - Rechargeable, BackUp, Lead-Acid;Rechargeable;"){
return "Batteries"}
}}
I also tried separating the values by comas, but that didn't produce any results either.
var cat = $feature.USER_Categ
var key = $feature.USER_Keywo
if (cat == "Automobile and Boat Reuse Recycling;", "Batteries;", "Batteries;Disposable Batteries;Household Hazardous Waste (HHW);Rechargeable Battery;"){
if key == "Bicycles;","Brick ;Building Construction & Demolition Debris;Drywall;Padding;Soil;Stone;Windows;Wood-Untreated;Construction Material Reuse;Demolition Material Reuse / Recycling;", "Books - Hardcover Recycling;Books"){
return "battery"}
}
Hey Jared Pilbeam,
Ok I think I have a better understanding now. One way you could do this is to create a list of all the words you want associated with batteries:
#If any of these words appear in the category I want it to return the word battery.
var batteries = ["Batteries","Disposable Batteries","Household Hazardous Waste (HHW)","Rechargeable Battery"]
#loop through each of the battery types
for (var batteryType in batteries){
#We search through the category for each of the battery types and if we get a match we return the word batteryif(Find(batteryType,cat) >=0) { #Find will return the starting position number of the word or -1 if it can't find it.
#So we check for anything greater than -1
return ("Battery")
}}
Let me know if it needs any other tweaks.
Thanks,
Ben
If this answer has helpful please mark it as helpful. If this answer solved your question please mark it as the answer to help others who have the same question.
Hi Ben Turrell,
Thanks for that. I put in the list all the category unique values straight from the Insert Values drop-down, and then added the for loop. It validates okay, but the "Batteries" group still isn't created.
You're looking for those strings ("Batteries;", "Batteries;Disposable Batters;...", etc.) in the category, not the keyword (if(Find(batteryType,cat) >=0)
Will,
Why would I not search the cat field? Shouldn't I be able to search either field?
This validates, but displays no results for "Battery":
var cat = $feature.USER_Categ
var key = $feature.USER_Keywo
if (cat == "Appliance Recycling;"){
if (key == "Air Conditioner;Appliance;Dishwasher;Dryer;Oven;Refrigerator;Stove;Washer;Water Heater;"){
return "Appliances"}
}
if (cat == "Asbestos Info / Removal Service;"){
if (key == "Asbestos;"){
return "Asbestos"}
}
if (cat == "Automobile and Boat Reuse Recycling;"){
if (key == "Airplane;Automobile;Boat;Car;Recreation Vehicle;RV;Truck;"){
return "Automobile & Boat"}
}
var batteries = ["Batteries","Disposable Batteries","Household Hazardous Waste (HHW)","Rechargeable Battery"]
for (var batteryType in batteries){
if(Find(batteryType,cat) >=0) {
return ("Battery")
}
}
Oddly enough, when I replace cat with key a symbol is created for "Battery". But, the USER_Keywo and USER_Categ fields do not have any of these unique values I'm searching for:
var batteries = ["Batteries","Disposable Batteries","Household Hazardous Waste (HHW)","Rechargeable Battery"]
for (var batteryType in batteries){
if(Find(batteryType,key) >=0) {
return ("Battery")
}
}
Ben Turrel Am I doing something wrong or is the Arcade Find Function not working the way it should?
Hi Jared Pilbeam ,
Edit 1: I just noticed an error in the code, and I am in the process of correcting it...
Edit 2: Found the error and corrected it (not add null values to groups list)
For an Arcade solution I suggest you work with an object (or dictionary). See the code below:
function GetGroup(keyword) {
var dct_groups = {'Appliance Recycling': 'Air Conditioner;Appliance;Refrigerator;Dishwasher;Dryer;Oven;Stove;Washer;Water Heater',
'Asbestos Info / Removal Service': 'Asbestos',
'Automobile & Boat Reuse Recycling': 'Airplane; Automobile;Boat;Car;Recreation Vehicle;RV;Truck',
'Awards & Recognition': 'Awards (Eco-Award)',
'Batteries': 'Lead-Acid Batteries;Single Use AA, AAA, C, D, 9-Volt;Batteries - Rechargeable, BackUp;Lead-Acid Batteries;Rechargebale;Disposable Batteries;Rechargeable;Automotive Batteries;Boat Batteries;Lithium Batteries;Button Batteries',
'Bicycle Reuse Donation': 'Bicycles',
'Book Recycling': 'Books - Hardcover Recycling;Books - Softcover Recycling',
'Cellular Telephone Reuse & Recycling': 'Cell Phone - Retail Drop-Off;Cell Phone - Electronic Drop Off',
'Clean - Up Services': 'Clean-Up of Properties;',
'Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations': 'Clothing;Gym Shoes / Sneakers / HighTops;Linens / Blankets / Tableclothes / Towels;Textile / Fabrics / Drapes / Curtains;Shoes / Boots;Purse or Handbag',
'Commercial Hazardous Waste': 'Hazardous Waste Services;Chemical Business Waste',
'Composting Facilities/Landscape Waste transfer Stations': 'Composting Facilities/Landscape Waste transfer Stations;Landscape Material Recycling',
'Computer Reuse & Recycling': 'Business Electronic Devices',
'Construction & Demolition Recycling': 'Asphalt;Brick;Building Construction & Demolition Debris;Carpet;Carpet Padding;Concrete;Dirt;Drywall;Gravel;Padding;Roofing Materials;Shingles;Soil;Stone;Vinyl Siding;Windows;Wood-Untreated;Pallets',
'Cooking Oil/Grease Recycling & Trap Service': 'Cooking Oil;Grease Recycling;Grease Trap Services',
'Crayon Recycling': 'Crayons',
'Curbside Recycling': 'Aerosol Cans (empty) Curbside;Aluminum Can Curbside;Aluminum Foil Curbside;Cardboard & Chipboard Curbside;Curbside Recycling;Glass Bottles & Jars Curbside;Juice Boxes/Drink Pouches Curbside;Paper (magazines, phone bks, etc) Curbside;Plastic #1 (PET) & #2 (HDPE) Containers;Plastic #3, #4, #5, #7, Containers Curbside;Six-Pack Rings Curbside;Tin / Steel Cans (soup,cofffee, etc) Curbside',
'Demolition Material Recycling & Disposal': 'Construction Material Reuse;Demolition Material Reuse / Recycling',
'Disposable Batteries': 'Batteries - Single Use AA, AAA, C, D, 9-Volt',
'Donation': 'Books - Hardcover;Computer Reuse/Donation;Couch;Sofa;Toys',
'Drum & Cylinder Disposal or Recycling': 'Cylinders;Drums',
'Dry Cleaners (Green)': 'Dry Cleaning',
'Electronics': 'Adding Machines;Answering Machines;Calculators;Cameras;Cassettes;CB\'s/Two-way radios;CD Players / Laser Disc Players;CD ROM Drives;CDs, DVDs;Cell Phone - Electronic Drop-Off;Computer Recycling;Computer Recycling Drop-Off;Copy Machine;Cords & Cables;Digital Clocks;DVD Machine;Electronic Mice;Electronics;Fax Machines;Floppy Disks;Hand Held Games;Hard Drives;Joysticks/Game controls;Keyboards;Microwaves;Modems;Monitors;Pagers;Palm Organizers;Paper shredders;Portable Radio; Postage Machines;Printers;Scanner Machines;Speakers/Stereo Systems;String Lights / Holiday String Lights;Sump Pump;Tape Drives;Telephone;Televisions;Thermometers (digital);Typewriters/Word Processors;UPS Battery Backups;VCR Machine;VHS Tapes;Video Game Players; Zip Drives',
'Eye Glass Reuse': 'Eye Glasses',
'Fire Extinguisher Refilling or Recycling': 'Fire Extinguishers',
'Fluorescent Lights': 'CFLs;Compact Fluorescent Light Bulbs;Fluorescent Lights',
'Food Donation': 'Food Donation',
'Furniture & Office Equipment ': 'Book Cases;Cubical Walls;Desks;File Cabinets;Furniture & Office Equipment;Office Chairs',
'Geothermal Energy': 'Geothermal',
'Gift Cards': 'Gift Cards (merchant plastic money card)',
'Green Energy Supplier': 'Energy Supplier',
'Grocery Bag': 'Grocery Bags',
'Heating Oil Tank Removal': 'Heating Oil Tank Removal',
'Household Hazardous Waste (HHW)': 'Aerosol Products;Antifreeze;Automotive Batteries;Automotive Fluid;Boat Batteries;Button Batteries;Cleaning Chemicals;Compact Fluorescent Light Bulbs - HHW Drop-Off;Drain Cleaners;Driveway Sealer;Fertilizers;Fluorescent Light Bulbs;Gasoline-Oil Mix;Hazardous Household Materials;HHW;Household Chemicals;Lawn & garden chemicals;Lithium Batteries;Medication (old or unwanted);Mercury / Mercury Products;Motor Oil;Nail Polish Remover;Oil Filters;Oil-based Paint / Stain / Varnish;Old Gasoline;Paint Thinners;Pesticides;Pool Chemicals;Rechargeable Batteries;Solvents;Thermometers (glass);Used Oil;Medication (old or unwanted);Thermometers (glass);Cough Medicine;Inhalers;Medicated Shampoo;Ointment / Medicated Ointment;Over-the-Counter Medication;Pills, Pharmaceuticals, Medication;Prescription Medication;Sunscreen;Vitamins',
'Landfill & Transfer Stations': 'Landfills & Transfer Stations;Beverage Carrier Straps;Six-Pack Rings;Plastic #1, PET;Plastic #2, HDPE;Plastic #3, PVC;Plastic #4, LDPE;Plastic #5, PP;Plastic #7, Other Container;Aerosol Cans (empty) Drop-Off;Aluminum Can Recycling Drop-Off ;Aluminum Foil Recycling Drop-Off;Glass Bottles and Jars Drop-Off;Juice Boxes / Drink Pouches Drop-Off;Tin / Steel Cans (soup, coffee, etc) Drop-Off;',
'Latex Paint': 'Latex Paint',
'Lead-base Paint Concerns': 'Lead Paint',
'Manure': 'Manure',
'Matress Recycling': 'Matress & Box Springs',
'Medical Equipment (durable)': 'Canes;Crutches;Portable Toliets;Shower Chairs;Wheelchairs',
'Medication Drop-Off': 'Cough Medicine;Inhalers;Medicated Shampoo;Ointment / Medicated Ointment;Over-the-Counter Medication;Pills, Pharmaceuticals,Medication;Prescription Medication;Sunscreen;Vitamins',
'Metal Recycling': 'Scrap Metal;Aluminum / Aluminum Can Scrap;Brass;Copper;Iron;Steel Scrap;',
'Motor Oil - Bulk': 'Motor Oil in Buk Drums',
'Motor Oil Recycling (DIY)': 'Motor Oil - DIY',
'Packaging Materials': 'Packing Peanut ;Styrofoam Peanuts;Cardboard Boxes',
'Pallet Reuse or Recycling': 'Pallets',
'Paper Recycling': 'Cardboard;Chipboard;Colored Paper;Construction Paper;Junk Mail;Magazines;Newspaper;Office Paper;Paper Recycling;Shredding Services;Clored Paper',
'Plastic Carrier Strap Recycling': 'Beverage Carrier Straps;Six-Pack Rings',
'Plastic Container Recycling': 'Plastic #1, PET;Plastic #2, HDPE;Plastic #3 PVC;Plastic #4, LDPE;Plastic #5, PP;Plastic #7, Other Container',
'Pop-Tab Recycling': 'Pop-Tab',
'Printer/Toner Cartridge & Ribbon Recycling': 'Inkjets (Ribbons);Printer/Toner Cartridges',
'Propane Tank Disposal or Recycling': 'Propane Tanks',
'Rechargeable Battery': 'Batteries - Rechargeable, BackUp, Lead-Acid;Rechargeable',
'Recycling and Waste Collection Companies': 'Recycling Collection Company;Garbage Collection Company;Waste Collection Company',
'Repair Services': 'Sharpening Services',
'Reuse & Resale Shops': 'Reuse/Resale',
'Smoke Detectors ': 'Smoke Detectors ',
'Solar Energy': 'Solar Energy',
'Styrofoam or Polystyrene Recycling': 'Plastic #6, PS, Polystyrene;Styrofoam',
'Tire Recycling': 'Tire',
'Water Conservation': 'Rain Barrels;Rain Garden',
'Wind Energy': 'Small Wind'}
for (var group in dct_groups) {
var keywords = dct_groups[group];
if (Find(keyword, keywords)>-1) {
return group;
}
}
return null;
}
//var test = "Automobile and Boat Reuse Recycling;Batteries;";
var test = "Bicycles;Clothing;Gym Shoes / Sneakers / HighTops;Linens / Blankets / Tableclothes / Towels;Purse or Handbag;Shoes / Boots;Textiles / Fabrics / Drapes / Curtains;Books - Hardcover;Couch;Sofa;Toys;Book Cases;Desks;File Cabinets;";
var lst = Split(test, ";");
var groups = [];
for (var i in lst) {
Console(i)
var kw = lst[i];
if (!IsEmpty(kw)) {
Console(" - kw:" + kw);
var group = GetGroup(kw);
if (!IsEmpty(group)) {
Console(" - group:" + group);
groups[Count(groups)] = group;
}
} else {
Console(" - item is empty");
}
}
Console("groups:" + groups);
if (Count(groups) > 0) {
var distinct_groups = Distinct(groups);
Console("distinct_groups:" + distinct_groups);
}
var dct_groups = {};
for (var i in groups) {
var group = groups[i];
if (HasKey(dct_groups, group)) {
dct_groups[group] += 1;
} else {
dct_groups[group] = 1;
}
}
Console("dct_groups:" + dct_groups);
var cntmax = 0;
var finalgroup = "";
for (var group in dct_groups) {
var cnt = dct_groups[group];
if (cnt > cntmax) {
finalgroup = group;
cntmax = cnt;
}
}
Console("finalgroup: " + finalgroup);
return finalgroup;
With a random test value of (see line 79):
"Bicycles;Clothing;Gym Shoes / Sneakers / HighTops;Linens / Blankets / Tableclothes / Towels;Purse or Handbag;Shoes / Boots;Textiles / Fabrics / Drapes / Curtains;Books - Hardcover;Couch;Sofa;Toys;Book Cases;Desks;File Cabinets;"
It writes to the Console:
0
- kw:Bicycles
- group:Bicycle Reuse Donation
1
- kw:Clothing
- group:Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations
2
- kw:Gym Shoes / Sneakers / HighTops
- group:Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations
3
- kw:Linens / Blankets / Tableclothes / Towels
4
- kw:Purse or Handbag
- group:Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations
5
- kw:Shoes / Boots
- group:Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations
6
- kw:Textiles / Fabrics / Drapes / Curtains
7
- kw:Books - Hardcover
- group:Book Recycling
8
- kw:Couch
- group:Donation
9
- kw:Sofa
- group:Donation
10
- kw:Toys
- group:Donation
11
- kw:Book Cases
- group:Furniture & Office Equipment
12
- kw:Desks
- group:Furniture & Office Equipment
13
- kw:File Cabinets
- group:Furniture & Office Equipment
14
- item is empty
groups:["Bicycle Reuse Donation","Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations","Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations","Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations","Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations","Book Recycling","Donation","Donation","Donation","Furniture & Office Equipment ","Furniture & Office Equipment ","Furniture & Office Equipment "]
distinct_groups:["Bicycle Reuse Donation","Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations","Book Recycling","Donation","Furniture & Office Equipment "]
dct_groups:{"Bicycle Reuse Donation":1,"Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations":4,"Book Recycling":1,"Donation":3,"Furniture & Office Equipment ":3}
finalgroup: Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations
And now we see something interesting. There are multiple groups returned and since the one that occurs most is "Clothing, Lines...." this is the one that is assigned. However, this poses a question. Should this occur?
Hi jpilbeam ,
I also notice that some of the keywords like "Textiles / Fabrics / Drapes / Curtains" are not found in the final groups. Is that correct? Should the words "Textiles", "Fabrics", etc be evaluated separately?
I wouldn't worry about those keywords. I must've left them out when re-doing the finalgroups.csv. I'll come back for those later.
Thanks for the code! But, I'm a little confused as to what I'm supposed to use in the Expression Builder in Pro. Am I to use the whole thing or just certain bits?