最近有个任务 用wikipedia判断tag的合法性,en.wikipedia.org/wiki/+"keyword"可以查询。
用c#调用webclient发生403错误,找了半天资料,后来搜索wiki api,找到了这个网址,http://en.wikipedia.org/w/api.php
很有用,里面提到程序默认header是会发生403错误的,于是添加了
WebClient client = new WebClient()
client.Headers["User-Agent"] ="Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) " +
"(compatible; MSIE 6.0; Windows NT 5.1; " +
".NET CLR 1.1.4322; .NET CLR 2.0.50727)";
能正常访问了。
wiki api还是很强大的,有兴趣的可以多多看看,对于模糊查询很有帮助,比如查询
http://en.wikipedia.org/w/api.php?action=opensearch&search=apple
返回结果:
["apple",["Apple","Apple Inc.","Apple Macintosh","Apple II","Appleton, Wisconsin","Apple Records","Apple II family","Apple iOS","Apple IIGS","Apple Store"]]
判断合法性还能使用wordnet,不过貌似没有wiki好。