Advertisement
yojimbos_law

horrible file parsing for modifier names.

Jun 26th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. string[int] mods = file_to_array("data/tcrs numeric modifiers.txt");
  2. string[int] items_with_mod;
  3. string[string] names_of_mods;
  4. string[int][int] files;
  5. for i from 1 to 6{
  6. files[i] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Mongoose.txt");
  7. files[i+6] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Wallaby.txt");
  8. files[i+12] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Vole.txt");
  9. files[i+18] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Platypus.txt");
  10. files[i+24] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Marmot.txt");
  11. files[i+30] = file_to_array("data/TCRS_"+(i.to_class().replace_string(" ","_"))+"_Opossum.txt");
  12. }
  13. int county_thing;
  14. slot some_buffer_item_slot;
  15. boolean see_above;
  16. string intersection;
  17. string[int] intersection_words;
  18. boolean[int] intersection_boolean;
  19. foreach i in mods{
  20. clear(items_with_mod);
  21. county_thing = 0;
  22. //make a big list of item tcrsnames containing that modifier's name. We don't need all of them, just a bunch.
  23. for j from 1 to 36{
  24. foreach k in files[j]{
  25. //select lines where item's string modifier is precisely the current modifier.
  26. if(files[j][k].group_string("\\t([^\\t]*)$")[0][1] == mods[i] ){
  27. //reduce that to lines corresponding to equipment that goes into non-bullshit slots
  28. some_buffer_item_slot = files[j][k].group_string("^(\\d)+\\t")[0][1].to_int().to_item().to_slot();
  29. see_above = false;
  30. foreach asdf in $slots[acc1,weapon,pants]{
  31. if(asdf == some_buffer_item_slot){
  32. see_above = true;
  33. }
  34. }
  35. if(see_above){
  36. //if modifiers contains a comma, we should probably exclude the item.
  37. //you know, for reasons.
  38. if(!(files[j][k].group_string("^(\\d)+\\t")[0][1].to_int().to_item().string_modifier("Modifiers").contains_text(","))){
  39. county_thing++;
  40. //grab item's tcrsname.
  41. items_with_mod[county_thing] = files[j][k].group_string("^\\d+\\t([^\\t]*)\\t")[0][1];
  42. }
  43. }
  44. }
  45. }
  46. }
  47. //arbitrarily choose an item name from list to be the start of our intersection.
  48. intersection_words = items_with_mod[1].split_string(" ");
  49. //print(intersection_words[1]);
  50.  
  51. int[string][int] counting_words;
  52. foreach j in items_with_mod{
  53. foreach k in items_with_mod[j].split_string(" "){
  54. foreach asdf in intersection_words{
  55. if( intersection_words[asdf] == items_with_mod[j].split_string(" ")[k] ){
  56. counting_words[intersection_words[asdf]][asdf]++;
  57. }
  58. }
  59. }
  60. }
  61. clear(intersection_words);
  62. county_thing = 0;
  63. foreach j,k in counting_words{
  64. if(counting_words[j][k] * 2 > count(items_with_mod)){
  65. intersection_words[county_thing] = j;
  66. county_thing++;
  67. }
  68. }
  69. //get rid of all duplicate words
  70. foreach j in intersection_words{
  71. foreach k in intersection_words{
  72. if(intersection_words[j].length() > 0 && j < k && intersection_words[j] == intersection_words[k]){
  73. intersection_words[k] = "";
  74. }
  75. }
  76. }
  77. //put the words together.
  78. intersection = "";
  79. foreach j in intersection_words{
  80. if(intersection_words[j].length() > 0){
  81. intersection += intersection_words[j] +" ";
  82. }
  83. }
  84. //trim single trailing whitespace guaranteed to result from above process
  85. intersection = intersection.group_string("^(.*)\\s$")[0][1];
  86. names_of_mods[mods[i]] = intersection;
  87. print(intersection);
  88. }
  89.  
  90. map_to_file(names_of_mods, "tcrs modifier name correspondence");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement