kitspace / electro-grammar

:zap: A parser for electronic component descriptions
https://kitspace.github.io/electro-grammar/
MIT License
276 stars 13 forks source link

tolerance should apply to previous unit #2

Open dvc94ch opened 6 years ago

dvc94ch commented 6 years ago

the grammar should be:

range : unit tolerance? unit : voltage | current | power | resistance | capacitance | inductance | frequency

kasbah commented 6 years ago

I think we have a bit of a conflict here between our "NLP" use cases (search, BOM creation) and our circuit HDL use cases. For the HDLs we want the clearest description but for search we want to extract as much info as possible.

For search I definitely want to parse 10uF 0603 10% as a 10% tolerance on capacitance. What to do for HDLs, I am not sure. The best thing for those cases maybe to lint and format the user input to be less ambiguous.

Are you thinking of use cases where you specify multiple tolerances on different units? What cases are you thinking of exactly?

dvc94ch commented 6 years ago

Maybe there isn't a use case. I think it makes it more readable and makes sense though.

Do you have any real world "NLP" examples where it is actually specified like that? And is a parsing framework the right tool for NLP processing? Wouldn't a NLP framework be more suited? (I'm not familiar with NLP concepts or terminology)

kasbah commented 6 years ago

Sure, I agree with you, but for search we don't care about that. For other applications it would be fairly easy to make a formatting function:

> format('0603 10% 1u capacitor for decoupling') 
'capacitor 1uF 10% 0603'

I have seen the specs rattled off in any old order all over the place really. Here is a capacitor description from Farnell: SMD Multilayer Ceramic Capacitor, 1210 [3225 Metric], 0.47 µF, 200 V, ± 10%, X7R, MC Series.

I think the existing implementation is a good proof of concept that a formal grammar approach can work well for this very limited subset of "natural language". I have been looking a bit at the implementation of Duckling and while they don't use a grammar DSL the "rules" they use seem very grammar-like. This is my first foray into this kind of parsing as well though.