yojimbos_law icon

horrible file parsing for modifier names.

yojimbos_law | PRO | 06/26/19 09:03:14 PM UTC | 0 ⭐ | 517 👁️ | Never ⏰ | []
text |

3.42 KB

|

None

|

0 👍

/

0 👎

string[int] mods = file_to_array("data/tcrs numeric modifiers.txt");
string[int] items_with_mod;
string[string] names_of_mods;
string[int][int] files;
for i from 1 to 6{
	files[i] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Mongoose.txt");
	files[i+6] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Wallaby.txt");
	files[i+12] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Vole.txt");
	files[i+18] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Platypus.txt");
	files[i+24] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Marmot.txt");
	files[i+30] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Opossum.txt");
}
int county_thing;
slot some_buffer_item_slot;
boolean see_above;
string intersection;
string[int] intersection_words;
boolean[int] intersection_boolean;
foreach i in mods{
	clear(items_with_mod);
	county_thing = 0;
	//make a big list of item tcrsnames containing that modifier's name. We don't need all of them, just a bunch.
	for j from 1 to 36{
		foreach k in files[j]{
			//select lines where item's string modifier is precisely the current modifier.
			if(files[j][k].group_string("\\t([^\\t]*)$")[0][1]  == mods[i] ){
				//reduce that to lines corresponding to equipment that goes into non-bullshit slots
				some_buffer_item_slot = files[j][k].group_string("^(\\d)+\\t")[0][1].to_int().to_item().to_slot();
				see_above = false;
				foreach asdf in $slots[acc1,weapon,pants]{
					if(asdf == some_buffer_item_slot){
						see_above = true;
					}
				}
				if(see_above){
					//if modifiers contains a comma, we should probably exclude the item.
					//you know, for reasons.
					if(!(files[j][k].group_string("^(\\d)+\\t")[0][1].to_int().to_item().string_modifier("Modifiers").contains_text(","))){
						county_thing++;
						//grab item's tcrsname.
						items_with_mod[county_thing] = files[j][k].group_string("^\\d+\\t([^\\t]*)\\t")[0][1];
					}
				}
			}
		}
	}
	//arbitrarily choose an item name from list to be the start of our intersection.
	intersection_words = items_with_mod[1].split_string(" ");
	//print(intersection_words[1]);
 	int[string][int] counting_words;
	foreach j in items_with_mod{
		foreach k in items_with_mod[j].split_string(" "){
			foreach asdf in intersection_words{
				if( intersection_words[asdf] == items_with_mod[j].split_string(" ")[k] ){
					counting_words[intersection_words[asdf]][asdf]++;
				}
			}
		}
	}
	clear(intersection_words);
	county_thing = 0;
	foreach j,k in counting_words{
		if(counting_words[j][k] * 2 > count(items_with_mod)){
			intersection_words[county_thing] = j;
			county_thing++;
		}
	}
	//get rid of all duplicate words
	foreach j in intersection_words{
		foreach k in intersection_words{
			if(intersection_words[j].length() > 0 && j < k && intersection_words[j] == intersection_words[k]){
				intersection_words[k] = "";
			}
		}
	}
	//put the words together.
	intersection = "";
	foreach j in intersection_words{
		if(intersection_words[j].length() > 0){
			intersection += intersection_words[j] +" ";
		}
	}
	//trim single trailing whitespace guaranteed to result from above process
	intersection = intersection.group_string("^(.*)\\s$")[0][1];
	names_of_mods[mods[i]] = intersection;
	print(intersection);
}
 map_to_file(names_of_mods, "tcrs modifier name correspondence");

Comments