ダミーデータをデータベースに登録

□未翻訳

□翻訳中

□翻訳完了(Yota Ichino)

■レビュー(Omi Chiba)

ダミーデータをデータベースに登録

テスト用目的にダミーデータをデータベーステーブルに登録できれば便利です。この目的に合う読解可能なダミーテキスを学習させたベイズ分類器を、web2pyはすでに含んでいます。

For testing purposes it is convenient to be able to populate database tables with dummy data. web2py includes a Bayesian classifier already trained to generate dummy but readable text for this purpose.

簡単な使い方:

Here is the simplest way to use it:

1.

2.

from gluon.contrib.populate import populate

populate(db.mytable,100)

100個のダミーレコードをdb.mytableに挿入します。stringフィールド用の短文、textフィールド用の長文、integer、double、date、datetime、time、boolean、その他のフィールドを知的に生成します。バリデータで指定された必要条件を尊重しようとします。フィールドに単語"name"が含まれているとダミーの名前を生成しようとします。リファレンスフィールドにより妥当なリファレンスを生成します。

It will insert 100 dummy records into db.mytable. It will try to do intelligently by generating short text for string fields, longer text for text fields, integers, doubles, dates, datetimes, times, booleans, etc. for the corresponding fields. It will try to respect requirements imposed by validators. For fields containing the word "name" it will try to generate dummy names. For reference fields it will generate valid references.

もしBがAを参照する2つのテーブル(AとB)があるとき、Aから先に登録し、次にBを登録します。

If you have two tables (A and B) where B references A, make sure to populate A first and B second.

登録作業はトランザクション中に終了し、とりわけリファレンスが含まれると、一度にたくさんのレコードを登録しようとはしません。その代わりに、その時に100個を登録し、コミット、ループします。

Because population is done in a transaction, do not attempt to populate too many records at once, particularly if references are involved. Instead, populate 100 at the time, commit, loop.

1.

2.

3.

for i in range(10):

populate(db.mytable,100)

db.commit()

ベイズ分類器にいくつかの文章を学習させ、学習データと似ているが無意味なダミーテキストを生成できます。

You can use the Bayesian classifier to learn some text and generate dummy text that sounds similar but should not make sense:

1.

2.

3.

4.

from gluon.contrib.populate import Learner, IUP

ell=Learner()

ell.learn('some very long input text ...')

print ell.generate(1000,prefix=None)