aboutsummaryrefslogtreecommitdiff
path: root/trygvis/eda/cli
diff options
context:
space:
mode:
Diffstat (limited to 'trygvis/eda/cli')
-rw-r--r--trygvis/eda/cli/__init__.py8
-rwxr-xr-xtrygvis/eda/cli/digikey_download_metadata.py13
2 files changed, 17 insertions, 4 deletions
diff --git a/trygvis/eda/cli/__init__.py b/trygvis/eda/cli/__init__.py
index 422cf48..3807fb3 100644
--- a/trygvis/eda/cli/__init__.py
+++ b/trygvis/eda/cli/__init__.py
@@ -5,13 +5,14 @@ from os import mkdir
from os.path import dirname, isdir
from typing import Callable
-from rdflib import store, ConjunctiveGraph, Graph, RDF, RDFS
+from rdflib import store, ConjunctiveGraph, Graph, RDF, RDFS, OWL
from rdflib.plugins.sparql import prepareQuery
import rdflib.plugins.stores.sparqlstore as sparqlstore
import configparser
# noinspection PyUnresolvedReferences
import argparse
+from .. import EDA
from ..digikey import rdf as digikey_rdf
from ..kicad import rdf as kicad_rdf
@@ -84,6 +85,9 @@ def with_database(tx):
def create_graph(digikey=False, kicad=False) -> Graph:
g = Graph()
+ g.bind("owl", OWL)
+ g.bind("eda", EDA)
+
if digikey:
g.bind("dk", digikey_rdf.DIGIKEY)
g.bind("dk-part", digikey_rdf.DIGIKEY_PART)
@@ -124,6 +128,8 @@ def write_graph(gen_g: Callable[[], Graph], filename: str = None, force_write: b
_initNs = {
"rdf": RDF,
"rdfs": RDFS,
+ "owl": OWL,
+ "eda": EDA,
"dk": digikey_rdf.DIGIKEY,
"dk-attr-type": digikey_rdf.DIGIKEY_ATTRIBUTE_TYPE,
"dk-attr-value": digikey_rdf.DIGIKEY_ATTRIBUTE_VALUE,
diff --git a/trygvis/eda/cli/digikey_download_metadata.py b/trygvis/eda/cli/digikey_download_metadata.py
index 60880ab..59c8099 100755
--- a/trygvis/eda/cli/digikey_download_metadata.py
+++ b/trygvis/eda/cli/digikey_download_metadata.py
@@ -1,4 +1,6 @@
-from trygvis.eda import cli
+from rdflib.term import URIRef
+
+from trygvis.eda import cli, EDA
from trygvis.eda.digikey import *
@@ -19,11 +21,15 @@ def do_categories(db: DigikeyDatabase, client: DigikeyClient, output: str):
def do_category(client: DigikeyClient, sc: DigikeyProductCategory, output: str):
- cli.info('Downloading categories for %s' % sc.label)
+ cli.info('Downloading attributes for %s' % sc.label)
def make_graph():
attributes = download_attribute_types_from_category(sc, client)
- g = cli.create_graph()
+ g = cli.create_graph(digikey=True)
+
+ g.add((sc.url(), RDF.type, OWL.Ontology))
+ g.add((sc.url(), OWL.imports, URIRef(rdf.DIGIKEY)))
+
for a in attributes:
[g.add(node) for node in a.to_nodes()]
@@ -31,6 +37,7 @@ def do_category(client: DigikeyClient, sc: DigikeyProductCategory, output: str):
cli.write_graph(make_graph, output, force_write=True)
+
def run(args):
db = DigikeyDatabase()
client = DigikeyClient()