def generate_lyrics(is_song: bool, templates: list, database) -> str: data_for_generator = [] for name in templates: data = normalize_data(get_data(name, database)).split("\n") data_for_generator.extend(data) chorus = None try: gen = mc.StringGenerator(samples=data_for_generator) except ValueError: return "" if is_song: chorus = "Припев:\n" + "\n".join( [generate_string(gen) for _ in range(4)]) couplets = [] strings_count = int(random.randint(1, 3)) couplet_strings_count = random.randint(4, 6) for _ in range(strings_count): couplet = "\n".join([ generate_string(gen).capitalize() for _ in range(couplet_strings_count) ]) couplets.append(couplet) if chorus is not None: couplets.append(chorus) result = "\n\n".join(couplets) return result
def generate(self, picture=False): if randint(0, 100) <= 10 or picture: attachment = choice([picture.vk_code for picture in Picture.objects.all()]) return {"attachment": attachment} else: text = mc.StringGenerator( samples=[message.message for message in EducationMessage.objects.filter( peer_id=self.peer_id)]).generate_string() return {"text": text}
async def on_message(message, attachments, env): if not env.args: return await env.reply("Пожалуйста введите аргументы)") parsed = parseRussian(env.args) generator = mc.StringGenerator(learning_data=parsed, order=1) return await env.reply(' '.join( generator.generate(count=len(parsed))).lower())
async def on_message(self, message): Insert(message.channel.name, message.content, message.guild.id) if int(time.clock()) % randint(5, 50) == 0: self.generator = mc.StringGenerator( samples=dataBaseSelectAll(message.guild.id)) self.result = self.generator.generate_string() if randint(1, 3) % 2 == 0: await message.channel.send(self.result.upper()) else: await message.channel.send(self.result)
def try_to_generate(name_of_file): try: data = [] with open(name_of_file, 'r') as file: for line in file: data.append(line) generator = mc.StringGenerator(data, 1) message = generator.generate(count=5, upper_first_letter=False) msg = convert_generated_to_text(message) return msg except mc.exceptions: return mc.exceptions
def get_generated_line(msg, minword=2, maxword=15, minsym=5, maxsym=150): samples_txt = mc.util.load_txt_samples( filepath + '/../samples/{0}.txt'.format(msg.guild.id), separator="\\") generator = mc.StringGenerator(samples=samples_txt) result = generator.generate_string( attempts=20, validator=mc.util.combine_validators( mc.validators.words_count(minword, maxword), mc.validators.symbols_count(minsym, maxsym), ), ) clean_result = re.sub( r'''(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))''', "[Link Deleted]", result) return clean_result
async def send_and_gen_sentence(*args): file, peer_id = args if not os.path.exists(file): message = "База слов для этой беседы ещё не существует" await get_api().messages.send( peer_id=peer_id, message=message, random_id=0 ) return async with AIOFile(file, encoding="utf-8") as f: text = await f.read() text_model = [sample.strip() for sample in text.split(",")] generator = mc.StringGenerator(samples=text_model) message = generator.generate_string( attempts=20, validator=mc.validators.words_count(minimal=1, maximal=15), formatter=mc.formatters.usual_syntax if USUAL_SYNTAX else None, ) if not message: message = "База слов слишком мала для генерации" await get_api().messages.send( peer_id=peer_id, message=message, random_id=0 )
def get_generated_line(bot, msg, minword=2, maxword=10, minsym=5, maxsym=150): samples_txt = mc.util.load_txt_samples( filepath + '/../samples/{0}.txt'.format(msg.guild.id), separator="\\") generator = mc.StringGenerator(samples=samples_txt) result = generator.generate_string( attempts=20, validator=mc.util.combine_validators( mc.validators.words_count(minword, maxword), mc.validators.symbols_count(minsym, maxsym), ), ) if result == None: return 'админ тупой дебил и не смог написать нормальное сооьщение об ошибке, но кароче после 20 попыток сгенерить прикол ниче не получилось, мож быть нету права на чтение сообщений или программист дебил ну в общем держу в курсе' else: clean_result = re.sub( r'''(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))''', "[Link Deleted]", result) return clean_result
import mc generator = mc.StringGenerator( learning_data=[ 'hello world', 'world of cuties', 'hello cuties' ], order=1 ) print(generator.generate(count=3)) # e.g. >> ['Hello world of cuties', 'Hello world', 'Hello cuties']
import mc generator = mc.StringGenerator( learning_data=['my name is Egor', 'Egor is programmer'], order=1) print(generator.generate( count=3)) # e.g. >> ['My name is egor', 'Egor is egor', 'Egor is egor']
import mc generator = mc.StringGenerator(samples=["hello world", "world of cuties"]) result = generator.generate_string( attempts=20, validator=mc.validators.words_count(minimal=4) ) # generates string with words count >= 4 print(result) # e.g. >> "hello world of cuties" result = generator.generate_string( attempts=20, validator=lambda string: len(string.split()) >= 4 ) # generates string with words count >= 4 print(result) # e.g. >> "hello world of cuties" result = generator.generate_string( attempts=20, validator=mc.util.combine_validators( mc.validators.words_count(minimal=4, maximal=10), mc.validators.symbols_count(minimal=10, maximal=100), ), ) # generates string with words count from 4 to 10 and symbols count from 10 to 100 print(result) # e.g. >> "hello world of cuties"
def __init__(self): sample = set() for line in open('headers.txt', 'r'): sample.add(line.split('\n')[0]) self.generator = mc.StringGenerator(samples=list(sample))