- import py2neo
- import pytholog as pl
- graph = py2neo.Graph("bolt://localhost:7687", auth=("neo4j", "12345678"))
- #input_name = input("Enter the name of the character: ")
- #create_node_from_variable = f"""
- #MERGE (n:SocialNetwork {{name: '{input_name}'}})
- #"""
- #graph.run(create_node_from_variable)
- #line = "mother(Sarah, Alisha)"
- #line = line.replace(")", "") # remove the closing parenthesis
- #predicate, arguments = line.split("(") # split at the opening parenthesis
- #argument1, argument2 = arguments.split(", ") # split the arguments at the comma
- #print(predicate, argument1, argument2)
- #query = f"""
- #MERGE (n:SocialNetwork {{name: '{argument1}'}})-[r:IS_{predicate.upper()}_OF]-(m:SocialNetwork {{name: '{argument2}'}})
- #"""
- #graph.run(query)
- kb = pl.KnowledgeBase("kb")
- list = [
- "male(ali)",
- "male(azaril)",
- "male(qasim)",
- "female(sarah)",
- "female(alisha)",
- "food(macaroni)",
- "parent(qasim, ali)",
- "parent(ali, azaril)",
- "parent(ali, alisha)",
- "parent(sarah, azaril)",
- "parent(sarah, alisha)",
- "likes(ali, macaroni)",
- "father(X, Y) :- parent(X, Y), male(X)"
- ]
- kb(list)
- prolog_query = "father(X, Y)"
- # This is a query from prolog (pytholog) knowledge-base.
- results = kb.query(pl.Expr(prolog_query))
- predicate, _ = prolog_query.split("(")
- print(predicate)
- print(results)
- x = [result['X'] for result in results if 'X' in result]
- y = [result['Y'] for result in results if 'Y' in result]
- while x:
- query = f"""
- MERGE (n:SocialNetwork {{name: '{x[0]}'}})-[r:IS_{predicate.upper()}_OF]-(m:SocialNetwork {{name: '{y[0]}'}})
- """
- x.pop(0)
- y.pop(0)
- graph.run(query)
[text] sex
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: