def main(corpus, nmin, case_sensitive): ac = AutoComplete(corpus, nmin=nmin, case_sensitive=case_sensitive) msg = 'Insert words for autocompletion. To terminate, press Cntrl-C.' print('%s\n%s\n%s' % ('=' * len(msg), msg, '=' * len(msg))) while True: user_word = raw_input() for completion in ac.completions(user_word): print('\t\t' + completion)
def main(): filename = None if len(sys.argv) > 1: filename = sys.argv[1] data = get_words_from_file(filename) logging.info('Number of word pairs: {0}'.format(len(data))) if filename: auto = AutoComplete(data) else: auto = AutoComplete() while True: query = input('Enter query to search: ') res = auto.query(query) print(res)
def setUp(self): self.ac = AutoComplete('data/testcorpus.csv', case_sensitive=False) self.ac_cs = AutoComplete('data/testcorpus.csv', case_sensitive=True) self.ac_n3 = AutoComplete('data/testcorpus.csv', case_sensitive=False, nmin=4)
## Path to yaml folder # check for yaml path pkg cfg_yaml_pkg = this_cfg.get('path_yaml_pkg', 'wrong') try: cfg_yaml_pkg = rospack.get_path(cfg_yaml_pkg) + '/' except Exception, e: print "Can't find ROS Package with name '" + cfg_yaml_pkg + "'" sys.exit() cfg_yaml_path = cfg_yaml_pkg + this_cfg.get('path_yaml_folder', 'config/components') editor = this_cfg.get('editor', 'subl') # add autocompletion of ros packages try: autocomplete = AutoComplete(rospack.list()) except Exception, e: print "Unable to get ROS Package List." sys.exit() readline.set_completer_delims(' \t\n;') readline.set_completer(autocomplete.complete) readline.parse_and_bind('tab: complete') # get package and file name print "\n1) Specify the name of the ROS package for parameter updates:" input_ros_pkg = raw_input("ROS Package: ") # find path to ros package try: pkg_path = rospack.get_path(input_ros_pkg)
def complete_path(text, state): return (glob.glob(text + '*') + [None])[state] # Important global variables rospack = rospkg.RosPack() try: this_pkg_path = rospack.get_path('ipa_code_refactoring') except Exception, e: print "Unable to find ROS Package with name 'ipa_code_refactoring'." sys.exit() # set autocompletion to ros packages try: autocomplete = AutoComplete(rospack.list()) except Exception, e: print "Unable to get ROS Package List." sys.exit() readline.set_completer_delims(' \t\n;') readline.set_completer(complete_path) readline.parse_and_bind('tab: complete') print print "Supply the executable for your clang formater:" user_input = raw_input("[clang-format-3.8]: ") clang = user_input if user_input != "" else "clang-format-3.8" exec_policy = {'cpp': ' -name "*.h" -or -name "*.hpp" -or -name "*.cpp" | xargs ' + clang + ' -i -style=file', # CPP 'py': ' -name "*.py" | xargs autopep8 --global-config ' + this_pkg_path + '/cfg/pep8.cfg'} # Python
def __init__(self): self.autoComplete = AutoComplete() self.resultFilter = Filter() self.googleCustom = GoogleCustomSearch() self.googleScholar = GoogleScholar()
def test_autocomplete(): list_of_words = [ "project runway", "pinterest", "river", "kayak", "progenex", "progeria", "pg&e", "project free tv", "bank", "proactive", "progesterone", "press democrat", "priceline", "pandora", "reprobe", "paypal", ] auto = AutoComplete(list_of_words) test_table = [ { "prefix": "p", "thruth": ["pandora", "paypal", "pg&e", "pinterest"] }, { "prefix": "P", "thruth": ["pandora", "paypal", "pg&e", "pinterest"] }, { "prefix": "pr", "thruth": ["press democrat", "priceline", "proactive", "progenex"] }, { "prefix": "pR", "thruth": ["press democrat", "priceline", "proactive", "progenex"] }, { "prefix": "pro", "thruth": ["proactive", "progenex", "progeria", "progesterone"] }, { "prefix": "PrO", "thruth": ["proactive", "progenex", "progeria", "progesterone"] }, { "prefix": "prog", "thruth": ["progenex", "progeria", "progesterone"] }, ] for test_case in test_table: result = auto.autocomplete(test_case["prefix"]) wanted = test_case["thruth"] assert result == wanted, f"Recieved:{result} instead of {wanted}" list_of_words = ["a", "b", "c", "d", "ab", "bc", "abcd"] auto = AutoComplete(list_of_words) assert auto.root.top_words == ["a", "ab", "abcd", "b"]
def test_init_autocomplet(): for list_of_words in (None, ["a", 1], 3.14): with pytest.raises(ValueError): AutoComplete(list_of_words)
def test_autcomplete_with_unknown_prefix(): auto = AutoComplete(["a", "b"]) assert auto.autocomplete("c") == []
def test_autocomplete_with_wrong_arg(): auto = AutoComplete([]) for arg in (None, 1, object, 3.14, True): with pytest.raises(ValueError): auto.autocomplete(arg)
def test_autoComplete_when_inputIsValid_should_returnWords(self): words = ["nature", "nation", "country", "county"] self.assertEqual(len(AutoComplete(words).find_words("nat")), len(["nation", "nature"]))
from parsecommands import parseargs_autocomplete app = Flask(__name__) @app.route('/', methods = ['GET', 'POST']) def autocomplete(): comps = [] word_current = '' if request.method == 'POST': word_current = request.form['word'] comps = ac.completions(word_current) return render_template('autocomplete.html', out_word=comps, word_current=word_current) if __name__ == '__main__': # parse command line arguments args = parseargs_autocomplete() # setup trie ac = AutoComplete(args.corpus, nmin=args.nmin, case_sensitive=args.casesensitive) app.run()
from autocomplete import AutoComplete if __name__ == "__main__": auto_complete = AutoComplete() sentence_1 = """나는 네가 정말 싫었다. 너를 다시 만나기 전까진… 따분한 게 질색인 아이, 이시다 쇼야. 간디가 어떤 사람인지, 인류의 진화과정 이라든지, 알게뭐람. 어느 날 쇼야의 따분함을 앗아갈 전학생이 나타났다. 니시미야 쇼코. 그 아이는 귀가 들리지 않는다고 한다. 쇼야의 짓궂은 장난에도 늘, 생글생글 웃고만 있다. 짜증난다. 그의 괴롭힘에 쇼코는 결국 전학을 갔고, 이시다 쇼야는 외톨이가 되었다. 6년 후, 더 이상 이렇게 살아봐야 의미가 없음을 느낀 쇼야는 마지막으로 쇼코를 찾아간다. 처음으로 전해진 두 사람의 목소리. 두 사람의 만남이 교실을, 학교를, 그리고 쇼야의 인생, 쇼코의 인생을 바꾸기 시작한다. 소년 그리고 소녀. 실타래처럼 뒤엉켜가는 청춘의 이야기.""" print("검색문장 1: ", sentence_1) print("검색어: ㅅㄴ / 검색결과: ", auto_complete.find_keyword(input_string=sentence_1, keyword="ㅅㄴ")) print("검색어: ㅁ / 검색결과: ", auto_complete.find_keyword(input_string=sentence_1, keyword="ㅁ")) print("검색어: 목소 / 검색결과: ", auto_complete.find_keyword(input_string=sentence_1, keyword="목소")) print("검색어: 굣 / 검색결과: ", auto_complete.find_keyword(input_string=sentence_1, keyword="굣")) print("\n----------------------------\n") sentence_2 = "동해물과 백두aa산이 마nn르고 닳dd도록, 하a느b님이 보c우bird하사 우리 나라 만세~"
return candidate return '' # nothing found # Important global variables rospack = rospkg.RosPack() try: this_pkg_path = rospack.get_path('ipa_code_refactoring') except Exception as e: print "Unable to find ROS Package with name 'ipa_code_refactoring'." sys.exit() # set autocompletion to ros packages try: autocomplete = AutoComplete(rospack.list()) except Exception, e: print "Unable to get ROS Package List." sys.exit() readline.set_completer_delims(' \t\n;') readline.set_completer(complete_path) readline.parse_and_bind('tab: complete') clang = find_clang_format() if clang != "": print 'Found ' + clang else: print print "Supply the executable for your clang formater:"
class TestAutoComplete(unittest.TestCase): def setUp(self): self.ac = AutoComplete('data/testcorpus.csv', case_sensitive=False) self.ac_cs = AutoComplete('data/testcorpus.csv', case_sensitive=True) self.ac_n3 = AutoComplete('data/testcorpus.csv', case_sensitive=False, nmin=4) def test_no_completion(self): self.assertEqual(len(self.ac.completions('zzz')), 0) def test_completion_len(self): self.assertEqual(len(self.ac.completions('a')), 6) self.assertEqual(len(self.ac.completions('b')), 3) self.assertEqual(len(self.ac.completions('z')), 0) self.assertEqual(len(self.ac.completions('d')), 1) self.assertEqual(len(self.ac.completions('abcdefg')), 1) self.assertEqual(len(self.ac.completions('Abcdefg')), 1) self.assertEqual(len(self.ac_cs.completions('a')), 5) self.assertEqual(len(self.ac_cs.completions('b')), 3) self.assertEqual(len(self.ac_cs.completions('z')), 0) self.assertEqual(len(self.ac_cs.completions('d')), 0) self.assertEqual(len(self.ac_cs.completions('abcdefg')), 0) self.assertEqual(len(self.ac_cs.completions('Abcdefg')), 1) def test_nmin(self): self.assertEqual(len(self.ac_n3.completions('q')), 0) self.assertEqual(len(self.ac_n3.completions('qw')), 0) self.assertEqual(len(self.ac_n3.completions('qwe')), 0) self.assertEqual(len(self.ac_n3.completions('qwer')), 1) def test_completions(self): completions = self.ac.completions('ab') words = ('abc', 'abcde', 'Abcdefg') cond = all([word in completions for word in words]) self.assertTrue(cond)