aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-06-12 21:53:26 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-06-12 21:53:26 +0200
commitb2e87255d3d51956dc5da440e535ce2cee5c6f5b (patch)
tree903d5497c09e706a4c30e7b67c3624dbf0137cd2 /src/ee/tools
parentaa6697f9d669c821896c26bc8597ed68c79619c5 (diff)
downloadee-python-b2e87255d3d51956dc5da440e535ce2cee5c6f5b.tar.gz
ee-python-b2e87255d3d51956dc5da440e535ce2cee5c6f5b.tar.bz2
ee-python-b2e87255d3d51956dc5da440e535ce2cee5c6f5b.tar.xz
ee-python-b2e87255d3d51956dc5da440e535ce2cee5c6f5b.zip
souffle: Using the same relation for inputs and outputs was not a good
idea, change to use fact() for inputs and add_fact() for outputs. Leaves room for implementing remove_fact() later too.
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/part_apply_souffle_post.py9
-rw-r--r--src/ee/tools/part_apply_souffle_pre.py2
-rw-r--r--src/ee/tools/souffle-export.py57
3 files changed, 3 insertions, 65 deletions
diff --git a/src/ee/tools/part_apply_souffle_post.py b/src/ee/tools/part_apply_souffle_post.py
index 819bd03..9322ccb 100644
--- a/src/ee/tools/part_apply_souffle_post.py
+++ b/src/ee/tools/part_apply_souffle_post.py
@@ -40,7 +40,7 @@ def work(in_path: Path, out_path: Path, work_dir: Path):
mpn_csv = out_dir / "mpn.csv"
new_facts = 0
- with (out_dir / "fact.csv").open("r") as f:
+ with (out_dir / "add_fact.csv").open("r") as f:
reader = csv.reader(f, dialect="excel-tab")
for uri, key, value in reader:
try:
@@ -48,12 +48,7 @@ def work(in_path: Path, out_path: Path, work_dir: Path):
except KeyError:
raise EeException("Unknown part found in output: uri={}".format(uri))
- old_value = part.facts.get_value(key)
-
- if old_value is None:
- log.info("New fact for {}: {}={}".format(uri, key, value))
- part.facts.add(key, value)
- new_facts += 1
+ part.facts.add(key, value)
if mpn_csv.is_file():
with mpn_csv.open("r") as f:
diff --git a/src/ee/tools/part_apply_souffle_pre.py b/src/ee/tools/part_apply_souffle_pre.py
index 66aea1b..3df9eda 100644
--- a/src/ee/tools/part_apply_souffle_pre.py
+++ b/src/ee/tools/part_apply_souffle_pre.py
@@ -36,7 +36,7 @@ def work(in_path: Path, work_dir: Path):
if print_header:
fact_csv.writerow(["part_uri", "key", "value"])
- for xml in load_db(in_path).iterparts():
+ for xml in in_parts.iterparts():
p = Part(xml)
sch_ref = p.get_only_schematic_reference()
part_csv.writerow([p.uri, sch_ref.referenceProp if sch_ref else None])
diff --git a/src/ee/tools/souffle-export.py b/src/ee/tools/souffle-export.py
deleted file mode 100644
index a04d966..0000000
--- a/src/ee/tools/souffle-export.py
+++ /dev/null
@@ -1,57 +0,0 @@
-import argparse
-import csv
-import os.path
-from pathlib import Path
-
-import ee.tools
-from ee.part import load_db, Part
-
-
-def run(args):
- print_header = False
-
- part_db = Path(args.part_db)
- out_dir = part_db.parent / "{}.{}".format(os.path.splitext(part_db.name)[0], "souffle")
-
- if not out_dir.is_dir():
- ee.tools.mk_dirs(out_dir)
-
- with open(out_dir / "facts.dl", "w") as f:
- print(".decl part(uri:symbol, ref:symbol, supplier:symbol)", file=f)
- print(".input part", file=f)
- print("", file=f)
- print(".decl fact(part_uri:symbol, key:symbol, value:symbol)", file=f)
- print(".input fact", file=f)
-
- with open(out_dir / "part.facts", "w") as part_f:
- with open(out_dir / "fact.facts", "w") as fact_f:
- part_csv = csv.writer(part_f, dialect="excel-tab")
- if print_header:
- part_csv.writerow(["uri", "ref", "supplier"])
-
- fact_csv = csv.writer(fact_f, dialect="excel-tab")
- if print_header:
- fact_csv.writerow(["part_uri", "key", "value"])
-
- for xml in load_db(part_db).iterparts():
- p = Part(xml)
- sch_ref = p.get_only_schematic_reference()
- part_csv.writerow([p.uri, sch_ref.referenceProp if sch_ref else None, p.supplier])
-
- for fact in p.get_facts():
- fact_csv.writerow([p.uri, fact.keyProp, fact.valueProp])
-
-
-import ee.tools
-
-parser = argparse.ArgumentParser()
-ee.tools.add_default_argparse_group(parser)
-
-parser.add_argument("--part-db",
- required=True,
- metavar="PART DB")
-
-args = parser.parse_args()
-ee.tools.process_default_argparse_group(args)
-
-run(args)