import random def weighted_list_to_flat_list(l): output_list = [] for k in l.keys(): output_list.extend([k] * l[k]) return output_list def generate_sentence(structures, choice_mappings): structure = random.choice(structures) outputstring = '' i = 0 i = 0 while i < len(structure): if structure[i] == '(': endparen = structure.find(')', i, len(structure)) if endparen == -1: outputstring += structure[i] i += 1 else: mappingid = structure[i+1:endparen] choicelist = weighted_list_to_flat_list(choice_mappings[mappingid]) outputstring += random.choice(choicelist) i = endparen + 1 else: outputstring += structure[i] i += 1 return outputstring def generate_innovative_startup_technology(): # the dict values represent the weight of each choice. higher numbers being chosen more frequently counter_verbs = {'mitigate':10, 'destroy':10, 'detect and destroy':10, 'detect':10, 'hunt':10, 'prevent':10, 'thwart':10, 'eliminate':10, 'neutralize':10} usage_verbs = {'leverage':10, 'synergize':10, 'deploy':10, 'take advantage of':10, 'innovate':10} using_verbs = {'leveraging':10, 'synergizing':10, 'deploying':10, 'taking advantage of':10, 'innovating':10} tech_adverbs = {'next generation':30, 'state-of-the-art':15, 'world-class':10, 'intelligent':10, 'cross-platform':10, 'best-of-breed':10, 'webscale':2, 'multi-OS':10, 'cloud':10, 'scalable':5, 'elastic':5, 'cloud capable':10, 'cloud-ready':10, 'enterprise':10, 'enterprise class':10, 'real-time':10} tech_nouns = {'agent technology':10, 'analytics':2, 'server':10, 'client':10, 'hypervisor':10, 'architecture':10, 'framework':10, 'mesh networks':1, 'mesh sensors':1, 'verticals':1, 'solution':10, 'portal':5} problem_nouns = {'threats':10, 'malware':10, 'targeted risks':2, 'the cyber kill chain':1, 'advanced threats':10, 'advanced persistent threats':10, 'adverseries':10, 'attackers':10, 'hackers':10} strategy_nouns = {'big data':10, 'machine learning':10, 'distributed computing':10, 'visualization':10, 'threat intelligence':10, 'threat modeling':10, 'risk analysis':2, 'cloud computing':10} sentence_mapping = {'counter_verb':counter_verbs, 'usage_verb':usage_verbs, 'using_verb':using_verbs, 'tech_adverb':tech_adverbs, 'tech_noun':tech_nouns, 'problem_noun':problem_nouns, 'strategy_noun':strategy_nouns } phrase_structures = ['A (tech_adverb) (tech_noun) to (counter_verb) (problem_noun)', 'A (tech_adverb) (tech_noun) to (counter_verb) (problem_noun) with (strategy_noun)', 'Using (tech_adverb) (tech_noun) to (counter_verb) (problem_noun)', 'Using (tech_adverb) (tech_noun) to (usage_verb) (strategy_noun) to (counter_verb) (problem_noun)', '(counter_verb) (problem_noun) with (tech_adverb) (strategy_noun) (tech_noun)', '(counter_verb) (problem_noun) by (using_verb) (tech_adverb) (tech_noun)', '(using_verb) (tech_adverb) (tech_noun) to (usage_verb) (strategy_noun) to (counter_verb) (problem_noun)' '(using_verb) (tech_adverb) (tech_noun) to (counter_verb) (problem_noun)', 'A stealth-mode startup dedicated to (using_verb) (tech_adverb) (tech_noun) to (counter_verb) (problem_noun)'] return generate_sentence(phrase_structures, sentence_mapping) for i in range(0, 10): print " * " + generate_innovative_startup_technology() print
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question