コード例 #1
0
ファイル: ai_cli.py プロジェクト: thejeswi/zamia-ai
    def do_prolog(self, subcmd, opts, *module_names):
        """${cmd_name}: open prolog shell for debugging

        ${cmd_usage}
        ${cmd_option_list}
        """

        if len(module_names) == 0:
            for mn2 in self.kernal.all_modules:
                self.kernal.consult_module (mn2)
        else:
            self.kernal.consult_module (module_names[0])

        histfile = os.path.join(os.path.expanduser("~"), ".xsb_hist")
        try:
            readline.read_history_file(histfile)
            # default history len is -1 (infinite), which may grow unruly
            readline.set_history_length(1000)
        except IOError:
            pass
        atexit.register(readline.write_history_file, histfile)

        while True:

            line = input ('prolog> ')

            if line == 'quit' or line == 'exit':
                break

            try:
                for res in xsb_hl_query(line):
                    logging.info('  %s' % repr(res))

            except Exception as e:
                logging.error(traceback.format_exc())
コード例 #2
0
 def prolog_query_one(self, query, idx=0):
     logging.debug('prolog_query_one: %s' % query)
     solutions = xsb_hl_query(query)
     if not solutions:
         return None
     return solutions[0][idx]
コード例 #3
0
 def prolog_check(self, query):
     logging.debug('prolog_check: %s' % query)
     res = xsb_hl_query(query)
     return len(res) > 0
コード例 #4
0
 def prolog_query(self, query):
     logging.debug('prolog_query: %s' % query)
     return xsb_hl_query(query)
コード例 #5
0
ファイル: ai_kernal.py プロジェクト: mpuels/zamia-ai
 def prolog_hl_query(self, fname, args):
     logging.debug('prolog_hl_query: %s %s' % (fname, repr(args)))
     return xsb_hl_query(fname, args)
コード例 #6
0
ファイル: demo2.py プロジェクト: thetimeofblack/py-xsb-prolog
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

#
# demo using the high level XSB interface
#

from xsbprolog import xsb_hl_init, xsb_hl_command, xsb_hl_query, xsb_close

XSB_ROOT = '/opt/xsb-3.8.0/'

xsb_hl_init([XSB_ROOT])

xsb_hl_command('consult', ['ft'])

for row in xsb_hl_query('label', ['X', 'L']):
    print u"label of %s is %s" % (row['X'], row['L'])

for row in xsb_hl_query('descend', ['X', 'Y']):
    print u"decendant of %s is %s" % (row['X'], row['Y'])

# Close connection
xsb_close()
コード例 #7
0
#
# demo using the high level XSB interface
#

from xsbprolog import xsb_hl_init, xsb_hl_command, xsb_hl_query, xsb_close, XSBFunctor, XSBVariable, xsb_to_json, json_to_xsb

XSB_ROOT = '/opt/xsb-3.8.0/'

xsb_hl_init([XSB_ROOT])

# simple string-based interface

xsb_hl_command('consult(ft).')

for row in xsb_hl_query('label(X, L).'):
    print u"label of %s is %s" % (row[0], row[1])

# structured XSB* interface

for row in xsb_hl_query(
        XSBFunctor('descend',
                   [XSBVariable('X'), XSBVariable('Y')])):
    print u"decendant of %s is %s" % (row[0], row[1])

for row in xsb_hl_query(
        u'A = 1, B = 0.5, C = "hello", D = yes, E = foo(bar), F = [1.1,2.2], G = \'günter\'.'
):

    for i, r in enumerate(row):
        print u"#%d: %-10s (type: %-20s, class: %-20s)" % (i, r, type(r),