GF web服务API示例 GF可以从GF Shell交互使用。 一些功能 GF shell中可用的也可以通过GF web服务API使用。 这个 GF公司 Web服务API页面 描述了GF web服务支持的调用 应用程序编程接口。 下面,我们通过示例说明这些调用,并显示 如何使用中定义的API从JavaScript进行这些调用 pgf在线.js
.
注释 那个 pgf在线.js
最初开发 考虑到一个特定的web应用程序(迷你吧),所以服务器API 不完整。 2011年8月对其进行了简化和推广,以支持 完整API。
这些框显示了JavaScript中的调用 API定义于 pgf在线.js
. 这些框显示发送到PGF服务器的相应URL。 这些框显示了PGF返回的JSON(JavaScript数据结构) 服务器。 这将传递给 呼叫。
初始化
//选择要使用的服务器和语法:
var服务器选项={ grammars_url:“ http://www.grammaticalframework.org/grammars(语法框架)/ ", grammar_list:[“Foods.pgf”] //可以跳过这个
} var服务器=pgf_online(服务器选项);
示例
//获取可用语法列表
server.get_grammarlist(回调) http://localhost:41296/grammars/grammars.cgi [“Foods.pgf”,“Phrasebook.pgf”] //选择要使用的语法
server.switch_grammar(“Foods.pgf”) //获取具体语言和其他语法信息的列表
server.grammar_info(回调) http://localhost:41296/grammars/Foods.pgf {“name”:“食品”, “userLanguage”:“FoodsEng”, “startcat”:“注释”, “类别”:[“注释”,“浮点”,“整数”,“项目”,“种类”,“质量”,“字符串”], “功能”:[“无聊”,“奶酪”,“美味”,“昂贵”,“鱼”,“新鲜”, “意大利语”、“Mod”、“披萨”、“Pred”、“That”、“These”、“This”、“thres”、, “温暖”,“葡萄酒”], “languages”:[{“name”:“FoodsBul”,“language Code”:“”}, {“name”:“FoodsEng”,“languageCode”:“en-US”}, {“name”:“FoodsFin”,“languageCode”:“”}, {“name”:“FoodsSwe”,“languageCode”:“sv-SE”}, ...] } //获取随机语法树
server.getrandom({},回调) http://localhost:41296/grammars/Foods.pgf?command=random [{“树”:“Pred(那个披萨)(很无聊)”}] //线性化语法树
server.linealize({tree:“Pred(That Pizza)(非常无聊)”,to:“FoodsEng”},回调) http://localhost:41296/grammars/Foods.pgf?command=linearize&tree=Pred +(That+Pizza)+(Very+Boring)&to=食品工程 [{“to”:“FoodsEng”,“text”:“那匹萨很无聊”}] linearize({tree:“Pred(That Pizza)(非常无聊)”},回调) http://localhost:41296/grammars/Foods.pgf?command=linearize&tree=Pred +(那+披萨)+(非常+无聊) [{“to”:“FoodsBul”,“text”:, {“to”:“FoodsEng”,“text”:“那匹萨很无聊”}, {“to”:“FoodsFin”,“text”:“tylsä中的厄里特ä上的陀比萨饼”}, {“to”:“FoodsSwe”,“text”:“den där pizzanär mycket trákig”}, ... ] //分析字符串
parse({from:“FoodsEng”,输入:“那个披萨很无聊”},回调) http://localhost:41296/grammars/Foods.pgf?command=parse&input=that +披萨+是+非常+无聊&来自=FoodsEng [{“from”:“FoodsEng”, “方括号”:{“cat”:“Comment”,“fid”:10,“index”:0,“children”:[{“猫”:“Item”,“fid”:7,“indexe”:0、“childen”:[}“token”:“that”},{“猫咪”:“Kind”,“fid”:6,“index0”,“child”:[[{”token“:“pizza”}]}]},“token:”is“}”,{”cat“:“Quality”,“find”:9,“indue”:0:[{“token”:“very”},{“cat”:“Quality”,“fid”:8,“index”:0,“children”:[{token:“boring”}]}]}, “树”:[“Pred(That Pizza)(非常无聊)”]}] //翻译为所有可用语言
translate({from:“FoodsEng”,输入:“那个披萨很无聊”},回调) ... //翻译成一种语言
translate({input:“那个披萨很无聊”,从:“FoodsEng”,到:“FoodesSwe”},回调) http://localhost:41296/grammars/Foods.pgf?command=translate&input=that +披萨+非常+无聊&from=FoodsEng&to=Foods Swe [{“from”:“FoodsEng”, “方括号”:{“cat”:“Comment”,“fid”:10,“index”:0,“children”:[{“猫”:“Item”,“fid”:7,“indexe”:0、“childen”:[}“token”:“that”},{“猫咪”:“Kind”,“fid”:6,“index0”,“child”:[[{”token“:“pizza”}]}]},“token:”is“}”,{”cat“:“Quality”,“find”:9,“indue”:0:[{“token”:“very”},{“cat”:“Quality”,“fid”:8,“index”:0,“children”:[{token:“boring”}]}]}, “翻译”: [{“树”:“Pred(那个披萨)(很无聊)”, “线性化”: [{“to”:“FoodsSwe”, “文本”:“den där pizzanär mycket trákig”}]}]] //完成(接下来会出现什么单词)
complete({from:“FoodsEng”,input:“that pizza is very”},回调) http://localhost:41296/grammars/Foods.pgf?command=complete&input=that +披萨+是+非常+来自=食品工程 [{“from”:“FoodsEng”, “方括号”:{“cat”:“_”,“fid”:0,“index”:0、“children”:[{“猫”:“项目”,“fid”:7,“索引”:0;“childens”:[}“标记”:“that”},{“猫咪”:“Kind”,“fid”:6,“indexe”:0, “完成”:[“无聊”,“美味”,“昂贵”,“新鲜”,“意大利语”,“非常”,“温暖”], “文本”:“”}] //获取抽象语法中类别的信息
browse({id:“Kind”},回调) http://localhost:41296/grammars/Foods.pgf?command=browse&id=Kind&format=json {“def”:“猫类”, “生产者”:[“奶酪”,“鱼”,“Mod”,“披萨”,“葡萄酒”], “消费者”:[“Mod”,“That”,“These”,“This”,“These”]} //获取抽象语法中函数的信息
browse({id:“This”},回调) http://localhost:41296/grammars/Foods.pgf?command=browse&id=This&format=json {“def”:“fun This:Kind->Item”,“生产者”:[],“消费者”:[]} //获取抽象语法中所有类别和函数的信息
server.browse({},回调) http://localhost:41296/grammars/Foods.pgf?command=browse&format=json {“cats”:{“Kind”:{“def”:“cat Kind”, “生产者”:[“奶酪”,“鱼”,“Mod”,“披萨”,“葡萄酒”], “消费者”:[“Mod”,“That”,“These”,“This”,“These”]}, ...}, “funs”:{“This”:{“def”:“fun-This:Kind->Item”,“producers”:[],“consumers”:[]}, ...} } //将抽象语法树转换为JSON
server.pgf_call(“absrjson”,{tree:“Pred(That Pizza)(非常无聊)”},回调) http://localhost:41296/grammars/Foods.pgf?command=absrjson&tree=Pred +(那+披萨)+(非常+无聊) {“乐趣”:“Pred”,“fid”:4, “children”:[{“fun”:“That”,“fid”:1, “children”:[{“fun”:“Pizza”,“fid”:0}]}, {“有趣”:“非常”,“fid”:3, “孩子们”:[{“有趣”:“无聊”,“烦躁”:2}]}]} //查找单词的形态分析
server.pgf_call(“lookupmorpho”,{input:“fish”,from:“FoodsEng”},回调) http://localhost:41296/grammars/Foods.pgf?command=lookupmorpho&input=fish&from=FoodsEng [{“引理”:“Fish”,“analysis”:“sPl”},{“lemma”:“Fish”,”analysis“:”sSg“}]
上次修改时间:2016年6月16日星期四17:08:04 CEST
真实航向