def test_generate_sentence(self):
     """Test loremipsum.generate_sentence function."""
     words, sentence = loremipsum.generate_sentence(incipit=True)
     self.assertEqual(words, len(list(self._s._find_words(sentence))))
     min_len = min(len(sentence), len(self._s['incipit'])) - 1
     self.assertEqual(sentence[:min_len], self._s['incipit'][:min_len])
     words, sentence = loremipsum.generate_sentence(sentence_len=5)
     self.assertEqual(5, words)
     self.assertEqual(5, len(list(self._s._find_words(sentence))))
Beispiel #2
0
 def test_generate_sentence(self):
     """Test loremipsum.generate_sentence function."""
     words, sentence = loremipsum.generate_sentence(incipit=True)
     self.assertEqual(words, len(list(self._s._find_words(sentence))))
     min_len = min(len(sentence), len(self._s['incipit'])) - 1
     self.assertEqual(sentence[:min_len], self._s['incipit'][:min_len])
     words, sentence = loremipsum.generate_sentence(sentence_len=5)
     self.assertEqual(5, words)
     self.assertEqual(5, len(list(self._s._find_words(sentence))))
def generate_book_title():
    words = loremipsum.generate_sentence()[2][:-1].split()
    title = ' '.join(words[:random.randrange(1, MAX_WORDS_IN_TITLE+1)])
    if title[-1] == ',':
        title = title[:-1] + '.'
    elif title[-1] != '.':
        title += '.'
    return title
Beispiel #4
0
    def handle(self, *args, **options):
        quantity = options.get('quantity')
        for i in range(quantity):
            sentence = loremipsum.generate_sentence(True)[2]
            sentence = sentence.split(' ')

            # tags with 3 words or fewer
            tag = ' '.join(sentence[:int(random.random() * 3) + 1])
            Tag.objects.create(tag=tag)
Beispiel #5
0
def insert_rows():
    while True:
        session = get_session()
        cur = session.cursor()
        message = loremipsum.generate_sentence()[2]
        cur.execute('insert into tw_challenge VALUES (%s)', (message, ))
        session.commit()
        cur.close()
        session.close()
        sleep(0.1)
Beispiel #6
0
    def test_add_comments_to_article(self):
        NUM_OF_COMMENTS = 5
        article = Article.objects.last()

        for i in range(NUM_OF_COMMENTS):
            article.comments.create(content=generate_sentence()[2],
                                    author=CustomUser.objects.first())

        self.assertEqual(NUM_OF_COMMENTS, Comment.objects.count())
        self.assertEqual(NUM_OF_COMMENTS, article.comments.count())
Beispiel #7
0
def create_topic(cafe_id, user_id):
    title = loremipsum.generate_sentence()[2]
    paragraphs = loremipsum.generate_paragraphs(random.randint(3, 7))
    paragraphs = [p[2] for p in paragraphs]
    md_content = random.choice(markdown_contents)
    index = random.randint(0, len(paragraphs))
    paragraphs.insert(index, md_content)
    content = '\n\n'.join(paragraphs)
    return {
        "title": title[:135],
        "content": content,
        "user_id": user_id,
    }
Beispiel #8
0
def catch_all(path):

    parents = ['/']
    accumulated = ''
    for p in path.split('/'):
        if p:
            accumulated += '/' + p
            parents.append(str(accumulated))

    children = [('/{}/{}' if path else '/{}{}').format(path, i) for i in range(4)]

    return render_template('first.html',
                           parents=parents,
                           children=children,
                           title=loremipsum.generate_sentence(),
                           paragraphs=loremipsum.get_paragraphs(3))
def conn_scan(tgtHost, tgtPort):
	# Starts the connection
	try:
		connSkt = socket(AF_INET,SOCK_STREAM)
		connSkt.connect((tgtHost, tgtPort))
		connSkt.send(loremipsum.generate_sentence(start_with_lorem=False))
		results = connSkt.recv(100)
		screenLock.acquire()
		print('[+]%d/tcp open' % tgtPort)
		print('[+]', str(results))
		connSkt.close()
	except Exception as e:
		screenLock.acquire()
		#print "Error: {0}".format(str(e))
		print('[-]%d/tcp open' % tgtPort)
	finally:
		screenLock.release()
		connSkt.close()
Beispiel #10
0
    def handle(self, *args, **options):
        count = options['count']
        for i in range(count):
            news_content = ""
            for j in range(random.randint(1, 4)):
                news_content = news_content + generate_paragraph()[2] + "\n"

            title = generate_sentence(start_with_lorem=True)[2]
            if len(title) > 50:
                title = title[0:50]

            news = {
                'content': news_content,
                'content_pt': news_content,
                'title': title,
                'title_pt': title
            }
            News.objects.create(**news)
            self.stdout.write("Created news number " + str(i))
Beispiel #11
0
def demo_add_post(person_id):
    _, words_amount, text = generate_sentence()
    # Piter coordinates:
    # lat, lon
    # 59.93900, 30.325896
    latitude = 59.0 + 1.0 * random.randint(850000, 999999) / 1000000
    longitude = 30.0 + 1.0 * random.randint(200000, 399999) / 1000000
    pic_url = "http://lorempixel.com/300/300/"
    try:
        if person_id:
            Person.get(Person.vkid == person_id)
        else:
            all_p = Person.select(Person.vkid)
            count = all_p.count() - 1
            person_id = all_p[random.randint(0, count)]
        Post.create(author=person_id, text=text, pic_url=pic_url, latitude=latitude, longitude=longitude)
        return True
    except DoesNotExist:
        return False
Beispiel #12
0
def demo_add_comment(author_id, post_id):
    _, words_amount, text = generate_sentence()
    try:
        if author_id:
            Person.get(Person.vkid == author_id)
        else:
            all_pers = Person.select(Person.vkid)
            count = all_pers.count() - 1
            author_id = all_pers[random.randint(0, count)]

        if post_id:
            p = Post.get(Post.post_id == post_id)
        else:
            all_posts = Post.select()
            count = all_posts.count() - 1
            p = all_posts[random.randint(0, count)]
            p.comments += 1
            p.save()
        Comment.create(post=p, author=author_id, text=text)
        return True
    except DoesNotExist:
        return False
Beispiel #13
0
def demo_add_comment(author_id, post_id):
    _, words_amount, text = generate_sentence()
    try:
        if author_id:
            Person.get(Person.vkid == author_id)
        else:
            all_pers = Person.select(Person.vkid)
            count = all_pers.count() - 1
            author_id = all_pers[random.randint(0, count)]

        if post_id:
            p = Post.get(Post.post_id == post_id)
        else:
            all_posts = Post.select()
            count = all_posts.count() - 1
            p = all_posts[random.randint(0, count)]
            p.comments += 1
            p.save()
        Comment.create(post=p, author=author_id, text=text)
        return True
    except DoesNotExist:
        return False
    def handle(self, *args, **options):
        blog = options.get('blog')
        quantity = options.get('quantity')
        blog_models = import_module('blog.blog%s.models' % blog)
        Post = blog_models.Post

        users = list(User.objects.all())
        categories = list(Category.objects.all())

        posts = []
        for i in range(int(quantity)):
            amount = int(random.random() * 4) + 1
            content = ' '.join(loremipsum.get_paragraphs(amount, True))
            title = loremipsum.generate_sentence(True)[2]
            posts.append(
                Post.objects.create(
                    author=random.choice(users),
                    category=random.choice(categories),
                    title=title[:60],
                    content=content,
                    approved=random.random() < 0.8,  # ~80% post approved
                    featured=random.random() < 0.1  # ~10% post approved
                )
            )

        tags = list(Tag.objects.all())

        for post in posts:
            for i in range(int(random.random() * 4)):
                comment = loremipsum.get_paragraph(True)
                blog_models.PostComment.objects.create(
                    post=post,
                    user=random.choice(users),
                    comment=comment,
                    approved=random.random() < 0.8  # ~80% post approved
                )

            for tag in random.choices(tags, k=random.choice([2, 3, 4])):
                post.tags.add(tag)
Beispiel #15
0
def demo_add_post(person_id):
    _, words_amount, text = generate_sentence()
    # Piter coordinates:
    # lat, lon
    # 59.93900, 30.325896
    latitude = 59.0 + 1.0 * random.randint(850000, 999999) / 1000000
    longitude = 30.0 + 1.0 * random.randint(200000, 399999) / 1000000
    pic_url = "http://lorempixel.com/300/300/"
    try:
        if person_id:
            Person.get(Person.vkid == person_id)
        else:
            all_p = Person.select(Person.vkid)
            count = all_p.count() - 1
            person_id = all_p[random.randint(0, count)]
        Post.create(author=person_id,
                    text=text,
                    pic_url=pic_url,
                    latitude=latitude,
                    longitude=longitude)
        return True
    except DoesNotExist:
        return False
                     user="******",
                     passwd="123456",
                     db="docker-test",
                     charset='utf8')
cursor = db.cursor()
sql = "SELECT  * from posts"
cursor.execute(sql)
data = cursor.fetchall()
comment_count = 0
fo = open("comments_generate.sql", "w")

for row in data:
    post_id = row[0]
    post_num = abs(int(numpy.random.normal(0, 200, 1))) % 200 + 1
    date_sta = row[6]
    insert_sql = "INSERT INTO comments(post_id, user_id, comment_id, content, added) VALUES "
    for comment in range(post_num):
        user_id = abs(int(numpy.random.normal(0, 2500, 1))) % 10000 + 1
        content = generate_sentence()[2]
        comment_id = 0 if random.random() < 0.7 else comment_count + int(
            random.random() * comment)
        date_sta = date_sta + timedelta(seconds=int(random.random() * 300))
        insert_sql =insert_sql + " (%d, %d,%d,  \"%s\",  '%s')," % \
               (post_id,user_id,comment_id, content, date_sta)
    insert_sql = insert_sql[:-1] + ';\n'
    fo.write(insert_sql)
    comment_count = comment_count + post_num
    print(comment_count)
    print(row[0])
fo.close()
db.close()
import re, csv, random, json
import loremipsum as LI

n = 10

path = 'scrap/dummy-collections/'
filename = "collection-" + str(random.randint(1000, 9999))
print filename

C = csv.writer(file(path + filename + ".csv", 'w'))
C.writerow(('content', 'META_sentences', 'META_words'))

J = {
    "name": " ".join(LI.generate_sentence()[2].split()[:3]),
    "description": LI.generate_sentence()[2],
    "documents": []
}

for a in range(n):
    sentences, words, text = LI.generate_paragraph()
    row = (text, sentences, words)
    C.writerow(row)

    j = {
        "content": text,
        "metadata": {
            "sentences": str(sentences),
            "words": str(words),
        }
    }
Beispiel #18
0
def create_data(size):
    begin_date = datetime.date(1999, 1, 1)
    start_date = datetime.date(1950, 1, 1)
    end_date = datetime.date(2001, 1, 1)

    list_alcoholic = []
    list_bed = []
    list_inspector = []
    list_taken = []
    list_passed = []
    list_released = []
    list_escaped = []
    list_bed_alco = []
    list_group_drinking = []
    list_alco_group = []

    list_drinks = [(1, 'whiskey', 40), (2, 'vodka', 40), (3, 'wine', 20),
                   (4, 'sherry', 20), (5, 'port', 35), (6, 'brandy', 35),
                   (7, 'rum', 50), (8, 'gin', 50), (9, 'tequila', 50),
                   (10, 'hock', 40), (11, 'vermouth', 17),
                   (12, 'absinthe', 45), (13, 'rye', 40), (14, 'beer', 10),
                   (15, 'champagne', 12), (16, 'sake', 30)]
    list_department = [
        (1, 'Criminal Investigation Office', 100),
        (2, 'Accident Registration Bureau', 30),
        (3, 'Center for Countering Extremism', 40),
        (4,
         'The operational investigative unit (ORC) to ensure the safety of persons subject to state protection',
         75), (5, 'Department of operative-search information', 30),
        (6, 'Office or Division of Economic Security and Anti-Corruption', 60),
        (7, 'Department of NC Interpol', 120), (8, 'Dog Training Center', 30)
    ]
    num_of_department = len(list_department)
    num_of_drinks = len(list_drinks)
    num_of_inspectors = size // 5

    # alcoholic, inspector, bed -- size
    for i in range(size):
        bed = (i + 1,
               random.choice([
                   'yellow', 'red', 'pink', 'blue', 'lemon', 'darkblue',
                   'white', 'grey'
               ]), random.randrange(1, 3))
        random_date = random_date_between(start_date, end_date)
        description = loremipsum.generate_sentence(start_with_lorem=3)[2]
        alcoholic = (i + 1, names.get_first_name(), names.get_last_name(),
                     random_date.strftime("%m-%d-%Y"), description)
        random_date = random_date_between(start_date, end_date)
        inspector = (i + 1, random.randrange(1, num_of_department + 1),
                     names.get_full_name(), random_date.strftime("%m-%d-%Y"))

        list_alcoholic.append(alcoholic)
        list_bed.append(bed)
        list_inspector.append(inspector)

    # all events occured size * 2 times
    for _ in range(size * 10):
        inspector_id = random.randint(1, (num_of_inspectors))
        alco_id = random.randrange(1, (size + 1))
        taken_date = random_date_between(begin_date, end_date)
        bed_id = random.randint(1, size)
        taken = (inspector_id, alco_id, bed_id,
                 taken_date.strftime("%m-%d-%Y"))
        list_taken.append(taken)

        f_passed = random.randint(0, 1)
        f_escaped = random.randint(0, 1)
        f_released = random.randint(0, 1)
        if f_escaped:
            f_released = 0

        for __ in range(random.randint(0, 3)):
            start_date = taken_date
            changed_date = random_date_between(start_date, end_date)
            new_bed_id = random.randint(1, size)
            bed_alco = (alco_id, new_bed_id, inspector_id,
                        changed_date.strftime("%m-%d-%Y"))
            list_bed_alco.append(bed_alco)
            taken_date = changed_date
            bed_id = new_bed_id

        if f_passed:
            start_date = taken_date
            passed_date = random_date_between(start_date, end_date)
            passed = (alco_id, bed_id, passed_date.strftime("%m-%d-%Y"))
            list_passed.append(passed)
            taken_date = passed_date

        if f_escaped:
            start_date = taken_date
            escaped_date = random_date_between(start_date, end_date)
            escaped = (alco_id, bed_id, escaped_date.strftime("%m-%d-%Y"))
            list_escaped.append(escaped)

        if f_released:
            start_date = taken_date
            released_date = random_date_between(start_date, end_date)
            released = (random.randint(1, num_of_inspectors), alco_id, bed_id,
                        released_date.strftime("%m-%d-%Y"))
            list_released.append(released)

    # adding groups
    for i in range(size // 10):
        random_date = random_date_between(begin_date, end_date)
        group = (i + 1, random.randint(1, num_of_drinks),
                 random_date.strftime("%m-%d-%Y"),
                 loremipsum.generate_sentence(start_with_lorem=3)[2])

        for _ in range(random.randint(1, 8)):
            alco_group = (i + 1, random.randint(1, size))
            list_alco_group.append(alco_group)

        list_group_drinking.append(group)

    write_data('alcoholic.csv', list_alcoholic)
    write_data('alcogroup.csv', list_alco_group)
    write_data('alco_released.csv', list_released)
    write_data('alco_passed.csv', list_passed)
    write_data('alco_escaped.csv', list_escaped)
    write_data('drinks.csv', list_drinks)
    write_data('alco_taken.csv', list_taken)
    write_data('bed.csv', list_bed)
    write_data('bed_alco.csv', list_bed_alco)
    write_data('groups.csv', list_group_drinking)
    write_data('inspectors.csv', list_inspector)
    write_data('department.csv', list_department)
                    usecols=[0,12,15,22,27,31,32], dtype={'volume':'str'}, nrows=row_num,
                    header=None, index_col=0)

# we are not considering articles not published in any journal
data.dropna(how='all', subset=['journal','volume'], inplace=True)
data.drop_duplicates(inplace=True)

# ---------------------------------generating synthetic data----------------------------------#

idx = data[data.journal.notnull()][data.volume.isnull()].index # row indices where volume=null
null_doi_num = data.doi.isnull().sum() # number of rows with doi=null
null_pages_num = data.pages.isnull().sum() # number of rows with pages=null

syn_volume = [str(np.random.randint(11, 1000)) for z in range(len(idx))] # casting to str is needed
                                                                         # for later concatenation
syn_doi = [generate_sentence()[2] for j in range(null_doi_num)]
syn_abstract = [generate_sentence()[2] for j in range(row_num)]
syn_pages = np.random.randint(50, 300, null_pages_num)

kws = np.array(pd.read_csv(r'../data/keyword_topic.csv',
                           names=['keyword'],
                           usecols=[0],
                           index_col=0).index.to_list()) # loading list of keywords from csv
# creating str 'kw1|kw2' where kw1 and kw2 are randomly chosen from kw
syn_kws = ['|'.join(kws[[np.random.randint(0, len(kws), 2)]]) for x in range(row_num)]

#--------------------------------------------------------------------------------------------#

# assigning synthetic data to dataframe
data.loc[data.doi.isnull(),'doi'] = syn_doi
data.loc[data.pages.isnull(),'pages'] = syn_pages
Beispiel #20
0

if __name__ == '__main__':
	password = '******'

	from db import User, Story, addDefault, refresh_db, session as dbsession
	import random
	import loremipsum

	for adduser in range(1,1000):
		username = "******" % (adduser)
		user = User(username,'',password)
		user.species = 'Automatic'
		user.bio = 'Automatic bio'
		user.email = '*****@*****.**'
		user.minorflag = True
		user.accepttos =True
		dbsession.add(user)
		dbsession.commit()

	for addstories in range(1,20000):
		newstory = Story(loremipsum.generate_sentence()[2])
		newstory.text = loremipsum.generate_paragraph()[2]
		newstory.adult = True
		newstory.uid = random.randrange(1000)+1
		dbsession.add(newstory)
		dbsession.commit()



Beispiel #21
0
def main():
    """Main function to complete task."""
    AMOUNT_OF_WORDS = 20
    list_of_sentences = []
    while len(list_of_sentences) < AMOUNT_OF_WORDS:
        list_of_sentences += lorem.generate_sentence()[2].split(' ')
    list_of_sentences = list_of_sentences[:AMOUNT_OF_WORDS]
    print("Here is generated list:\n%s" % (list_of_sentences, ))
    searched_word = input("Enter word to search: ")
    amount_of_checks = 0
    start_time = float(time.time())
    print(start_time)

    for n, elem in enumerate(list_of_sentences):
        amount_of_checks += 1
        if elem == searched_word:
            print("You word has %s position." % ((n + 1), ))
            break
    else:
        print("There is no such word in list")

    unsorted_search_time = float(time.time()) - start_time
    print(float(time.time()))
    print(unsorted_search_time)
    time_per_check = unsorted_search_time / amount_of_checks

    print("Unsorted search time: %s" % (unsorted_search_time, ))
    print("Amount of checks: %s" % (amount_of_checks, ))
    print("Time per check: %s" % (time_per_check, ))
    print("*" * 80)

    sorted_list = sorted(list_of_sentences)
    searched_word = input(
        "List was sorted, enter new word to search [old word]: "
    ) or searched_word
    amount_of_checks_sorted = 0
    start_time = float(time.time())

    for n, elem in enumerate(sorted_list):
        amount_of_checks_sorted += 1
        if elem == searched_word:
            print("You word has %s position." % ((n + 1), ))
            break
    else:
        print("There is no such word in list")
    sorted_search_time = float(time.time() - start_time)
    sorted_time_per_check = sorted_search_time / amount_of_checks_sorted
    print("Sorted search time: %s" % (sorted_search_time, ))
    print("Amount of checks: %s" % (amount_of_checks_sorted, ))
    print("Time per check: %s" % (sorted_time_per_check, ))
    print("*" * 80)

    search_checks = 0

    def binary_search(seq, t):
        nonlocal search_checks
        min = 0
        max = len(seq) - 1
        while True:
            search_checks += 1
            if max < min:
                return -1
            m = (min + max) // 2
            if seq[m] < t:
                min = m + 1
            elif seq[m] > t:
                max = m - 1
            else:
                return m

    start_time = float(time.time())

    binary_search(sorted_list, searched_word)

    log_search_time = float(time.time() - start_time)
    log_time_per_check = log_search_time / search_checks
    print("Sorted log search time: %s" % (log_search_time, ))
    print("Amount of checks: %s" % (search_checks, ))
    print("Time per check: %s" % (log_time_per_check, ))
    print("*" * 80)
Beispiel #22
0
from default import db
from models import Institutes
from loremipsum import generate_paragraph, generate_sentence

#db.create_all()
# db.session.add(Institutes("a","b"))
# db.session.add(Institutes("a1","b"))
# db.session.add(Institutes("a2","b"))
# db.session.add(Institutes("a3","b"))
# db.session.add(Institutes("a4","b"))
# db.session.add(Institutes("a5","b"))
# db.session.add(Institutes("a6","b"))
# db.session.add(Institutes("a7","b"))
# db.session.add(Institutes("a8","b"))
# db.session.add(Institutes("a9","b"))
# db.session.add(Institutes("a10","b"))
# db.session.add(Institutes("a11","b"))
# db.session.add(Institutes("a12","b"))
# db.session.add(Institutes("a13","b"))

for i in range(0,1000):
    a1,a2,title = generate_sentence()
    b1,b2,paragraph = generate_paragraph()
    db.session.add(Institutes(title,paragraph))

db.session.commit()
Beispiel #23
0
 def sentence():
   return loremipsum.generate_sentence()[2]
Beispiel #24
0
 def test_new_post(self):
     post = Post(date=str(datetime.now()),
                 body=generate_paragraph()[2],
                 title=generate_sentence()[2])
     r = self.loop.run_until_complete(self.controller.new_post(post))
     assert r is True
Beispiel #25
0
 def word():
   return choice(loremipsum.generate_sentence()[2].split(' '))
import re, csv, random, json
import loremipsum as LI

n = 10

path = 'scrap/dummy-collections/'
filename = "collection-"+str(random.randint(1000,9999))
print filename

C = csv.writer(file(path+filename+".csv", 'w'))
C.writerow(('content', 'META_sentences', 'META_words'))

J = {
    "name": " ".join(LI.generate_sentence()[2].split()[:3]),
    "description": LI.generate_sentence()[2],
    "documents": []
}

for a in range(n):
    sentences, words, text = LI.generate_paragraph()
    row = ( text, sentences, words )
    C.writerow(row)

    j = {
        "content" : text,
        "metadata" : {
            "sentences" : str(sentences),
            "words" : str(words),
        }
    }
reviewed_by = [(i, '|'.join(
    list(
        map(
            lambda x: str(x),
            sample(
                list(authored_by.loc[
                    authored_by.articleID != i].authorID.unique()), 3)))))
               for i in articles]
reviewed_by_df = pd.DataFrame.from_records(
    reviewed_by, columns=['articleID',
                          'reviewerID'])  # converting into Dataframe

# generating reviews and decisions
syn_reviews = [
    '|'.join([
        generate_sentence()[2],
        generate_sentence()[2],
        generate_sentence()[2]
    ]) for j in range(row_num)
]
decisions = ['accept', 'accept', 'reject']
syn_decisions = [
    '|'.join(sample(decisions, len(decisions))) for i in range(row_num)
]

# dataframe for reviews and decisions
rev_dec_df = pd.DataFrame.from_dict({
    'reviews': syn_reviews,
    'decisions': syn_decisions
})