1

データ ツールキットをインストールし、コマンド ラインからファイルといくつかの Web ページに対して text2people を実行しました。

出力として、次のようなものが得られます

Peter Williams,Peter,Williams,,m,151431,151445,stdin
David Philippaerts,David,Philippaerts,,m,152500,152518,stdin
Da Ryse,Da,Ryse,,m,158551,158558,stdin

最初のフィールドは名前、姓、性別だと推測できますが、民族など、ウェブサイトに表示される他の情報を取得する方法がわかりませんでした。python/javascript などで使用する必要がありますか? ヘルプとドキュメントは本当に最小限です...

4

1 に答える 1

1

python_tools.zip をダウンロードして解凍します。ライブラリを OS にインストールした場合は、必要な場所にプログラムを作成できます。それ以外の場合は、テスト プログラムを dstk.py があるディレクトリに書き込むだけです。

ここに簡単なテストプログラムがあります。サービスから情報を取得する人のリストがあります。次に、民族情報を調べて、最も可能性の高い民族とそのパーセンテージを出力します。

import dstk
from pprint import pprint

dstk = dstk.DSTK()

# List of people you want to search for
people_names = ["Samuel L. Jackson", "Michelle Yeoh", "Danny Trejo", "Vanessa Minnillo","Naomi Campbell","Chuck Norris"]

# Query information for each person in the list
people = dstk.text2people(",".join(people_names))

# Print the structure of the received information
#print people

# Prints the structure of the people in more readable way
#pprint(people)

# Print name and ethnicity information of person
for person in people:

    if person['ethnicity'] == None:
        print (person['first_name'] + " " + person['surnames']).ljust(26), "Unknown ethnicity"
    else:
        ethnics = ['percentage_american_indian_or_alaska_native','percentage_asian_or_pacific_islander','percentage_black','percentage_hispanic','percentage_two_or_more','percentage_white']
        highest_probability = 0
        highest_index = 0

        # Find highest percentage
        for eth_index in ethnics:
            if person['ethnicity'][eth_index] > highest_probability:
                highest_probability = person['ethnicity'][eth_index]
                highest_index = eth_index
        print (person['first_name'] + " " + person['surnames']).ljust(20), str(person['ethnicity'][highest_index]).ljust(5), highest_index

上記のコードは以下を出力します。

Samuel L Jackson     53.02 percentage_black
Michelle Yeoh        87.74 percentage_asian_or_pacific_islander
Danny Trejo          94.15 percentage_hispanic
Vanessa Minnillo           Unknown ethnicity
Naomi Campbell       76.47 percentage_white
Chuck Norris         82.01 percentage_white

サーバーから受け取った構造体を出力することで変数の名前を確認できます ( pprint(people))。名前は非常に明白です。

多民族またはアメリカインディアンとして数えられる人を見つけるのに苦労しました. データベースは彼らが白人であると主張しているようです.

于 2013-06-11T12:57:58.867 に答える