diff --git a/README.rst b/README.rst index d0a3f0e..6061ac5 100644 --- a/README.rst +++ b/README.rst @@ -4,15 +4,9 @@ pyspotlight is a thin python wrapper around `DBpedia Spotlight`_'s `REST Interface`_. -The currently supported DBpedia Spotlight versions are 0.5 and 0.6.5. -However, as long as there are no major API overhauls, this wrapper might also -work with future versions. If you encounter a bug with a newer DBpedia version, -feel free to create an issue here on github. - -Note that I'm trying to track DBpedia Spotlight release version numbers, so you can -easily see which pyspotlight version has been tested with which Spotlight -release. Therefore all pyspotlight 0.5 releases are tested against -Spotlight 0.5. +This repository contains a fork of the original `pyspotlight` that aims at providing compatibility +with newer releases of DBpedia Spotlight. The orignal seems unmaintained; pull requests are not being +reviewed and merged. .. _`DBpedia Spotlight`: https://github.com/dbpedia-spotlight/dbpedia-spotlight#dbpedia-spotlight .. _`REST Interface`: https://github.com/dbpedia-spotlight/dbpedia-spotlight/wiki/Web-service @@ -29,7 +23,7 @@ Therefore installation is as easy as:: Requirements for installation from source/github ================================================ -This module has been tested with Python 2.6 and Python 2.7. +This module has been tested with Python 2.7 and Python 3.5. As long as you use the ``setup.py`` for the installation (``python setup.py install``), you'll be fine because Python takes care of the diff --git a/setup.py b/setup.py index 1269835..8355417 100644 --- a/setup.py +++ b/setup.py @@ -14,13 +14,13 @@ "Development Status :: 5 - Production/Stable", ] -requires = ["requests=>2.10.0", ] +requires = ["requests", ] # This might not be the best idea. try: import json except ImportError: - requires.append('simplejson>=2.0') + requires.append('simplejson') # Python 2.6 does not ship with an OrderedDict implementation. @@ -28,17 +28,18 @@ try: from collections import OrderedDict except ImportError: - requires.append('ordereddict>=1.1') + requires.append('ordereddict') setup(name='pyspotlight', - version='0.6.5.2', + version='0.7.0', license='BSD', - url='https://github.com/newsgrape/pyspotlight', + url='https://github.com/aolieman/pyspotlight', packages=find_packages(), description='Python interface to the DBPedia Spotlight REST API', long_description=open('README.rst').read(), keywords="dbpedia spotlight semantic", classifiers=classifiers, install_requires=requires, + test_suite='nose2.collector.collector', ) diff --git a/spotlight/__init__.py b/spotlight/__init__.py index 826c1b2..55181a9 100644 --- a/spotlight/__init__.py +++ b/spotlight/__init__.py @@ -4,18 +4,9 @@ This is just a simple interface to a Spotlight API. -Tested with DBPedia Spotlight 0.5 and 0.6.5. - -Note that I'm trying to track Spotlight release version numbers, so you can -easily see which pyspotlight version has been tested with which Spotlight -release. - -I hope the code and the small documentation speaks for itself :-) - -If you should encounter any problems, feel free to contact me on github -(originell). I'm happy to help out with anything related to my code. +Tested with DBPedia Spotlight 0.7. """ -__version_info__ = (0, 6, 5) +__version_info__ = (0, 7, 0) __version__ = '.'.join(map(str, __version_info__)) @@ -42,7 +33,7 @@ def _convert_number(value): # Workaround for footnotes being put into Resources.surfaceForm and then # having them parsed by the JSON parser into a list. (issue #4) if isinstance(value, list): - value = unicode(value) + value = str(value) try: return int(value) @@ -61,7 +52,7 @@ def _dict_cleanup(dic, dict_type=dict): That way we can avoid stack fails. """ clean = dict_type() - for key, value in dic.iteritems(): + for key, value in dic.items(): if value is None: continue @@ -70,7 +61,7 @@ def _dict_cleanup(dic, dict_type=dict): try: # If this is a string or bool, # go straight to type conversion. - if (isinstance(value, basestring) or + if (hasattr(value, 'strip') or isinstance(value, bool)): raise AttributeError # Test for an iterable (list, tuple, set) @@ -86,12 +77,7 @@ def _dict_cleanup(dic, dict_type=dict): # Main functions. -# -# I was inspired to go back to a function based approach after seeing this -# awesome talk by Jack Diederich: Stop Writing Classes -# http://pyvideo.org/video/880/stop-writing-classes -# Most of the class-based approach had the problems he described. -# Embarrassing! + def annotate(address, text, confidence=0.0, support=0, spotter='Default', disambiguator='Default', filters=None, headers=None): @@ -157,9 +143,13 @@ def annotate(address, text, confidence=0.0, support=0, :rtype: list of resources """ - payload = {'confidence': confidence, 'support': support, - 'spotter': spotter, 'disambiguator': disambiguator, - 'text': text} + payload = { + 'confidence': confidence, + 'support': support, + 'text': text, + 'spotter': spotter, + 'disambiguator': disambiguator + } filter_kwargs = {'policy': 'whitelist'} filter_kwargs.update(filters or {}) @@ -204,9 +194,13 @@ def candidates(address, text, confidence=0.0, support=0, :rtype: list of surface forms """ - payload = {'confidence': confidence, 'support': support, - 'spotter': spotter, 'disambiguator': disambiguator, - 'text': text} + payload = { + 'confidence': confidence, + 'support': support, + 'text': text, + 'spotter': spotter, + 'disambiguator': disambiguator + } filter_kwargs = {'policy': 'whitelist'} filter_kwargs.update(filters or {})