summaryrefslogtreecommitdiff
path: root/sandbox/py-rest-doc/sphinx/environment.py
diff options
context:
space:
mode:
authorblackbird <blackbird@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-05-22 13:14:50 +0000
committerblackbird <blackbird@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-05-22 13:14:50 +0000
commitff997d5a24d0f427e785ebaab42ae6b65e74c38c (patch)
treebffff49c6143c931af69baeedfcd094e47e5614a /sandbox/py-rest-doc/sphinx/environment.py
parent49b51ed098782ea4b802264e98182adad0e2f4f5 (diff)
downloaddocutils-ff997d5a24d0f427e785ebaab42ae6b65e74c38c.tar.gz
added close matches
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@5086 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'sandbox/py-rest-doc/sphinx/environment.py')
-rw-r--r--sandbox/py-rest-doc/sphinx/environment.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/sandbox/py-rest-doc/sphinx/environment.py b/sandbox/py-rest-doc/sphinx/environment.py
index 221f27822..03d2ea6fd 100644
--- a/sandbox/py-rest-doc/sphinx/environment.py
+++ b/sandbox/py-rest-doc/sphinx/environment.py
@@ -9,7 +9,9 @@
:license: Python license.
"""
+import difflib
import itertools
+import heapq
import cPickle as pickle
from os import path
from string import uppercase
@@ -454,6 +456,30 @@ class BuildEnvironment:
if newnode:
node.replace_self(newnode)
+ def get_close_matches(self, searchstring, n=20):
+ """
+ Return a list of tuples in the form ``(type, filename, title)`` with
+ close matches for the given search string.
+ """
+ cutoff = 0.6
+ s = difflib.SequenceMatcher()
+ s.set_seq2(searchstring)
+
+ possibilities = [('module', fn, title) for (title, (fn, _, _)) in
+ self.modules.iteritems()] + \
+ [('ref', fn, title) for (title, (fn, _)) in
+ self.descrefs.iteritems()]
+
+ result = []
+ for type, filename, title in possibilities:
+ s.set_seq1(title)
+ if s.real_quick_ratio() >= cutoff and \
+ s.quick_ratio() >= cutoff and \
+ s.ratio() >= cutoff:
+ result.append((s.ratio(), type, filename, title))
+
+ return [item[1:] for item in heapq.nlargest(n, result)]
+
def resolve_toctrees(self, documents):
# determine which files (containing a toc) must be rebuilt for each
# target file (basically all "parent" files)