44
55This is just a simple interface to a Spotlight API.
66
7- Tested with DBPedia Spotlight 0.5 and 0.6.5.
8-
9- Note that I'm trying to track Spotlight release version numbers, so you can
10- easily see which pyspotlight version has been tested with which Spotlight
11- release.
12-
13- I hope the code and the small documentation speaks for itself :-)
14-
15- If you should encounter any problems, feel free to contact me on github
16- (originell). I'm happy to help out with anything related to my code.
7+ Tested with DBPedia Spotlight 0.7.
178"""
18- __version_info__ = (0 , 6 , 5 )
9+ __version_info__ = (0 , 7 , 0 )
1910__version__ = '.' .join (map (str , __version_info__ ))
2011
2112
@@ -42,7 +33,7 @@ def _convert_number(value):
4233 # Workaround for footnotes being put into Resources.surfaceForm and then
4334 # having them parsed by the JSON parser into a list. (issue #4)
4435 if isinstance (value , list ):
45- value = unicode (value )
36+ value = str (value )
4637
4738 try :
4839 return int (value )
@@ -61,7 +52,7 @@ def _dict_cleanup(dic, dict_type=dict):
6152 That way we can avoid stack fails.
6253 """
6354 clean = dict_type ()
64- for key , value in dic .iteritems ():
55+ for key , value in dic .items ():
6556 if value is None :
6657 continue
6758
@@ -70,7 +61,7 @@ def _dict_cleanup(dic, dict_type=dict):
7061 try :
7162 # If this is a string or bool,
7263 # go straight to type conversion.
73- if (isinstance (value , basestring ) or
64+ if (hasattr (value , 'strip' ) or
7465 isinstance (value , bool )):
7566 raise AttributeError
7667 # Test for an iterable (list, tuple, set)
@@ -86,12 +77,7 @@ def _dict_cleanup(dic, dict_type=dict):
8677
8778
8879# Main functions.
89- #
90- # I was inspired to go back to a function based approach after seeing this
91- # awesome talk by Jack Diederich: Stop Writing Classes
92- # http://pyvideo.org/video/880/stop-writing-classes
93- # Most of the class-based approach had the problems he described.
94- # Embarrassing!
80+
9581def annotate (address , text , confidence = 0.0 , support = 0 ,
9682 spotter = 'Default' , disambiguator = 'Default' ,
9783 filters = None , headers = None ):
@@ -157,9 +143,13 @@ def annotate(address, text, confidence=0.0, support=0,
157143
158144 :rtype: list of resources
159145 """
160- payload = {'confidence' : confidence , 'support' : support ,
161- 'spotter' : spotter , 'disambiguator' : disambiguator ,
162- 'text' : text }
146+ payload = {
147+ 'confidence' : confidence ,
148+ 'support' : support ,
149+ 'text' : text ,
150+ 'spotter' : spotter ,
151+ 'disambiguator' : disambiguator
152+ }
163153
164154 filter_kwargs = {'policy' : 'whitelist' }
165155 filter_kwargs .update (filters or {})
@@ -204,9 +194,13 @@ def candidates(address, text, confidence=0.0, support=0,
204194
205195 :rtype: list of surface forms
206196 """
207- payload = {'confidence' : confidence , 'support' : support ,
208- 'spotter' : spotter , 'disambiguator' : disambiguator ,
209- 'text' : text }
197+ payload = {
198+ 'confidence' : confidence ,
199+ 'support' : support ,
200+ 'text' : text ,
201+ 'spotter' : spotter ,
202+ 'disambiguator' : disambiguator
203+ }
210204
211205 filter_kwargs = {'policy' : 'whitelist' }
212206 filter_kwargs .update (filters or {})
0 commit comments