此 Python 脚本生成一个 json 文件,其格式为 WKS 可理解:
import uuid
import json
# Generate IDs
ent_id,lbl01_id = uuid.uuid4(), uuid.uuid4()
json_out = {}
json_out.update({
"entityTypes":[{
"id":str(lbl01_id), "label":"Calificativo",
"sireProp":
{
"mentionType":None,
"subtypes":["Bueno_extremo", "Bueno_moderado", "Regular", "Malo_moderado", "Malo_extremo"],
"roles":[str(lbl01_id)], "clazz":None, # Roles relates to self & other labels, if any
"color":None, "hotkey":None, "backGroundColor":None, "active":True, "roleOnly":False
},
"creationDate":1583241330349, "source":None, "modifiedDate":1583247016579, "typeType":None,
"typeClass":None, "typeVersion":None, "typeDesc":None, "typeSuperType":None, "typeSuperTypeId":None,
"typeCreateDate":None, "typeUpdateDate":None, "typeProvenance":None, "alchemyAPITypes":None,
"nluAPITypes":None
}],
"sireInfo":{
"entityProp":{
"mentionType":[{"color":"white", "hotkey":"1", "backGroundColor":"#AA00FF", "name":"NAM"},
{"color":"black", "hotkey":"2", "backGroundColor":"#00FF7F", "name":"NOM"},
{"color":"black", "hotkey":"3", "backGroundColor":"#AAFFFF", "name":"PRO"},
{"color":"white", "hotkey":"4", "backGroundColor":"gray", "name":"NONE"}],
"subtypes":None,
"roles":None,
"clazz":[{"color":"#A5A5A5", "hotkey":"3", "backGroundColor":"white", "name":"SPC"},
{"color":"black", "hotkey":"2", "backGroundColor":"#00FF7F", "name":"NEG"},
{"color":"black", "hotkey":"1", "backGroundColor":"#AAFFFF", "name":"GEN"}],
"color":None,
"hotkey":None,
"backGroundColor":None,
"active":True,
"roleOnly":False
},
"relationProp":{
"tense":[{"name":"PAST"}, {"name":"PRESENT"}, {"name":"FUTURE"}, {"name":"UNSPECIFIED"}],
"modality":[{"name":"ASSERTED"}, {"name":"OTHER"}],
"clazz":[{"name":"SPECIFIC"}, {"name":"NEG"}, {"name":"OTHER"}],
"backGroundColor":None, "color":None, "hotkey":None, "active":True}
},
"functionalEntityTypes":[
{"id":"CATCH_ALL_ENTITY_ID", "label":"*",
"sireProp":{
"mentionType":None, "subtypes":None, "roles":None, "clazz":None, "color":None,
"hotkey":None, "backGroundColor":None, "active":True, "roleOnly":False},
"creationDate":1487227572757, "source":None, "modifiedDate":0, "typeType":None,
"typeClass":None, "typeVersion":None, "typeDesc":None, "typeSuperType":None,
"typeSuperTypeId":None, "typeCreateDate":None, "typeUpdateDate":None, "typeProvenance":None,
"alchemyAPITypes":None, "nluAPITypes":None
}],
"pid":str(ent_id), "modified_date":1583247016579, "kgimported":False
})
with open('json_file.json', 'w') as outfile:
json.dump(json_out, outfile)
这只会生成 1 个实体;要生成更多,就在“id”和“nluAPITypes”之间,与要添加的实体一样多。
这里也可以包含“relationshipTypes”