-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_wikify.py
60 lines (48 loc) · 1.59 KB
/
test_wikify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Path hack
import os
import sys
import logging
sys.path.insert(0, os.path.abspath('..'))
try:
import unittest2 as unittest
except ImportError:
import unittest
from cdata.wikify import wikidata_search, wikidata_get # noqa
class WikifyTestCase(unittest.TestCase):
def setUp(self):
pass
def test_wikidata(self):
query = u"居里夫人"
ret = wikidata_search(query, lang="zh")
#logging.info(ret)
nodeid = ret["itemList"][0]["identifier"]
assert nodeid == "Q7186"
ret = wikidata_get(nodeid)
lable_zh = ret["entities"][nodeid]["labels"]["zh"]["value"]
assert lable_zh == u"玛丽·居里"
query = u"AutoDealer"
ret = wikidata_search(query)
logging.info(ret)
assert 0 == len(ret["itemList"])
query = u"Campsite"
ret = wikidata_search(query)
logging.info(ret)
nodeid = ret["itemList"][0]["identifier"]
assert nodeid == "Q832778"
ret = wikidata_get(nodeid)
lable_zh = ret["entities"][nodeid]["labels"]["zh"]["value"]
logging.info(lable_zh)
assert lable_zh == u"露營場"
query = "birthplace"
ret = wikidata_search(query, searchtype="property")
#logging.info(ret)
nodeid = ret["itemList"][0]["identifier"]
assert nodeid == "P19"
ret = wikidata_get(nodeid)
lable_zh = ret["entities"][nodeid]["labels"]["zh"]["value"]
logging.info(lable_zh)
assert lable_zh == u"出生地"
if __name__ == '__main__':
unittest.main()