MCPcopy Create free account
hub / github.com/SamuelSchmidgall/AgentLaboratory / strip_string

Function strip_string

utils.py:414–480  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

412
413
414def strip_string(string):
415 # linebreaks
416 string = string.replace("\n", "")
417
418 # remove inverse spaces
419 string = string.replace("\\!", "")
420
421 # replace \\ with \
422 string = string.replace("\\\\", "\\")
423
424 # replace tfrac and dfrac with frac
425 string = string.replace("tfrac", "frac")
426 string = string.replace("dfrac", "frac")
427
428 # remove \left and \right
429 string = string.replace("\\left", "")
430 string = string.replace("\\right", "")
431
432 # Remove circ (degrees)
433 string = string.replace("^{\\circ}", "")
434 string = string.replace("^\\circ", "")
435
436 # remove dollar signs
437 string = string.replace("\\$", "")
438
439 # remove units (on the right)
440 string = remove_right_units(string)
441
442 # remove percentage
443 string = string.replace("\\%", "")
444 string = string.replace("\%", "") # noqa: W605
445
446 # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
447 string = string.replace(" .", " 0.")
448 string = string.replace("{.", "{0.")
449 # if empty, return empty string
450 if len(string) == 0:
451 return string
452 if string[0] == ".":
453 string = "0" + string
454
455 # to consider: get rid of e.g. "k = " or "q = " at beginning
456 if len(string.split("=")) == 2:
457 if len(string.split("=")[0]) <= 2:
458 string = string.split("=")[1]
459
460 # fix sqrt3 --> sqrt{3}
461 string = fix_sqrt(string)
462
463 # remove spaces
464 string = string.replace(" ", "")
465
466 # \frac1b or \frac12 --> \frac{1}{b} and \frac{1}{2}, etc. Even works with \frac1{72} (but not \frac{72}1). Also does a/b --> \\frac{a}{b}
467 string = fix_fracs(string)
468
469 # manually change 0.5 --> \frac{1}{2}
470 if string == "0.5":
471 string = "\\frac{1}{2}"

Callers 1

is_equivFunction · 0.85

Calls 4

remove_right_unitsFunction · 0.85
fix_sqrtFunction · 0.85
fix_fracsFunction · 0.85
fix_a_slash_bFunction · 0.85

Tested by

no test coverage detected