aboutsummaryrefslogtreecommitdiff
path: root/trygvis/eda/digikey/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'trygvis/eda/digikey/__init__.py')
-rw-r--r--trygvis/eda/digikey/__init__.py63
1 files changed, 42 insertions, 21 deletions
diff --git a/trygvis/eda/digikey/__init__.py b/trygvis/eda/digikey/__init__.py
index 8fe18c8..2f93858 100644
--- a/trygvis/eda/digikey/__init__.py
+++ b/trygvis/eda/digikey/__init__.py
@@ -7,7 +7,7 @@ from cachecontrol.caches.file_cache import FileCache
from cachecontrol.heuristics import ExpiresAfter
from lxml import html
from rdflib import Literal
-from rdflib.namespace import RDF, RDFS
+from rdflib.namespace import RDF, RDFS, OWL
import trygvis.eda.digikey.rdf
@@ -41,8 +41,8 @@ class DigikeyDatabase(object):
return sc
return None
- def merge_attribute_types(self, attributeTypes):
- for a in attributeTypes:
+ def merge_attribute_types(self, attribute_types):
+ for a in attribute_types:
if a.id in self.attributeTypes:
# TODO: implement merging
continue
@@ -78,11 +78,12 @@ class DigikeyProductCategory(object):
node = self.url()
nodes = [
(node, RDF.type, rdf.DIGIKEY.productCategory),
+ # (node, RDF.type, OWL.Class),
(node, RDFS.label, Literal(self.label)),
]
if self.parent is not None:
- parentUrl = rdf.DIGIKEY_PRODUCT_CATEGORY[self.parent.id]
- nodes.append((node, rdf.DIGIKEY.parent, parentUrl))
+ parent_url = rdf.DIGIKEY_PRODUCT_CATEGORY[self.parent.id]
+ nodes.append((node, rdf.DIGIKEY.parent, parent_url))
if self.digikey_url is not None:
nodes.append((node, rdf.DIGIKEY.url, Literal(self.digikey_url)))
return nodes
@@ -101,17 +102,34 @@ class DigikeyAttributeType(object):
assert self.options is not None
def to_nodes(self):
- nodes = []
node = rdf.DIGIKEY_ATTRIBUTE_TYPE[self.id]
- nodes.append((node, RDF.type, rdf.DIGIKEY.attributeType))
- nodes.append((node, RDFS.label, Literal(self.label)))
+ node_value = rdf.DIGIKEY_ATTRIBUTE_TYPE[self.id + "-value"]
+ node_option = rdf.DIGIKEY_ATTRIBUTE_TYPE[self.id + "-option"]
+ nodes = [
+ (node, RDF.type, rdf.DIGIKEY.attributeType),
+ (node, RDF.type, OWL.Class),
+ (node, RDFS.subClassOf, rdf.DIGIKEY['AttributeType']),
+ (node, RDFS.label, Literal(self.label)),
+
+ (node_option, RDF.type, OWL.ObjectProperty),
+ (node_option, RDFS.domain, node),
+ (node_option, RDFS.range, node_value),
+ (node_option, RDFS.label, Literal('Options for ' + self.label)),
+
+ (node_value, RDF.type, OWL.Class),
+ (node_value, RDFS.subClassOf, rdf.DIGIKEY['AttributeValue']),
+ (node_value, RDFS.label, Literal(self.label + ' values')),
+ ]
for o in self.options:
- optionNode = rdf.DIGIKEY_ATTRIBUTE_VALUE[self.id + '-' + o.id]
+ option_node = rdf.DIGIKEY_ATTRIBUTE_VALUE[self.id + '-' + o.id]
nodes.extend([
- (optionNode, rdf.DIGIKEY.id, Literal(o.id)),
- (optionNode, RDFS.label, Literal(o.label)),
- (node, rdf.DIGIKEY.value, optionNode)])
+ (option_node, RDF.type, OWL.Class),
+ (option_node, RDFS.subClassOf, node_value),
+ (option_node, rdf.DIGIKEY.id, Literal(o.id)),
+ (option_node, RDFS.label, Literal(o.label)),
+ # (node, rdf.DIGIKEY.value, option_node)])
+ (node, node_option, option_node)])
return nodes
@@ -190,17 +208,20 @@ def download_category_tree(database: DigikeyDatabase, client: DigikeyClient,
for h2 in items:
label = _to_string(h2)
# print(h2)
- pcId = None
+ if not label == 'Resistors':
+ continue
+
+ pc_id = None
for a in h2.getchildren():
url = a.get('href')
- pcId = _id_from_url(url)
- if pcId is None:
+ pc_id = _id_from_url(url)
+ if pc_id is None:
continue
- if pcId is None:
+ if pc_id is None:
continue
- pc = DigikeyProductCategory(pcId, label)
+ pc = DigikeyProductCategory(pc_id, label)
n = h2.getnext()
if n.tag == 'span':
n = n.getnext()
@@ -230,13 +251,13 @@ def download_attribute_types_from_category(category: DigikeyProductCategory, cli
td = select.getparent()
index = td.getparent().index(td)
try:
- attributeLabel = headers[index]
+ attribute_label = headers[index]
except:
continue
- attributeId = select.get('name')
- print("label: " + attributeLabel + ", id: " + attributeId)
+ attribute_id = select.get('name')
+ print("label: " + attribute_label + ", id: " + attribute_id)
options = []
- type = DigikeyAttributeType(category, attributeId, attributeLabel, options)
+ type = DigikeyAttributeType(category, attribute_id, attribute_label, options)
for o in select.xpath("./option"):
id = o.get('value')
label = _to_string(o)