Package: ltp-server
ltp_server基于Python的用FastAPI简单封装的LTP服务安装pipinstallltp_server服务端使用方式方式一：Python库引用示例：fromltp_serverimportServerif__name__=='__main__':model_path=r"/root/Data/NLP/Model/LTP"# server = Server(model_path=model_path)# server.run()Server(model_path).run()方式二：shell命令示例：ltp_server--model_path=/root/Data/NLP/Model/LTP可用选项参数名是否可选默认值说明model_path否LTP模型路径（绝对路径）dict_path是None用户词表路径（绝对路径）max_window是4前向分词最大窗口host是127.0.0.1服务主机名port是8000服务监听端口服务概览服务功能服务路由请求方式分句/sent_splitPOST增加自定义词语/add_wordsPOST分词/segPOST词性标注/posPOST命名实体识别/nerPOST语义角色标注/srlPOST依存句法分析/depPOST语义依存分析（树）/sdpPOST语义依存分析（图）/sdpgPOST请求示例分句### sent_splitPOSThttp://localhost:8000/sent_split
Content-Type:application/json{"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"]}返回值：{"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"],"sents":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"],"status":0}增加自定义词语### add_wordsPOSThttp://localhost:8000/add_words
Content-Type:application/json{"words":["江大桥"]}返回值{"status":0}分词### segPOSThttp://localhost:8000/seg
Content-Type:application/json{"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"]}返回值{"status":0,"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"],"res":[["曹操","和","司马懿","去","赶集","，","中途","遇","上","关羽","，","一起","吃","了","个","饭","。"]]}词性标注### posPOSThttp://localhost:8000/pos
Content-Type:application/json{"texts":["南京市长江大桥"]}返回值{"status":0,"texts":["南京市长江大桥"],"res":[[["南京市","ns"],["长江","ns"],["大桥","n"]]],"seg":[["南京市","长江","大桥"]]}命名实体识别### nerPOSThttp://localhost:8000/ner
Content-Type:application/json{"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"]}返回值{"status":0,"texts":["乔丹是一位出生在纽约的美国职业篮球运动员。"],"res":[[["乔丹","Nh",0,0],["纽约","Ns",6,6],["美国","Ns",8,8]]],"seg":[["乔丹","是","一","位","出生","在","纽约","的","美国","职业","篮球","运动员","。"]]}语义角色标注### srlPOSThttp://localhost:8000/srl
Content-Type:application/json{"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"]}返回值{"status":0,"texts":["乔丹是一位出生在纽约的美国职业篮球运动员。"],"res":[[["是",1,[["A0",["乔丹"],0,0],["A1",["一","位","出生","在","纽约","的","美国","职业","篮球","运动员"],2,11]]],["出生",4,[["A1",["在","纽约"],5,6],["A0",["职业","篮球","运动员"],9,11]]]]],"seg":[["乔丹","是","一","位","出生","在","纽约","的","美国","职业","篮球","运动员","。"]]}依存句法分析### depPOSThttp://localhost:8000/dep
Content-Type:application/json{"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"]}返回值{"status":0,"texts":["乔丹是一位出生在纽约的美国职业篮球运动员。"],"res":[[[1,"乔丹",2,"是","SBV"],[2,"是",0,"ROOT","HED"],[3,"一",4,"位","ATT"],[4,"位",12,"运动员","ATT"],[5,"出生",12,"运动员","ATT"],[6,"在",5,"出生","CMP"],[7,"纽约",6,"在","POB"],[8,"的",5,"出生","RAD"],[9,"美国",12,"运动员","ATT"],[10,"职业",12,"运动员","ATT"],[11,"篮球",12,"运动员","ATT"],[12,"运动员",2,"是","VOB"],[13,"。",2,"是","WP"]]],"seg":[["乔丹","是","一","位","出生","在","纽约","的","美国","职业","篮球","运动员","。"]]}语义依存分析（树）### sdpPOSThttp://localhost:8000/sdp
Content-Type:application/json{"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"]}返回值{"status":0,"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"],"res":[[[1,"曹操",4,"去","AGT"],[1,"曹操",5,"赶集","AGT"],[2,"和",3,"司马懿","mRELA"],[3,"司马懿",4,"去","AGT"],[4,"去",0,"ROOT","Root"],[5,"赶集",4,"去","eSUCC"],[6,"，",5,"赶集","mPUNC"],[7,"中途",8,"遇","MANN"],[8,"遇",5,"赶集","eSUCC"],[9,"上",8,"遇","mDEPD"],[10,"关羽",8,"遇","DATV"],[11,"，",8,"遇","mPUNC"],[12,"一起",13,"吃","MANN"],[13,"吃",8,"遇","eSUCC"],[14,"了",13,"吃","mDEPD"],[15,"个",16,"饭","MEAS"],[16,"饭",13,"吃","PAT"],[17,"。",13,"吃","mPUNC"]]],"seg":[["曹操","和","司马懿","去","赶集","，","中途","遇","上","关羽","，","一起","吃","了","个","饭","。"]]}语义依存分析（图）### sdpgPOSThttp://localhost:8000/sdpg
Content-Type:application/json{"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"]}返回值{"status":0,"texts":["曹操和司马懿去赶集，中途遇上关羽，一起吃了个饭。"],"res":[[[1,"曹操",4,"去","AGT"],[1,"曹操",5,"赶集","AGT"],[2,"和",3,"司马懿","mRELA"],[3,"司马懿",4,"去","AGT"],[4,"去",0,"ROOT","Root"],[5,"赶集",4,"去","eSUCC"],[6,"，",5,"赶集","mPUNC"],[7,"中途",8,"遇","MANN"],[8,"遇",5,"赶集","eSUCC"],[9,"上",8,"遇","mDEPD"],[10,"关羽",8,"遇","DATV"],[11,"，",8,"遇","mPUNC"],[12,"一起",13,"吃","MANN"],[13,"吃",8,"遇","eSUCC"],[14,"了",13,"吃","mDEPD"],[15,"个",16,"饭","MEAS"],[16,"饭",13,"吃","PAT"],[17,"。",13,"吃","mPUNC"]]],"seg":[["曹操","和","司马懿","去","赶集","，","中途","遇","上","关羽","，","一起","吃","了","个","饭","。"]]}客户端使用方式方式一：Python库使用示例如下：fromltp_serverimportClientif__name__=='__main__':client=Client()texts=["乔丹是一位出生在纽约的美国职业篮球运动员。"]print(client.sent_split(texts))print(client.seg(texts))print(client.pos(texts))print(client.ner(texts))print(client.srl(texts))print(client.dep(texts))print(client.sdp(texts))print(client.sdpg(texts))请求结果：{'texts':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'res':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'status':0}{'status':0,'texts':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'res':[['乔丹','是','一','位','出生','在','纽约','的','美国','职业','篮球','运动员','。']]}{'status':0,'texts':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'res':[[['乔丹','nh'],['是','v'],['一','m'],['位','q'],['出生','v'],['在','p'],['纽约','ns'],['的','u'],['美国','ns'],['职业','n'],['篮球','n'],['运动员','n'],['。','wp']]],'seg':[['乔丹','是','一','位','出生','在','纽约','的','美国','职业','篮球','运动员','。']]}{'status':0,'texts':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'res':[[['乔丹','Nh',0,0],['纽约','Ns',6,6],['美国','Ns',8,8]]],'seg':[['乔丹','是','一','位','出生','在','纽约','的','美国','职业','篮球','运动员','。']]}{'status':0,'texts':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'res':[[['是',1,[['A0',['乔丹'],0,0],['A1',['一','位','出生','在','纽约','的','美国','职业','篮球','运动员'],2,11]]],['出生',4,[['A1',['在','纽约'],5,6],['A0',['职业','篮球','运动员'],9,11]]]]],'seg':[['乔丹','是','一','位','出生','在','纽约','的','美国','职业','篮球','运动员','。']]}{'status':0,'texts':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'res':[[[1,'乔丹',2,'是','SBV'],[2,'是',0,'ROOT','HED'],[3,'一',4,'位','ATT'],[4,'位',12,'运动员','ATT'],[5,'出生',12,'运动员','ATT'],[6,'在',5,'出生','CMP'],[7,'纽约',6,'在','POB'],[8,'的',5,'出生','RAD'],[9,'美国',12,'运动员','ATT'],[10,'职业',12,'运动员','ATT'],[11,'篮球',12,'运动员','ATT'],[12,'运动员',2,'是','VOB'],[13,'。',2,'是','WP']]],'seg':[['乔丹','是','一','位','出生','在','纽约','的','美国','职业','篮球','运动员','。']]}{'status':0,'texts':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'res':[[[1,'乔丹',2,'是','EXP'],[2,'是',0,'ROOT','Root'],[3,'一',4,'位','MEAS'],[4,'位',12,'运动员','MEAS'],[5,'出生',12,'运动员','rEXP'],[6,'在',7,'纽约','mRELA'],[7,'纽约',5,'出生','LOC'],[8,'的',5,'出生','mDEPD'],[9,'美国',12,'运动员','FEAT'],[10,'职业',11,'篮球','FEAT'],[10,'职业',12,'运动员','FEAT'],[11,'篮球',12,'运动员','FEAT'],[12,'运动员',2,'是','LINK'],[13,'。',2,'是','mPUNC']]],'seg':[['乔丹','是','一','位','出生','在','纽约','的','美国','职业','篮球','运动员','。']]}{'status':0,'texts':['乔丹是一位出生在纽约的美国职业篮球运动员。'],'res':[[[1,'乔丹',2,'是','EXP'],[2,'是',0,'ROOT','Root'],[3,'一',4,'位','MEAS'],[4,'位',12,'运动员','MEAS'],[5,'出生',12,'运动员','rEXP'],[6,'在',7,'纽约','mRELA'],[7,'纽约',5,'出生','LOC'],[8,'的',5,'出生','mDEPD'],[9,'美国',12,'运动员','FEAT'],[10,'职业',11,'篮球','FEAT'],[10,'职业',12,'运动员','FEAT'],[11,'篮球',12,'运动员','FEAT'],[12,'运动员',2,'是','LINK'],[13,'。',2,'是','mPUNC']]],'seg':[['乔丹','是','一','位','出生','在','纽约','的','美国','职业','篮球','运动员','。']]}方式二：自己通过http请求调用略参考HIT-SCIR/ltp: Language Technology Platformltp/quickstart.rst at master · HIT-SCIR/ltppython fire使用指南_coordinate的博客-CSDN博客命令行脚本 — Python Packaging Tutorial玩转 Python 命令行：4 大主流工具库的对比 - Python猫的个人空间 - OSCHINA - 中文开源技术交流社区用它5分钟以后，我放弃用了四年的 Flask_涛哥聊Python-CSDN博客