Skip to content
Snippets Groups Projects
Commit 3038606e authored by Nathan Daelman's avatar Nathan Daelman
Browse files

Add DB posting

parent 91b91ff7
No related branches found
No related tags found
No related merge requests found
from neomodel import config
from pathlib import Path
import yaml
from to_db import post
from general_parser import trace_files
from maple_parser import handler_maple
maple_dir = "maple"
maple_files = ["gga_k_apbe.mpl"]
def get_neo4j_settings() -> tuple[str, str, str, str]:
with open("config.yaml", "r") as file:
config = yaml.safe_load(file)
file.close()
return (
config["neo4j"]["user"],
config["neo4j"]["password"],
config["neo4j"]["host"],
config["neo4j"]["port"],
)
def get_libxc_settings() -> tuple[str, str]:
# Read the YAML file
with open("config.yaml", "r") as file:
config = yaml.safe_load(file)
file.close()
return config["libxc"]["path"], config["libxc"]["maple"]
def __main__():
# set up Neo4j connection
config.DATABASE_URL = "bolt://{}:{}@{}:{}".format(*get_neo4j_settings())
# Parse the Maple files
maple_dir = "{}/{}/".format(*get_libxc_settings())
maple_files = [str(file).split('/')[-1] for file in Path(maple_dir).rglob('*.mpl')]
maple_files = [str(file).split("/")[-1] for file in Path(maple_dir).rglob("*.mpl")]
for maple_file in maple_files:
triples = trace_files(
maple_file, maple_dir, handler_maple, triples=set()
)
triples = trace_files(maple_file, maple_dir, handler_maple, triples=set())
for triple in triples:
if triple[2] == "FileReference":
print(f"Maple file {triple[0]} references {triple[1]}")
post(triple)
# execute the main function
if __name__ == "__main__":
......
......@@ -16,7 +16,7 @@ FileHandler = Callable[[FileName], set[Triple]]
def file_path_to_name(file_path: str) -> str:
return file_path.split("/")[-1]
return file_path.replace('//', '/').split("/")[-1]
def read_file(file_path: str, line_processor: Callable[[str], str]) -> FileContents:
with open(file_path, "r") as file:
......
to_db.py 0 → 100644
from neomodel import StructuredNode, StringProperty, RelationshipTo
from general_parser import Triple
class FileNode(StructuredNode):
name = StringProperty(unique_index=True, required=True)
# parameters defined?
references = RelationshipTo("FileNode", "references")
def file_path_to_name(file_path: str) -> str:
return file_path.split("/")[-1]
def post_file_reference(file_path_1: str, file_path_2: str) -> None:
file_1 = FileNode.get_or_create(
{"path": file_path_1, "name": file_path_to_name(file_path_1)}
)[0]
file_2 = FileNode.get_or_create(
{"path": file_path_2, "name": file_path_to_name(file_path_2)}
)[0]
file_1.references.connect(file_2)
def post(triple: Triple):
if triple[2] == "FileReference":
post_file_reference(triple[0], triple[1])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment