diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-06-12 21:53:26 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-06-12 21:53:26 +0200 |
commit | b2e87255d3d51956dc5da440e535ce2cee5c6f5b (patch) | |
tree | 903d5497c09e706a4c30e7b67c3624dbf0137cd2 | |
parent | aa6697f9d669c821896c26bc8597ed68c79619c5 (diff) | |
download | ee-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.
-rw-r--r-- | src/ee/souffle/digikey.dl | 7 | ||||
-rw-r--r-- | src/ee/souffle/kicad.dl | 13 | ||||
-rw-r--r-- | src/ee/tools/part_apply_souffle_post.py | 9 | ||||
-rw-r--r-- | src/ee/tools/part_apply_souffle_pre.py | 2 | ||||
-rw-r--r-- | src/ee/tools/souffle-export.py | 57 |
5 files changed, 14 insertions, 74 deletions
diff --git a/src/ee/souffle/digikey.dl b/src/ee/souffle/digikey.dl index 5073e4d..e168db9 100644 --- a/src/ee/souffle/digikey.dl +++ b/src/ee/souffle/digikey.dl @@ -1,6 +1,7 @@ #include "facts.dl" -.output fact +.decl add_fact(part_uri:symbol, key:symbol, value:symbol) +.output add_fact #define RESISTANCE "http://purl.org/ee/digikey-fact-key#2085" #define CAPACITANCE "http://purl.org/ee/digikey-fact-key#2049" @@ -31,7 +32,7 @@ dk_to_ipc("0805 (2012 Metric)", "2012"). dk_to_ipc("1206 (3216 Metric)", "3216"). dk_to_ipc("1812 (4532 Metric)", "4532"). -fact(part, "http://purl.org/ee/fact-type/footprint", ipc) :- +add_fact(part, "http://purl.org/ee/fact-type/footprint", ipc) :- fact(part, "http://purl.org/ee/digikey-fact-key#16", dk), dk_to_ipc(dk, ipc). @@ -41,6 +42,6 @@ supplier_device_package_to_footprint("Mini-Dip (TO-269AA)", "TO-269AA"). supplier_device_package_to_footprint("SMA (DO-214AC)", "SMA"). supplier_device_package_to_footprint("SOD-323", "SOD-323"). -fact(part, "http://purl.org/ee/fact-type/footprint", footprint) :- +add_fact(part, "http://purl.org/ee/fact-type/footprint", footprint) :- fact(part, SUPPLIER_DEVICE_PACKAGE, dk), supplier_device_package_to_footprint(dk, footprint). diff --git a/src/ee/souffle/kicad.dl b/src/ee/souffle/kicad.dl index f176dd4..ed9bf4a 100644 --- a/src/ee/souffle/kicad.dl +++ b/src/ee/souffle/kicad.dl @@ -1,7 +1,8 @@ #include "facts.dl" #include "kicad-mpn.dl" -.output fact +.decl add_fact(part_uri:symbol, key:symbol, value:symbol) +.output add_fact /* .decl is_resistor(uri:symbol) @@ -31,15 +32,15 @@ capacitor_lib("Capacitor_SMD"). .decl inductor_lib(name:symbol) inductor_lib("Inductor_SMD"). -fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#resistor") :- +add_fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#resistor") :- resistor_lib(lib), fact(Ref, "http://purl.org/ee/kicad-sch-fact-type#footprint-library", lib). -fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#capacitor") :- +add_fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#capacitor") :- capacitor_lib(lib), fact(Ref, "http://purl.org/ee/kicad-sch-fact-type#footprint-library", lib). -fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#inductor") :- +add_fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#inductor") :- inductor_lib(lib), fact(Ref, "http://purl.org/ee/kicad-sch-fact-type#footprint-library", lib). @@ -53,7 +54,7 @@ net_tie_symbol("Device", "Net-Tie_3_Tee"). net_tie_symbol("Device", "Net-Tie_4"). net_tie_symbol("Device", "Net-Tie_4_Cross"). -fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#net-tie") :- +add_fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#net-tie") :- net_tie_symbol(lib, name), fact(Ref, "http://purl.org/ee/kicad-sch-fact-type#symbol-library", lib), fact(Ref, "http://purl.org/ee/kicad-sch-fact-type#symbol-name", name). @@ -65,7 +66,7 @@ test_point_symbol("Connector", "TestPoint_Alt"). test_point_symbol("Connector", "TestPoint_Flag"). test_point_symbol("Connector", "TestPoint_Probe"). -fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#test-point") :- +add_fact(Ref, "http://purl.org/ee/fact-type/ee-component-type", "http://purl.org/ee/part-type#test-point") :- test_point_symbol(lib, name), fact(Ref, "http://purl.org/ee/kicad-sch-fact-type#symbol-library", lib), fact(Ref, "http://purl.org/ee/kicad-sch-fact-type#symbol-name", name). 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) |