- 获取Wikidata的所有properties:
在https://query.wikidata.org/直接输入一下代码,可以获取wikidata知识图谱的所有properties,根据下面SPARQL语言可以获得properties的链接URL、ID、name、 description、label等,
目前property的数量是10115个。
1 2 3 4 5 6 7 | SELECT ?property ?propertyLabel ?propertyDescription (GROUP_CONCAT( DISTINCT (?altLabel); separator = ", " ) AS ?altLabel_list) WHERE { ?property a wikibase:Property . OPTIONAL { ?property skos:altLabel ?altLabel . FILTER (lang(?altLabel) = "en" ) } SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .} } GROUP BY ?property ?propertyLabel ?propertyDescription LIMIT 11000 |
Wikipedia的SPARQL查询界面:
在界面可以选择保存的数据格式,我这里保存为csv文件:
wikidata_all_properties_20220706.csv
1 2 3 4 5 6 | property ,propertyLabel,propertyDescription,altLabel_list http: / / www.wikidata.org / entity / P6,head of government, "head of the executive power of this town, city, municipality, state, country, or other governmental body" , "governor, prime minister, mayor, chancellor, president, first minister, premier, head of national government, government headed by, executive power headed by" http: / / www.wikidata.org / entity / P10,video, "relevant video. For images, use the property P18. For film trailers, qualify with " "object has role" " (P3831)=" "trailer" " (Q622550)" , "trailer (Commons), gif, media, animation" http: / / www.wikidata.org / entity / P15,route map ,image of route map at Wikimedia Commons, "watercourse map, underground map, transit map, subway map, street map, road map, road atlas, metro map, map of route, highway map, railway map, railroad map, schema" http: / / www.wikidata.org / entity / P14,traffic sign, "graphic symbol describing the item, used at the side of or above roads to give instructions or provide information to road users" , "highway shield, road sign, route shield, trail blazer, route marker, road marker, motorway sign, highway marker, shield" ... |
- 其他:获取properties的embeddings
根据properties的相关信息,得到每个property的embedding,推荐采用MPNet模型,其专门用于获取sentence embedding的:
https://huggingface.co/sentence-transformers/all-mpnet-base-v1
具体转化代码如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from sentence_transformers import SentenceTransformer import pandas as pd import numpy as np data = pd.read_csv( 'data/wikidata_all_properties_20220706.csv' ) sentences = [ '{} {} {}' . format (n,d,l) for n,d,l in zip (data[ 'propertyLabel' ],data[ 'propertyDescription' ],data[ 'altLabel_list' ])] IDs = [ id .rsplit( '/' , 1 )[ - 1 ] for id in data[ 'property' ]] batch_size = 256 allembeddings = [] model = SentenceTransformer( 'sentence-transformers/all-mpnet-base-v1' ).to( 'cuda:1' ) for i in range ( len (sentences) / / batch_size + 1 ): embeddings = model.encode(sentences[i * batch_size:(i + 1 ) * batch_size]) allembeddings.append(embeddings) allembeddings = np.concatenate(allembeddings,axis = 0 ) allembeddings = [ list (emb) for emb in list (allembeddings)] data[ 'embedding' ] = allembeddings data[ 'sentence' ] = sentences data[ 'ID' ] = IDs D = data[[ 'ID' , 'propertyLabel' , 'sentence' , 'embedding' ]] D.to_csv( 'wikidata_all_properties_20220706+embeddings.csv' , index = False ) |
这里转化embedding采用的是propertyLabel, propertyDescription, altLabel_list三部分文本信息转化的,可以根据需要进行调整
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧