2020年12月31日星期四

My output ought to have been: X = us, D = [fact2,ipGeolocation(us)]

I am running my Prolog query from Python 3 using pyswip, but the response to the query is not what I am expecting. Instead of: X = us, D = [fact2,ipGeolocation(us)] ? I am getting {'X': 'us', 'D': [Atom('712197'), Atom('711429'), Functor(15831181,1,us)]}. How do I do away with the Atom and Functor keywords and get the actual values, as in the first instance? Look at the two screenshots I have attached.

These are my prolog and python codes respectively:

Prolog

:- compile('/PATH_TO_GORGIAS/gorgias-src-0.6d/lib/gorgias.pl').  :- compile('/PATH_TO_GORGIAS/gorgias-src-0.6d/ext/lpwnf.pl').      % Rules  rule(notGuiltyByDefault(X), (neg(isCulprit(X)), []).  rule(ipGeolocation(X), isCulprit(X), [ipGeoloc(X, IP)]).  rule(spoofedIp(X), neg(isCulprit(X)), [ipGeoloc(X, IP), spoofedIP(IP)]).      % Facts  rule(fact1, ipGeoloc(china, ip1), []).  rule(fact2, ipGeoloc(us, ip2), []).  rule(fact3, spoofedIP(ip1), []).      %Priority/Preference  rule(p1(X), prefer(spoofedIp(X), ipGeolocation(X)), []).  rule(p2(X), prefer(ipGeolocation(X), notGuiltyByDefault(X)), []).  

Python

def get_argument():      parser = argparse.ArgumentParser(description=display_banner())      parser.add_argument("-q", "--query", dest= "query", help="Query")      option = parser.parse_args()        if not option.query:          parser.error(f"{Red}[-] You need to specify query, enter -h for help")          raise SystemExit          return option.query       def query_knowledge_base(query_term):      prolog = Prolog()      prolog.consult('code.pl')      return list(prolog.query(query_term))          def print_query_result(query_term, query_result_list):      print(f'[+] The query submitted is: {Green}%s{Reset}' % (query_term))            if not query_result_list:          print(f'\n[-] The result of your submitted query: {Red}%s{Reset}' % ('False'))          raise SystemExit        for query_result in query_result_list:                    if len(query_result) == 0:              print(f'\n[+] The result of your submitted query: {Green}%s{Reset}' % ('True'))              raise SystemExit            str(query_result)          print(f'\n[+] The result of your submitted query: {Green}{query_result}{Reset}')      query_term = get_argument()  query_result_list = query_knowledge_base(query_term)  print_query_result(query_term, query_result_list)  

Instead of having the output with these Atom and Functor keywords:

enter image description here

I want the output like this, without the Atom and Functor keywords, but the actual values:

enter image description here

https://stackoverflow.com/questions/65526512/my-output-ought-to-have-been-x-us-d-fact2-ipgeolocationus January 01, 2021 at 08:26AM

没有评论:

发表评论