aboutsummaryrefslogtreecommitdiff
path: root/trygvis
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-12-28 15:46:01 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2016-12-28 15:46:01 +0100
commit8c90d2e409e9c457a8e27fc11d8e030248eb6f70 (patch)
tree4d1cb0a85adc0c33700e80a643f688af4ae0f4fe /trygvis
parentdb85189ea87b214d3649138fcd943a942bf8c530 (diff)
downloadeda-rdf-8c90d2e409e9c457a8e27fc11d8e030248eb6f70.tar.gz
eda-rdf-8c90d2e409e9c457a8e27fc11d8e030248eb6f70.tar.bz2
eda-rdf-8c90d2e409e9c457a8e27fc11d8e030248eb6f70.tar.xz
eda-rdf-8c90d2e409e9c457a8e27fc11d8e030248eb6f70.zip
o Modernized digikey-download-for-schematic so that it works against the remote SPARQL endpoint.
Diffstat (limited to 'trygvis')
-rwxr-xr-xtrygvis/eda/cli/digikey_download_for_schematic.py67
1 files changed, 10 insertions, 57 deletions
diff --git a/trygvis/eda/cli/digikey_download_for_schematic.py b/trygvis/eda/cli/digikey_download_for_schematic.py
index 0cb5baa..4be2632 100755
--- a/trygvis/eda/cli/digikey_download_for_schematic.py
+++ b/trygvis/eda/cli/digikey_download_for_schematic.py
@@ -1,22 +1,8 @@
-from rdflib.plugins.sparql import prepareQuery
import rdflib
import rdflib.term
from trygvis.eda import cli
from trygvis.eda.digikey import *
-from trygvis.eda.digikey import rdf as digikey_rdf
-from trygvis.eda.kicad import rdf as kicad_rdf
-
-initNs = {
- "rdf": rdflib.RDF,
- "rdfs": rdflib.RDFS,
- "dk": digikey_rdf.DIGIKEY,
- "dk-attr-type": digikey_rdf.DIGIKEY_ATTRIBUTE_TYPE,
- "dk-attr-value": digikey_rdf.DIGIKEY_ATTRIBUTE_VALUE,
- "dk-part": digikey_rdf.DIGIKEY_PART,
- "dk-p-c": digikey_rdf.DIGIKEY_PRODUCT_CATEGORY,
- "kicad": kicad_rdf.KICAD,
- "kicad-type": kicad_rdf.KICAD_TYPE}
def work(schematic_url, g):
@@ -37,17 +23,17 @@ def work(schematic_url, g):
# for row in g.query(allComponentsQ, initBindings={'schematic_url': schematic_url}):
# print("ref=%s, value=%s" % (row.ref, row.value))
- res = g.query(prepareQuery("SELECT ?schematic WHERE {?schematic a kicad-type:schematic}", initNs=initNs))
+ res = cli.sparql(g, "SELECT ?schematic WHERE {?schematic a kicad-type:schematic}")
print("Found %d schematics in database" % len(res))
for row in res:
print("schematic: %s" % row.schematic)
- res = g.query(prepareQuery("SELECT ?dk_part ?dk_part_number WHERE {?dk_part a dk:part ; dk:partNumber ?dk_part_number}", initNs=initNs))
+ res = cli.sparql(g, "SELECT ?dk_part ?dk_part_number WHERE {?dk_part a dk:part ; dk:partNumber ?dk_part_number}")
print("Found %d Digikey parts in database" % len(res))
for row in res:
print("Part: url=%s, partNumber=%s" % (row.dk_part, row.dk_part_number))
- q = prepareQuery("""
+ res = cli.sparql(g, """
SELECT
?digikey_pn
(group_concat(distinct ?ref;separator=";") as ?refs)
@@ -59,17 +45,20 @@ WHERE {
?cmp kicad:field ?d .
?d kicad:field_name "digikey" ;
kicad:field_value ?digikey_pn .
-# OPTIONAL {
+ OPTIONAL {
?dk_part a dk:part ;
dk:partNumber ?digikey_pn .
-# }
+ }
}
}
GROUP BY ?digikey_pn
ORDER BY ?digikey_pn
-""", initNs=initNs)
+""", init_bindings={'schematic_url': rdflib.term.URIRef(schematic_url)})
+ size = len(res)
+
+ if size == 0:
+ cli.info('Could not find an parts for the schematic, did you use the correct URL: %s?' % schematic_url)
- res = g.query(q, initBindings={'schematic_url': rdflib.term.URIRef(schematic_url)})
for row in res:
pn = row.digikey_pn
@@ -92,42 +81,6 @@ ORDER BY ?digikey_pn
cli.write_graph(download_graph, filename)
- # q = prepareQuery("""
- # SELECT
- # DISTINCT ?category ?digikeyUrl
- # WHERE {
- # ?schematic_url kicad:component ?cmp .
- # ?cmp rdfs:label ?ref .
- # ?cmp kicad:value ?value .
- # ?cmp kicad:field ?d .
- # ?d kicad:field_name "digikey" .
- # ?d kicad:field_value ?digikey .
- #
- # ?part a dk:part .
- # ?part dk:partNumber ?digikey .
- # ?part dk:category ?category .
- # ?category dk:parent ?_ .
- # ?category dk:url ?digikeyUrl
- # }""", initNs=initNs)
- #
- # res = g.query(q, initBindings={'schematic_url': schematic_url})
- #
- # cli.info("Found %d categories" % (len(res)))
- # for row in res:
- # cli.info("Category: %s" % (row.category))
- # category = db.findSubCategoryByUrl(row.category)
- # if category is None:
- # raise Exception('could not find category: ' + row.category)
- # attributes = downloadAttributeTypesFromCategory(category, client)
- # db.mergeAttributeTypes(attributes)
- #
- # filename = 'digikey-category-' + normalize_filename(str(category.label) + ".ttl")
- # if not isfile(filename):
- # tmpG = cli.create_graph()
- # for a in attributes:
- # [tmpG.add(node) for node in a.toNodes()]
- # writeGraph(tmpG, 'ttl/' + filename)
-
def run(schematic_url, args):
cli.info("Schematic: %s" % schematic_url)