update-math-words
#3
by ikarasz - opened
Files changed (3)
- handler.py+68-64
- requirements.txt+1
- utils.py+513-410
1234563 unmodified lines101112121314151678 unmodified lines95969797989910051 unmodified lines15215315415515515615715615715815916016116216016116216316416516616716816917017117217317416316416516616716816917017117217317417517617717817918018118218318418518618718818919017617717817918018118218318418518618718818919019119219319119219322 unmodified lines21621721822221922022134 unmodified lines25625725826325926026127 unmodified lines28929029129729229329472 unmodified lines3673683693703713723733743753763773783793803813823833843803813823833843853863873883893901 unmodified line3923933943953963973983993974004014024034044024054064073 unmodified lines411412413412413414414415416417416418418419420419420421422423424424425426427428429430431425426427428429430431432433434435436437435438439440441442from typing import Dict, List, Anyfrom scipy.special import softmaxfrom collections import Counterimport numpy as npimport weakrefimport re3 unmodified lines
from utils import clean_str, clean_str_nopunctimport torchfrom utils import MultiHeadModel, BertInputBuilder, get_num_words, MATH_PREFIXES, MATH_WORDSfrom utils import MultiHeadModel, BertInputBuilder, get_num_words, MATH_PREFIXES, MATH_WORDS, plural_to_singular
import transformersfrom transformers import BertTokenizer, BertForSequenceClassification78 unmodified lines f"text='{self.text}', uid={self.uid}," \ f"starttime={self.starttime}, endtime={self.endtime}, props={self.props})"
class Transcript: def __init__(self, **kwargs): self.utterances = []51 unmodified lines return {'teacher': teacher_percentage, 'student': student_percentage}, {'teacher': avg_teacher_length, 'student': avg_student_length}
def get_word_clouds(self): # Initialize dictionaries teacher_dict = {} student_dict = {} uptake_teacher_dict = {} teacher_dict = Counter() student_dict = Counter() uptake_teacher_dict = Counter() stop_words = stopwords.words('english')
# Go through the utterances for utt in self.utterances: words = (utt.get_clean_text(remove_punct=True)).split(' ') for word in words: if word in stop_words or word in ['inaudible', 'crosstalk']: continue # handle uptake case if utt.role == 'teacher': if utt.uptake == 1: if word not in uptake_teacher_dict: uptake_teacher_dict[word] = 0 uptake_teacher_dict[word] += 1 # ignore math words so they don't get tagged as general if any(math_word in word for math_word in utt.math_terms): continue if utt.role == 'teacher': if word not in teacher_dict: teacher_dict[word] = 0 teacher_dict[word] += 1 # Get clean text clean_text = utt.get_clean_text(remove_punct=True) words = clean_text.split() words = [word for word in words if word not in stop_words and word not in ['inaudible', 'crosstalk']]
# Handle uptake case if utt.role == 'teacher' and utt.uptake == 1: uptake_teacher_dict.update(words)
general_text = ' '.join(words) # Replace math terms with empty strings for math_term in utt.math_terms: general_text = general_text.replace(math_term, '') general_text = general_text.replace(' ', ' ')
general_words = general_text.split() # Update the appropriate dictionary if utt.role == 'teacher': teacher_dict.update(general_words) else: student_dict.update(general_words)
# Sorting and trimming dictionaries dict_list = dict_to_list(teacher_dict, 'general') + dict_to_list(student_dict, 'general') uptake_dict_list = dict_to_list(uptake_teacher_dict, 'teacher') teacher_dict_list = dict_to_list(teacher_dict, 'general') student_dict_list = dict_to_list(student_dict, 'general')
else: if word not in student_dict: student_dict[word] = 0 student_dict[word] += 1 dict_list = [] uptake_dict_list = [] teacher_dict_list = [] student_dict_list = [] for word in uptake_teacher_dict.keys(): uptake_dict_list.append({'text': word, 'value': uptake_teacher_dict[word], 'category': 'teacher'}) for word in teacher_dict.keys(): teacher_dict_list.append( {'text': word, 'value': teacher_dict[word], 'category': 'general'}) dict_list.append({'text': word, 'value': teacher_dict[word], 'category': 'general'}) for word in student_dict.keys(): student_dict_list.append( {'text': word, 'value': student_dict[word], 'category': 'general'}) dict_list.append({'text': word, 'value': student_dict[word], 'category': 'general'}) sorted_dict_list = sorted(dict_list, key=lambda x: x['value'], reverse=True) sorted_uptake_dict_list = sorted(uptake_dict_list, key=lambda x: x['value'], reverse=True) sorted_teacher_dict_list = sorted(teacher_dict_list, key=lambda x: x['value'], reverse=True)22 unmodified lines def __repr__(self): return f"Transcript(utterances={self.utterances}, custom_params={self.params})"
class QuestionModel: def __init__(self, device, tokenizer, input_builder, max_length=300, path=QUESTION_MODEL): print("Loading models...")34 unmodified lines return_pooler_output=False) return output
class ReasoningModel: def __init__(self, device, tokenizer, input_builder, max_length=128, path=REASONING_MODEL): print("Loading models...")27 unmodified lines token_type_ids=instance["token_type_ids"]) return output
class UptakeModel: def __init__(self, device, tokenizer, input_builder, max_length=120, path=UPTAKE_MODEL): print("Loading models...")72 unmodified lines token_type_ids=instance["token_type_ids"]) return output
def dict_to_list(d, category): combined_dict = Counter() for word, count in d.items(): singular_word = plural_to_singular(word) combined_dict[singular_word] += count return [{'text': word, 'value': count, 'category': category} for word, count in combined_dict.items()]
def load_math_terms(): math_regexes = [] math_terms_dict = {} for term in MATH_PREFIXES: math_terms_dict[rf"\b{term}(s|es|d|ed)?\b"] = term math_regexes.append(rf"\b{term}(s|es|d|ed)?\b")
for term in MATH_WORDS: if term in MATH_PREFIXES: math_terms_dict[rf"\b{term}(s|es|d|ed)?\b"] = term math_regexes.append(rf"\b{term}(s|es|d|ed)?\b") else: math_regexes.append(rf"\b{term}\b") if not term in MATH_PREFIXES: math_terms_dict[rf"\b{term}\b"] = term math_regexes.append(rf"\b{term}\b") return math_regexes, math_terms_dict
def run_math_density(transcript):1 unmodified line sorted_regexes = sorted(math_regexes, key=len, reverse=True) teacher_math_word_cloud = {} student_math_word_cloud = {}
for i, utt in enumerate(transcript.utterances): text = utt.get_clean_text(remove_punct=True) num_matches = 0 matched_positions = set() match_list = [] match_list = set() for regex in sorted_regexes: matches = list(re.finditer(regex, text, re.IGNORECASE)) # Filter out matches that share positions with longer terms matches = [match for match in matches if not any(match.start() in range(existing[0], existing[1]) for existing in matched_positions)] # matched_text = [match.group(0) for match in matches] if len(matches) > 0: if utt.role == "teacher": if math_terms_dict[regex] not in teacher_math_word_cloud:3 unmodified lines if math_terms_dict[regex] not in student_math_word_cloud: student_math_word_cloud[math_terms_dict[regex]] = 0 student_math_word_cloud[math_terms_dict[regex]] += len(matches) match_list.append(math_terms_dict[regex]) # Update matched positions matched_positions.update((match.start(), match.end()) for match in matches) for match in matches: match_list.add(match.group()) matched_positions.add((match.start(), match.end())) num_matches += len(matches) # print("match group list: ", [match.group(0) for match in matches]) utt.num_math_terms = num_matches utt.math_terms = match_list # utt.math_match_positions = list(matched_positions) # utt.math_terms_raw = [text[start:end] for start, end in matched_positions] utt.math_terms = list(match_list)
# Initialize lists teacher_dict_list = [] student_dict_list = [] dict_list = [] for word in teacher_math_word_cloud.keys(): teacher_dict_list.append( {'text': word, 'value': teacher_math_word_cloud[word], 'category': "math"}) dict_list.append({'text': word, 'value': teacher_math_word_cloud[word], 'category': "math"}) for word in student_math_word_cloud.keys(): student_dict_list.append( {'text': word, 'value': student_math_word_cloud[word], 'category': "math"}) dict_list.append({'text': word, 'value': student_math_word_cloud[word], 'category': "math"})
# Process teacher_math_word_cloud teacher_dict_list = dict_to_list(teacher_math_word_cloud, 'math') dict_list.extend(teacher_dict_list)
# Process student_math_word_cloud student_dict_list = dict_to_list(student_math_word_cloud, 'math') dict_list.extend(student_dict_list)
# Sort the lists sorted_dict_list = sorted(dict_list, key=lambda x: x['value'], reverse=True) sorted_teacher_dict_list = sorted(teacher_dict_list, key=lambda x: x['value'], reverse=True) sorted_student_dict_list = sorted(student_dict_list, key=lambda x: x['value'], reverse=True) # return sorted_dict_list[:50]
# Return the sorted lists return sorted_dict_list[:50], sorted_teacher_dict_list[:50], sorted_student_dict_list[:50]
class EndpointHandler():4 unmodified lines56784 unmodified linestorch==2.3.1transformers==4.46.1nltk==3.9.1inflect==7.5.06 unmodified lines7891011121321 unmodified lines353637373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169394017117217317417517617717817918018118218318418518618718841424344454647481901911921931941951961971981992002012022032042052062072082092102114950515221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629753545556575859606162636465666768697071727374757677787980818283305848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452463593603612472482492502512522532543632552562572582592602612622632642652662673673682682692702712722732742752762773722782792802813752822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413953423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484404494504514524534544554564574584424594604614624634644654664674684694704714724734744754764774784794804814824834844854864874554884894904914924934944954964974984995005015025035045055065075085094685105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415424845435445455465475485495505515525535545555565575585595605615625635645655664945675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736745376756766776786796806816825416836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217225567237247257267277287297307317327337347357367377387397407417421 unmodified line7447457467477487497507517527537547557567577587597605735745757617627637647657667677687697707717727737747757767777787797807817827837847857867877887895815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116127906146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956967917927937947957966997977987998008018027038038047057067077087097107117127137147157167177188058068078088098108118128138148158168178188198208218228238248258266 unmodified linesfrom num2words import num2wordsimport reimport stringimport inflect
punct_chars = list((set(string.punctuation) | {'’', '‘', '–', '—', '~', '|', '“', '”', '…', "'", "`", '_'}))punct_chars.sort()21 unmodified lines "median", "ratio", "area",]
MATH_WORDS = [ "absolute value", "algebra", "area", "average", "base of", "box plot", "categorical", "coefficient", "common factor", "common multiple", "compose", "coordinate", "cubed", "decompose", "dependent variable", "distribution", "dot plot", "double number line diagram", "equivalent", "equivalent expression", "ratio", "exponent", "frequency", "greatest common factor", "gcd", "height of", "histogram", "independent variable", "integer", "interquartile range", "iqr", "least common multiple", "long division", "mean absolute deviation", "median", "negative number", "opposite vertex", "parallelogram", "percent", "polygon", "polyhedron", "positive number", "prism", "pyramid", "quadrant", "quadrilateral", "quartile", "rational number", "reciprocal", "equality", "inequality", "squared", "statistic", "surface area", "identity property", "addend", "unit", "number sentence", "make ten", "take from ten", "number bond", "total", "estimate", "hashmark", "meter", "number line", "ruler", "centimeter", "base ten", "expanded form", "hundred", "thousand", "place value", "number disk", "standard form", "unit form", "word form", "tens place", "algorithm", "equation", "simplif", "addition", "subtract", "array", "even number", "odd number", "repeated addition", "tessellat", "whole number", "number path", "rectangle", "square", "bar graph", "data", "degree", "line plot", "picture graph", "scale", "survey", "thermometer", "estimat", "tape diagram", "value", "analog", "angle", "parallel", "partition", "pentagon", "right angle", "cube", "digital", "quarter of", "tangram", "circle", "hexagon", "half circle", "half-circle", "quarter circle", "quarter-circle", "semicircle", "semi-circle", "rectang", "rhombus", "trapezoid", "triangle", "commutative", "equal group", "distributive", "divide", "division", # added "multipl", "parentheses", "quotient", "rotate", "unknown", "add", "capacity", "continuous", "endpoint", "gram", "interval", "kilogram", "volume", "liter", "milliliter", "approximate", "area model", "square unit", "unit square", "divid", "subtrac", "logarit", "algebr", "calcul", "matri", "vect", "geometr", "equivalent fraction", "fraction form", "fractional unit", "unit fraction", "unit interval", "measur", "graph", "scaled graph", "diagonal", "perimeter", "regular polygon", "tessellate", "tetromino", "heptagon", "octagon", "digit", "expression", "sum", "kilometer", "mass", "mixed unit", "length", "statist", "probabli", "coeffi", "measure", "simplify", "associative", "composite", "divisible", "divisor", "partial product", "prime number", "remainder", "acute", "arc", "collinear", "equilateral", "intersect", "isosceles", "symmetry", "line segment", "line", "obtuse", "perpendicular", "protractor", "scalene", "straight angle", "supplementary angle", "vertex", "common denominator", "denominator", "fraction", "mixed number", "numerator", "whole", "decimal expanded form", "decimal", "hundredth", "tenth", "customary system of measurement", "customary unit", "gallon", "metric", "metric unit", "ounce", "pint", "quart", "convert", "distance", "millimeter", "thousandth", "hundredths", "conversion factor", "decimal fraction", "multiplier", "equivalence", "multiple", "product", "benchmark fraction", "cup", "pound", "yard", "whole unit", "decimal divisor", "factors", "bisect", "cubic units", "hierarchy", "unit cube", "attribute", "kite", "bisector", "solid figure", "square units", "dimension", "axis", "ordered pair", "angle measure", "horizontal", "vertical", "categorical data", "lcm", "measure of center", "meters per second", "numerical", "solution", "unit price", "unit rate", "variability", "variable", "simplif"]
MATH_WORDS = [ "absolute deviation", "absolute value", "abundant number", "accurate", "acre", "acute", "add", "addend", "addition fact", "addition", "additive identity", "additive inverse", "adjacent", "algebra", "algebraic", "algorithm", "alternate interior angle", "altitude", "analog", "angle measure", "angle", "angular", "apex", "approximate", "arc", "area model", "area", "arithmetic facts", "arithmetic fact", "arithmetic", "array", "associative property", "associative", "astronomical unit", "attribute", "average", "axis", "bar graph", "base of a parallelogram", "base of a prism", "base of a pyramid", "base of a triangle", "base of an exponent", "base of", "base ten", "base", "baseline", "benchmark fraction", "billion", "binomial", "bisect", "bisector", "box and whisker plot", "box plot", "capacity", "cartesian coordinate", "categorical data", "categorical", "celsius", "census", "cent", "center of a circle", "center of a dilation", "center of a sphere", "center", "centimeter", "central angle", "centroid", "chance experiment", "chance", "chord", "circle graph", "circle", "circular", "circumference", "clockwise", "coefficient", "collinear", "column matrix" "column", "combination", "combine", "common denominator", "common factor", "common fraction", "common multiple", "commutative property", "commutative", "comparison diagram", "comparison story", "compass", "complement", "complementary", "compose", "composite", "concave polygon", "concentric circles", "concentric", "cone", "congruent", "consecutive", "constant function", "constant", "continuous model of area", "continuous model of volume", "continuous", "contour", "conversion fact", "conversion factor", "convert", "convex function", "convex polygon", "coordinate", "coplanar", "corresponding", "counterclockwise", "counting numbers", "counting up subtraction", "covariance", "covariate", "cover-up method", "cross multiplication", "cross product", "cross section", "cross-section", "cube root", "cube", "cubed", "cubic unit", "cubic", "cubit", "cup", "curved surface", "customary system of measurement", "customary unit", "cylinder", "cylindrical", "data", "decagon", "decimal divisor", "decimal expanded form", "decimal fraction", "decimal point", "decimal", "decimeter", "decompose", "deficient number", "degree", "delta", "denominator", "density", "dependent event", "dependent variable", "deposit", "derivative", "determinant", "diagonal", "diameter", "difference", "differential" "digit", "digital", "dilation", "dimension", "discrete model", "displacement method", "distance", "distribution", "distributive", "divide", "dividend", "divisibility test", "divisible by", "divisible", "division", "divisor", "dodecahedron", "dot plot", "double number line diagram", "double stem plot", "doubles fact", "edge", "egyptian multiplication", "elevation", "embed figure", "end point", "endpoint", "enlarge", "equal group", "equal part", "equal", "equal groups", "equal parts", "equidistant marks", "equality", "equation", "equidistant mark", "equilateral polygon", "equilateral triangle", "equilateral", "equivalence", "equivalent expression", "equivalent fractions", "equivalent fraction", "equivalent", "error bound", "error of measurement", "estimat", "estimate", "european subtraction", "even number", "event", "expand", "expanded form", "expanded notation", "expected outcome", "exponential", "extended facts", "expected value", "exponent", "exponential function", "exponential growth", "expression", "extended fact", "face", "fact power", "fact triangle", "factor", "factors of numbers", "factorial", "factors of number", "fahrenheit", "false number sentence", "figurate numbers", "figurate number", "flowchart", "fluid ounce", "formula", "fraction form", "fraction", "fractional part", "fractional unit", "frequency", "fulcrum", "function machine", "function", "furlong", "gallon", "gcd", "genus", "geoboard", "geometr", "geometric solid", "geometry template", "girth", "golden ratio", "golden rectangle", "gram", "graph key", "graph", "greatest common divisor" "greatest common factor", "grouping symbol", "half circle", "half-circle", "hashmark", "height of a parallelogram or triangle", "height of", "height", "hemisphere", "heptagon", "heptagonal", "hexagon", "hexagonal", "hierarchy", "histogram", "horizontal shift", "horizontal stretch", "horizontal", "hundred", "hundredth", "hypotenuse", "hypothesis", "icosahedron", "identity function", "identity matrix", "identity property of", "identity property", "improper fraction", "inch", "incircle", "indefinite integral", "independent event", "independent variable", "index of locations", "index of location", "indirect measurement", "inequality", "infinity", "input", "inscribed angle", "inscribed polygon", "instance of a pattern", "integer", "intercept", "intercepted arc", "interior angle", "interior of a figure", "interpolate", "interquartile range", "intersect", "interval", "inverse operation", "inverse", "iqr", "irrational number", "irrational root", "irrational", "isometry transformation", "isosceles trapezoid", "isosceles triangle", "isosceles", "joint probability", "joint variation", "juxtapose", "key sequence", "kilogram", "kilometer", "kite", "label", "landmark", "latitude", "lattice multiplication", "lcm", "least common denominator", "least common multiple", "left to right subtraction", "leg of a right triangle", "legs", "length", "like fraction", "like terms", "line graph", "line of reflection", "line of symmetry", "line plot", "line segment", "line symmetry", "line", "linear relationship", "lines of latitude", "lines of longitude", "liter", "local maximum", "local minimum", "locus", "logarithm", "logarithmic function", "logarithmic scale", "logic", "long division", "longitude", "lowest term", "magnitude estimate", "make ten", "map legend", "map scale", "mass", "maximum", "mean absolute deviation", "mean value", "mean", "measure of center", "measure", "measurement division", "measurement error", "measurement unit", "median", "meridian bar", "meter", "meters per second", "metric system", "metric unit", "metric", "midpoint", "mile", "milliliter", "millimeter", "millisecond", "minimum", "minuend", "mirror image", "mixed number", "mixed unit", "mobius", "modal", "mode", "multipl", "multiple", "multiplication counting principle", "multiplication diagram", "multiplication fact", "multiplication symbols", "multiplication symbol", "multiplication use class", "multiplicative identity", "multiplicative inverse", "multiplier", "mutually exclusive event", "natural number", "negative association", "negative exponent", "negative number", "negative rational numbers", "negative rational number", "nested parentheses", "net score", "net weight", "net", "nonagon", "nonconvex polygon", "nonlinear", "normal distribution", "normal span", "normal", "number bond", "number disk", "number grid", "number line", "number path", "number sentence", "number sequence", "numeral", "numeration", "numerator", "numerical data", "numerical", "obtuse", "octagon", "octagonal", "octahedron", "odd number", "open proportion", "operation", "operation symbol", "operational", "opposite angle", "opposite change rule", "opposite of a number", "opposite side", "opposite vertex", "opposite", "order of magnitude", "order of operations", "order of rotation symmetry", "order of", "ordered pair", "ordered", "ordinal number", "orthogonal", "ounce", "outlier", "pace", "pan balance", "parabola", "parallel lines", "parallel planes", "parallel plane", "parallel", "parallelogram", "parentheses", "part to part ratio", "part to whole ratio", "part whole fraction", "partial differences subtraction", "partial product", "partial products multiplication", "partial quotients division", "partial sums addition", "partition", "partitive division", "parts and total diagram", "pentagon", "pentagonal", "per capita", "per unit rate", "per", "percent circle", "percent", "percentage", "perfect number", "perfect square", "perfect triangle", "perimeter", "permutation", "perpendicular", "perpetual calendar", "pi", "picture graph", "pie graph", "plane", "pint", "pivot", "place value", "plane figure", "plane", "point symmetry", "point", "polar coordinate", "polygon", "polyhedron", "polynominal" "population density", "population", "positive association", "positive number", "pound", "power", "precise", "predict", "prediction line", "preimage", "prime factor", "prime factorization", "prime meridian", "probability", "prime number", "prism", "probability meter", "probability tree diagram", "probability", "product", "proper factor", "proper fraction", "property", "proportion", "proportional", "proportionality", "protractor", "pyramid", "pythagorean theorem", "quadrangle", "quadrant", "quadratic", "quadrilateral", "quart", "quarter circle", "quarter of", "quarter-circle", "quartile", "quick common denominator", "quotient", "quotitive division", "radian", "radius of" "radius", "random draw", "random experiment", "random number", "random sample", "random", "range", "rank", "rate diagram", "rate multiplication ", "rate of change", "rate unit", "rate", "ratio of", "ratio", "rational equation", "rational number", "ray", "real number", "recall survey", "reciprocal", "rectang", "rectangle", "rectangular array", "rectangular coordinate grid", "rectangular prism", "rectangular pyramid", "rectangular", "rectilinear figure", "reflection", "reflex angle", "region", "regular polygon", "regular polyhedron", "regular tessellation", "relation symbol", "relative frequency", "remainder", "repeated addition", "repeating decimal", "representative", "revolution", "rhombus", "right angle", "right cone", "right cylinder", "right prism", "right pyramid", "right triangle", "rigid transformation", "roman numerals", "root", "rotate", "rotation symmetry", "rotation", "round off", "round-off", "ruler", "same change rule for subtraction", "sample", "scalar", "scale factor", "scale model", "scale of a map", "scale of a number line", "scale", "scaled graph", "scaled", "scalene triangle", "scalene", "scatter plot", "scattergram", "sector", "segment", "semi-circle", "semicircle", "sequence", "set", "sign", "significant digits", "significant digit", "significant figure", "similar figures", "similar", "simpler form", "simplify", "simulation", "situtation diagram", "skew lines", "skew line", "slanted", "slide rule", "slope", "solid figure", "solution", "span", "speed", "sphere", "square root", "square unit", "square", "squared", "stacked bar graph", "standard form", "standard unit", "statistic", "stem and leaf plot", "step graph", "straight angle", "straightedge", "subset of" "substitute", "subtract", "subtrahend", "sum of", "sum", "supplementary angle", "surface area", "surface", "survey", "symmetric", "symmetry", "system of equation", "system of", "table", "take from ten", "tally", "tangent circle", "tangent", "tangent circles", "tangram", "tape diagram", "temperature", "template", "tens place", "tenth", "term", "terminating decimal", "tessellat", "tessellate", "tessellation", "tetrahedron", "tetromino", "theorem", "thermometer", "thousand", "thousandth", "tile", "tiling", "time graph",1 unmodified line "top heavy fraction", "topological", "topology", "total area", "total of", "total surface", "total volume", "trade first subtraction", "transformation", "translation", "transversal", "trapezoid", "tree diagram", "triangle", "triangular", "true number sentence", "truncate", "twin primes", "unlike denominators", "unlike fractions", "twin prime", "two-way table", "unit cube", "unit form", "unit fraction", "unit interval", "unit price", "unit rate", "unit square", "unit", "unknown", "unlike denominator", "unlike fraction", "value", "vanishing ", "variability", "variable", "velocity", "venn diagram", "vernal equinox", "vertex", "vertical", "volume of", "volume", "weight", "whole number", "whole unit", "whole", "width", "base of a prism", "base of a pyramid", "face", "numerical data", "opposite", "pace", "per", "region", "sign", "alternate interior angles", "base of an exponent", "cone", "congruent", "counterclockwise", "cube root", "hypotenuse", "irrational number", "linear relationship", "positive association", "rate of change", "translation", "transversal", "circumference", "corresponding", "expand", "population", "proportion", "radius", "random", "repeating decimal", "representative", "scaled", "withdrawal", "center", "edge", "height of a parallelogram or triangle", "net", "speed", "table", "term", "adjacent", "complementary", "cross-section", "cross section", "deposit", "event", "measurement error", "proportional", "simulation", "center of a dilation", "clockwise", "dilation", "function", "negative association", "pythagorean theorem", "relative frequency", "rigid transformation", "scale factor", "scatter plot", "similar", "sphere", "two-way table", "additive identity", "additive inverse", "box and whisker plot", "cartesian coordinates", "central angle", "chord", "combination", "commutative property", "coplanar", "cross product", "dependent events", "difference", "dividend", "equilateral triangle", "error of measurement", "factorial", "formula", "identity property of", "independent events", "infinity", "inscribed angle", "intercept", "intercepted arc", "inverse", "inverse operations", "isosceles triangle", "least common denominator", "like fractions", "locus", "logic", "lowest terms", "mode", "multiplicative identity", "multiplicative inverse", "mutually exclusive events", "natural numbers", "normal", "permutation", "pi", "point", "power", "range", "rate", "ray", "real numbers", "rectangular", "root", "rotation", "scalene triangle", "scattergram", "set", "statistics", "terminating decimal", "transformation", "word form", "x axes", "x axis", "x intercept", "x-axes", "x-axis", "x-intercept", "y axes", "y axis", "y intercept", "y-axes", "y-axis", "y-intercept", "zero", "yard", "zero property of multiplication", "base of a parallelogram", "base of a triangle", "height", "chance experiment", "diameter", "mean", "percentage", "sample", "legs", "outlier", "slope", "square root", "system of equations", "tessellation", "zero",]
p = inflect.engine()
def singular_to_plural(word): """Convert singular words to plural using inflect.""" plural = p.plural(word) return plural or word
def plural_to_singular(word): """Convert plural word to singular using inflect.""" return p.singular_noun(word) or word
plural_MATH_WORDS = [singular_to_plural(word) for word in MATH_WORDS]
MATH_WORDS += plural_MATH_WORDS
def get_num_words(text): if not isinstance(text, str): print("%s is not a string" % text)handler.py+68-64
requirements.txt+1
utils.py+513-410