def printable(): return string.printable def uppercase(): return string.uppercase def whitespace(): return string.whitespace # m = str.find # m("foo", "oo") # 1 string_functions = { "ascii_lowercase" : ( 0, fm.fcall0(ascii_lowercase)), "ascii_uppercase" : ( 0, fm.fcall0(ascii_uppercase)), "digits" : ( 0, fm.fcall0(digits)), "hexdigits" : ( 0, fm.fcall0(hexdigits)), "letters" : ( 0, fm.fcall0(letters)), "lowercase" : ( 0, fm.fcall0(lowercase)), "octdigits" : ( 0, fm.fcall0(octdigits)), "punctuation" : ( 0, fm.fcall0(punctuation)), "printable" : ( 0, fm.fcall0(printable)), "uppercase" : ( 0, fm.fcall0(uppercase)), "whitespace" : ( 0, fm.fcall0(whitespace)), "capitalize" : ( 1, fm.mcall1("capitalize")), "find" : ( 2, fm.mcall2("find")), # INCOMPLETE, more poss "rfind" : ( 2, fm.mcall2("rfind")), # INCOMPLETE, more poss "index" : ( 2, fm.mcall2("index")), # INCOMPLETE, more poss "rindex" : ( 2, fm.mcall2("rindex")), # INCOMPLETE, more poss
for item in final: tdict = {} tdict['text'] = item[0] tdict['weight'] = int(item[1] * self.max_words) res.append(tdict) return res def createWordcloud(max_words): return Wordcloud(int(max_words)) wordcloud_functions = { "createWordcloud": (1, fm.fcall1(createWordcloud)), "getwords": (1, fm.fcall1(getwords)), "stopwords": (0, fm.fcall0(stopwords)), "addText": (2, fm.mcall2(Wordcloud.addText)), "update_wordcloud": (2, fm.fcall2(update_wordcloud)), "getWordWeights": (1, fm.mcall1(Wordcloud.getWordWeights)), } ECA_parser.functions.update(wordcloud_functions) # Test function. if __name__ == '__main__': print("#!TWORDCLOUD") wc = createWordcloud(15) wc.addText( '@vessie @Tapz @Scarbir Ik ben in Enschede zaterdag! Batavierenrace. Veel plezier!' ) wc.addText(
def uppercase(): return string.uppercase def whitespace(): return string.whitespace # m = str.find # m("foo", "oo") # 1 string_functions = { "ascii_lowercase": (0, fm.fcall0(ascii_lowercase)), "ascii_uppercase": (0, fm.fcall0(ascii_uppercase)), "digits": (0, fm.fcall0(digits)), "hexdigits": (0, fm.fcall0(hexdigits)), "letters": (0, fm.fcall0(letters)), "lowercase": (0, fm.fcall0(lowercase)), "octdigits": (0, fm.fcall0(octdigits)), "punctuation": (0, fm.fcall0(punctuation)), "printable": (0, fm.fcall0(printable)), "uppercase": (0, fm.fcall0(uppercase)), "whitespace": (0, fm.fcall0(whitespace)), "capitalize": (1, fm.mcall1("capitalize")), "find": (2, fm.mcall2("find")), # INCOMPLETE, more poss "rfind": (2, fm.mcall2("rfind")), # INCOMPLETE, more poss "index": (2, fm.mcall2("index")), # INCOMPLETE, more poss "rindex": (2, fm.mcall2("rindex")), # INCOMPLETE, more poss
"log" : ( 2, fm.fcall2(math.log)), "log1p" : ( 1, fm.fcall1(math.log1p)), "log10" : ( 1, fm.fcall1(math.log10)), "pow" : ( 2, fm.fcall2(math.pow)), "sqrt" : ( 1, fm.fcall1(math.sqrt)), "acos" : ( 1, fm.fcall1(math.acos)), "asin" : ( 1, fm.fcall1(math.asin)), "atan" : ( 1, fm.fcall1(math.atan)), "atan2" : ( 2, fm.fcall2(math.atan2)), "cos" : ( 1, fm.fcall1(math.cos)), "hypot" : ( 2, fm.fcall1(math.hypot)), "sin" : ( 1, fm.fcall1(math.sin)), "tan" : ( 1, fm.fcall1(math.tan)), "degrees" : ( 1, fm.fcall1(math.degrees)), "radians" : ( 1, fm.fcall1(math.radians)), "acosh" : ( 1, fm.fcall1(math.acosh)), "asinh" : ( 1, fm.fcall1(math.asinh)), "atanh" : ( 1, fm.fcall1(math.atanh)), "cosh" : ( 1, fm.fcall1(math.cosh)), "sinh" : ( 1, fm.fcall1(math.sinh)), "tanh" : ( 1, fm.fcall1(math.tanh)), "erf" : ( 1, fm.fcall1(math.erf)), "erfc" : ( 1, fm.fcall1(math.erfc)), "gamma" : ( 1, fm.fcall1(math.gamma)), "lgamma" : ( 1, fm.fcall1(math.ceil)), "pi" : ( 0, fm.fcall0(pi)), "e" : ( 0, fm.fcall0(e)) } ECA_parser.functions.update( math_functions )
"log": (2, fm.fcall2(math.log)), "log1p": (1, fm.fcall1(math.log1p)), "log10": (1, fm.fcall1(math.log10)), "pow": (2, fm.fcall2(math.pow)), "sqrt": (1, fm.fcall1(math.sqrt)), "acos": (1, fm.fcall1(math.acos)), "asin": (1, fm.fcall1(math.asin)), "atan": (1, fm.fcall1(math.atan)), "atan2": (2, fm.fcall2(math.atan2)), "cos": (1, fm.fcall1(math.cos)), "hypot": (2, fm.fcall1(math.hypot)), "sin": (1, fm.fcall1(math.sin)), "tan": (1, fm.fcall1(math.tan)), "degrees": (1, fm.fcall1(math.degrees)), "radians": (1, fm.fcall1(math.radians)), "acosh": (1, fm.fcall1(math.acosh)), "asinh": (1, fm.fcall1(math.asinh)), "atanh": (1, fm.fcall1(math.atanh)), "cosh": (1, fm.fcall1(math.cosh)), "sinh": (1, fm.fcall1(math.sinh)), "tanh": (1, fm.fcall1(math.tanh)), "erf": (1, fm.fcall1(math.erf)), "erfc": (1, fm.fcall1(math.erfc)), "gamma": (1, fm.fcall1(math.gamma)), "lgamma": (1, fm.fcall1(math.ceil)), "pi": (0, fm.fcall0(pi)), "e": (0, fm.fcall0(e)) } ECA_parser.functions.update(math_functions)
# print(res) res = [] for item in final: tdict = {} tdict['text'] = item[0] tdict['weight'] = int(item[1]*self.max_words) res.append(tdict) return res def createWordcloud(max_words): return Wordcloud(int(max_words)) wordcloud_functions = { "createWordcloud" : ( 1, fm.fcall1(createWordcloud)), "getwords" : ( 1, fm.fcall1(getwords)), "stopwords" : ( 0, fm.fcall0(stopwords)), "addText" : ( 2, fm.mcall2(Wordcloud.addText)), "update_wordcloud" : ( 2, fm.fcall2(update_wordcloud)), "getWordWeights" : ( 1, fm.mcall1(Wordcloud.getWordWeights)), } ECA_parser.functions.update( wordcloud_functions ) # Test function. if __name__ == '__main__': print("#!TWORDCLOUD") wc = createWordcloud(15) wc.addText('@vessie @Tapz @Scarbir Ik ben in Enschede zaterdag! Batavierenrace. Veel plezier!') wc.addText('Ik heb dit weekend bijna 10km hardgelopen, dus vind eigenlijk wel dat ik volgend weekend naar het feestje vd #batavierenrace mag.') wc.addText('Bataradio doet live verslag Batavierenrace http://t.co/6FVfQE') wc.getWordWeights()