91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

基于知識圖譜的自動問答系統,有代碼,和說明文檔,大家可以看看.很很好的知識圖譜的入門案例代碼

資源截圖

代碼片段和文件信息

#?encoding=utf-8

“““

@author:?SimmerChan

@contact:?hsl7698590@gmail.com

@file:?movie_crawler.py

@time:?2017/12/19?13:23

@desc:
利用The?Movie?DB(https://www.themoviedb.org)提供的API接口獲取周星馳及其相關演員的基本信息和參演電影的基本信息。
數據保存在Mysql中。

“““

import?requests
import?json
from?crawler.tradition2simple?import?traditional2simple
import?re
import?pymysql
import?time

api_key?=?‘your_api_key‘
person_detail_url?=?‘https://api.themoviedb.org/3/person/{person_id}?api_key={api_key}&language=zh-cn‘
movie_cast_url?=?‘https://api.themoviedb.org/3/movie/{movie_id}/credits?api_key={api_key}‘
person_movie_detail_url?=?‘https://api.themoviedb.org/3/person/{person_id}/movie_credits?api_key={api_key}&language=zh-cn‘
all_movie_genres_url?=?‘https://api.themoviedb.org/3/genre/movie/list?api_key={api_key}&language=zh-cn‘

chinese_pattern?=?re.compile(u“[\u4e00-\u9fa5]+“)???#?用于查找漢字,選取演員的中文名

#?TODO?連接本地mysql的CBDB數據庫
mysql_db?=?pymysql.connect(host=“localhost“?user=“root“?db=“kg_demo_movie“?use_unicode=True?charset=“utf8mb4“)
mysql_cursor?=?mysql_db.cursor()

#?TODO?插入語句模板
insert_person_command?=?‘insert?into?person?(person_english_name?person_name?person_biography?person_birth_place?person_id?person_birth_day?person_death_day)?values?(%s?%s?%s?%s?%s?%s?%s)‘
insert_movie_command?=?‘insert?into?movie?(movie_title?movie_introduction?movie_rating?movie_id?movie_release_date)?values?(%s?%s?%s?%s?%s)‘
insert_person_movie_command?=?‘insert?into?person_to_movie?(person_id?movie_id)?values?(%s?%s)‘
insert_movie_genre_command?=?‘insert?into?movie_to_genre?(movie_id?genre_id)?values?(%s?%s)‘
insert_genre_command?=?‘insert?into?genre?(genre_id?genre_name)?values?(%s?%s)‘


def?get_all_genres():
????“““
????獲取所有的電影類型
????:return:
????“““
????r?=?requests.get(all_movie_genres_url.format(api_key=api_key))
????json_result?=?json.loads(r.content)
????genres?=?json_result[‘genres‘]
????genre_list?=?list()

????for?g?in?genres:
????????genre_list.append((g[‘id‘]?g[‘name‘]))

????return?genre_list


def?get_movie_cast(movie_id):
????#?type:?(int)?->?list
????“““
????獲取此電影所有參演演員的ID
????:param?movie_id:
????:return:
????“““
????cast_list?=?list()
????r?=?requests.get(movie_cast_url.format(movie_id=movie_id?api_key=api_key))
????json_result?=?json.loads(r.content)
????movie_cast?=?json_result[‘cast‘]

????for?cast?in?movie_cast:
????????cast_list.append(cast[‘id‘])

????return?cast_list


def?get_person_detail(person_id):
????“““
????獲取該演員的基本信息
????:param?person_id:
????:return:
????“““
????detail_list?=?list()
????r?=?requests.get(person_detail_url.format(person_id=person_id?api_key=api_key))
????json_result?=?json.loads(r.content)

????try:
????????detail_list.append(json_result[‘name‘].strip())
????except?KeyError:
????????detail_list.append(None)

????exist_chinese_name?=?False
????for?tmp?in?json_result[‘also_known_as‘]:
????????if?chinese_pattern.search(tmp):
????????????detail_list.append(traditional2simple.tradition2simple(tmp.strip()))
????????????exist_chinese_

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-06-01?16:09??基于知識圖譜的自動問答系統\
?????文件?????????265??2018-01-28?11:10??基于知識圖譜的自動問答系統\catalog-v001.xml
?????目錄???????????0??2018-06-01?20:29??基于知識圖譜的自動問答系統\data\
?????文件???????10547??2018-01-28?11:10??基于知識圖譜的自動問答系統\data\ER_diagram.mwb
?????文件?????1757163??2018-06-01?20:29??基于知識圖譜的自動問答系統\data\kg_demo_movie.sql
?????文件????????1527??2018-01-28?11:10??基于知識圖譜的自動問答系統\fuseki_conf.ttl
?????目錄???????????0??2018-06-01?16:09??基于知識圖譜的自動問答系統\kg_demo_movie\
?????文件?????8915766??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie.nt
?????目錄???????????0??2018-06-01?16:09??基于知識圖譜的自動問答系統\kg_demo_movie\.idea\
?????目錄???????????0??2018-06-01?16:09??基于知識圖譜的自動問答系統\kg_demo_movie\.idea\inspectionProfiles\
?????文件?????????228??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\.idea\inspectionProfiles\profiles_settings.xml
?????文件?????????459??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\.idea\kg_demo_movie.iml
?????文件?????????213??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\.idea\misc.xml
?????文件?????????278??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\.idea\modules.xml
?????文件???????31453??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\.idea\workspace.xml
?????目錄???????????0??2018-06-01?16:09??基于知識圖譜的自動問答系統\kg_demo_movie\crawler\
?????文件????????9495??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\crawler\movie_crawler.py
?????目錄???????????0??2018-06-01?16:09??基于知識圖譜的自動問答系統\kg_demo_movie\crawler\tradition2simple\
?????文件????????7953??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\crawler\tradition2simple\langconv.py
?????文件?????????283??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\crawler\tradition2simple\traditional2simple.py
?????文件??????143251??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\crawler\tradition2simple\zh_wiki.py
?????文件?????????129??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\crawler\tradition2simple\__init__.py
?????文件?????????129??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\crawler\__init__.py
?????目錄???????????0??2018-06-01?16:09??基于知識圖譜的自動問答系統\kg_demo_movie\KB_query\
?????目錄???????????0??2018-06-01?16:09??基于知識圖譜的自動問答系統\kg_demo_movie\KB_query\external_dict\
?????文件?????????490??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\KB_query\external_dict\csv2txt.py
?????文件???????31633??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\KB_query\external_dict\movie_title.csv
?????文件???????38267??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\KB_query\external_dict\movie_title.txt
?????文件????????2425??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\KB_query\external_dict\person_name.csv
?????文件????????3171??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\KB_query\external_dict\person_name.txt
?????文件?????????133??2018-01-28?11:10??基于知識圖譜的自動問答系統\kg_demo_movie\KB_query\external_dict\__init__.py
............此處省略13個文件信息

評論

共有 條評論