示例#1
0
    def _pre_interact(self):        
        try:
            import gf
        except ImportError:
            print "No autocompletion available"
            return

        pgf = gf.read_pgf(self.pgf_path)
        langs = [l for l in pgf.languages() if `l`[-3:] == self.lang]
        assert len(langs) == 1, "Cannot retrieve chosen pgf language."
        lang = langs[0]
        ip = __IPYTHON__
        class myCompleter:
            def __init__(self, pgf, lang):
                self.pgf = pgf
                self.lang = lang
            def complete(self, text, state,line_buffer=None):
                # we need the whole line; only available from readline
                line = ip.readline.get_line_buffer()
                completions = self.pgf.complete(lang, line)
                try:
                    return completions[state]
                except IndexError:
                    return None
        ip.Completer = myCompleter(pgf,lang)
示例#2
0
文件: test.py 项目: McMbuvi/GF-core
	def test_parse(self):
		pgf = gf.read_pgf(self.pgf)
		l = gf.read_language(self.lang)
		for abs,cnc in self.lexed:
			rabs = exp2str(abs)
			ps = pgf.parse(cnc['eng'], l)
			self.failUnless(ps)
			pt = rmprefix(ps[0])
			self.assertEqual(pt,rabs)
示例#3
0
文件: test.py 项目: McMbuvi/GF-core
	def setUp(self):
		self.samples = samples
		self.pgf = gf.read_pgf('Query.pgf')
		self.langs = dict([(lang2iso(l),l) for l in self.pgf.languages()])
示例#4
0
文件: test.py 项目: McMbuvi/GF-core
	def pgf(self, path=None):
		path = path or self.path
		return gf.read_pgf(path)
示例#5
0
文件: test.py 项目: McMbuvi/GF-core
	def setUp(self):
		self.samples = samples
		self.pgf = gf.read_pgf('Query.pgf') 
		self.lang = gf.read_language('QueryEng')