Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support QUDT #1964

Closed
wants to merge 3 commits into from
Closed

support QUDT #1964

wants to merge 3 commits into from

Conversation

andrewgsavage
Copy link
Collaborator

  • Closes # (insert issue number)
  • Executed pre-commit run --all-files with no errors
  • The change is fully covered by automated unit tests
  • Documented in docs/ as appropriate
  • Added an entry to the CHANGES file

Started writing a parser for QUDT. QUDT has defined 1100 quantitykinds, which are like the 'kind' previously discussed in pint #676. There's also a load of metadata for the quantitykind and units:

quantitykind and unit examples

.
unit:A
a qudt:Unit ;
dcterms:description """$\textit{Ampere}$, often shortened to $\text{amp}$,
is the SI unit of electric current and is one of the seven SI base units defined as:

$$\text{A} \equiv \frac{\textit{C}}{\textit{s}}
\equiv \frac{\textit{coulomb}}{\textit{second}}
\equiv \frac{\text{joule}}{\text{weber}}$$

Note that SI supports only the use of symbols and deprecates the use of any abbreviations for units.
"""^^qudt:LatexString ;
qudt:applicableSystem sou:CGS-EMU ;
qudt:applicableSystem sou:CGS-GAUSS ;
qudt:applicableSystem sou:PLANCK ;
qudt:applicableSystem sou:SI ;
qudt:conversionMultiplier 1.0 ;
qudt:conversionMultiplierSN 1.0E0 ;
qudt:dbpediaMatch "http://dbpedia.org/resource/Ampere"^^xsd:anyURI ;
qudt:hasDimensionVector qkdv:A0E1L0I0M0H0T0D0 ;
qudt:hasQuantityKind quantitykind:CurrentLinkage ;
qudt:hasQuantityKind quantitykind:DisplacementCurrent ;
qudt:hasQuantityKind quantitykind:ElectricCurrent ;
qudt:hasQuantityKind quantitykind:ElectricCurrentPhasor ;
qudt:hasQuantityKind quantitykind:MagneticTension ;
qudt:hasQuantityKind quantitykind:MagnetomotiveForce ;
qudt:hasQuantityKind quantitykind:TotalCurrent ;
qudt:iec61360Code "0112/2///62720#UAA101" ;
qudt:iec61360Code "0112/2///62720#UAD717" ;
qudt:informativeReference "http://en.wikipedia.org/wiki/Ampere?oldid=494026699"^^xsd:anyURI ;
qudt:omUnit http://www.ontology-of-units-of-measure.org/resource/om-2/ampere ;
qudt:siExactMatch si-unit:ampere ;
qudt:symbol "A" ;
qudt:ucumCode "A"^^qudt:UCUMcs ;
qudt:udunitsCode "A" ;
qudt:uneceCommonCode "AMP" ;
rdfs:isDefinedBy http://qudt.org/2.1/vocab/unit ;
rdfs:label "Ampere"@de ;
rdfs:label "amper"@hu ;
rdfs:label "amper"@pl ;
rdfs:label "amper"@ro ;
rdfs:label "amper"@sl ;
rdfs:label "amper"@tr ;
rdfs:label "ampere"@en ;
rdfs:label "ampere"@it ;
rdfs:label "ampere"@ms ;
rdfs:label "ampere"@pt ;
rdfs:label "amperio"@es ;
rdfs:label "amperium"@LA ;
rdfs:label "ampère"@fr ;
rdfs:label "ampér"@cs ;
rdfs:label "αμπέρ"@el ;
rdfs:label "ампер"@bg ;
rdfs:label "ампер"@ru ;
rdfs:label "אמפר"@he ;
rdfs:label "آمپر"@fa ;
rdfs:label "أمبير"@ar ;
rdfs:label "एम्पीयर"@hi ;
rdfs:label "アンペア"@ja ;
rdfs:label "安培"@zh ;
skos:altLabel "amp" ;
.

#################################

quantitykind:Acceleration
a qudt:QuantityKind ;
dcterms:description "Acceleration is the (instantaneous) rate of change of velocity. Acceleration may be either linear acceleration, or angular acceleration. It is a vector quantity with dimension \(length/time^{2}\) for linear acceleration, or in the case of angular acceleration, with dimension \(angle/time^{2}\). In SI units, linear acceleration is measured in \(meters/second^{2}\) (\(m \cdot s^{-2}\)) and angular acceleration is measured in \(radians/second^{2}\). In physics, any increase or decrease in speed is referred to as acceleration and similarly, motion in a circle at constant speed is also an acceleration, since the direction component of the velocity is changing."^^qudt:LatexString ;
qudt:applicableUnit unit:CentiM-PER-SEC2 ;
qudt:applicableUnit unit:FT-PER-SEC2 ;
qudt:applicableUnit unit:G ;
qudt:applicableUnit unit:GALILEO ;
qudt:applicableUnit unit:IN-PER-SEC2 ;
qudt:applicableUnit unit:KN-PER-SEC ;
qudt:applicableUnit unit:KiloM-PER-SEC2 ;
qudt:applicableUnit unit:KiloPA-M2-PER-GM ;
qudt:applicableUnit unit:M-PER-SEC2 ;
qudt:applicableUnit unit:MI_US-PER-SEC2 ;
qudt:applicableUnit unit:MicroG ;
qudt:applicableUnit unit:MilliG ;
qudt:applicableUnit unit:MilliGAL ;
qudt:applicableUnit unit:MilliM-PER-SEC2 ;
qudt:applicableUnit unit:YD-PER-SEC2 ;
qudt:dbpediaMatch "http://dbpedia.org/resource/Acceleration"^^xsd:anyURI ;
qudt:exactMatch quantitykind:LinearAcceleration ;
qudt:hasDimensionVector qkdv:A0E0L1I0M0H0T-2D0 ;
qudt:iec61360Code "0112/2///62720#UAD002" ;
qudt:informativeReference "http://en.wikipedia.org/wiki/Acceleration"^^xsd:anyURI ;
qudt:siExactMatch si-quantity:ACCE ;
rdfs:isDefinedBy http://qudt.org/2.1/vocab/quantitykind ;
rdfs:label "Beschleunigung"@de ;
rdfs:label "Pecutan"@ms ;
rdfs:label "Zrychlení"@cs ;
rdfs:label "acceleratio"@LA ;
rdfs:label "acceleration"@en ;
rdfs:label "accelerazione"@it ;
rdfs:label "accelerație"@ro ;
rdfs:label "accélération"@fr ;
rdfs:label "aceleración"@es ;
rdfs:label "aceleração"@pt ;
rdfs:label "ivme"@tr ;
rdfs:label "pospešek"@sl ;
rdfs:label "przyspieszenie"@pl ;
rdfs:label "Όγκος"@el ;
rdfs:label "Ускоре́ние"@ru ;
rdfs:label "التسارع"@ar ;
rdfs:label "شتاب"@fa ;
rdfs:label "त्वरण"@hi ;
rdfs:label "加速度"@ja ;
rdfs:label "加速度"@zh ;
.

I think Quantitykind definition can be split into another PR to make things smaller.

Not sure what the best way to right tests for parsing files is either.

The QUDT data is updated regularly, so would need to be downloaded rather than be saved in pint, which would need an optional dependency like requests - Should I add code for downloading files to this?

Would be good to get @hgrecco 's thoughts on the parsing (I've mostly copied pint and adapted as needed so far)
I wonder if it would be possible/better to change the delimiter to "\n.\n" or something instead of using a block?
Also unsure on how to deal with multiline strings

todo:

  • parse units
  • offset units
  • log units
  • quantitykind definition
  • parse quantitykind
  • quantitykind method/interactions on quantity, eg quantity.kind()
  • parse systems

I'm interested in what functionality quantitykind will allow.

@dalito
Copy link
Contributor

dalito commented Apr 7, 2024

Cool. Connecting pint to unit ontologies is something I also thought about but never had the time to work on.
Your main idea here would be to replace/extend definitions based on the qudt ontology data?
Could you not use an existing parser for rdf like rdflib? Would this be a too big dependency?

Have you already thought about how to add quantity kinds to pint? I understand that it will be in another PR.

@andrewgsavage
Copy link
Collaborator Author

Cool. Connecting pint to unit ontologies is something I also thought about but never had the time to work on. Your main idea here would be to replace/extend definitions based on the qudt ontology data?

I have made a parser like the default one for default_en.txt, that parses the qudt files into an empty UnitRegistry - so not compatable with existing pint defintions.

Could you not use an existing parser for rdf like rdflib? Would this be a too big dependency?

Possibly, didn't know about rdf to look into this! flexparser is quite good for this and I can structure it very similiarly to pint's default parser

Have you already thought about how to add quantity kinds to pint? I understand that it will be in another PR.

I mean to say I can split that into a PR seperate from the parsing of QUDT and such here. For now both are in this PR.

I haven't thought on it much, it would be good to get your thoughts. My thoughts so far:

We could have a Quantitykind class subclassing from Quantity, or just have a Quantity class with a property for the quantitykind.

>>> power= Q_(1, "W")
>>> power.show_unit_quantitykinds()
['ActivePower', 'Power']
A0E0L2I0M1H0T-3D0
>>> power.show_dimension_quantitykinds()
['ActivePower', 'ApparentPower', 'ComplexPower', 'ExhaustStreamPower', 'Power', 'ConvectiveHeatTransfer', 'ConvectiveHeatTransfer'... ]
>>> power.to_quantitykind("ActivePower") 
<Quantitykind(1, 'W', 'ActivePower')>

I would like to be able to do

>>> Quantitykind(1, 'W', 'ApparentPower') * Quantitykind(1, '', 'PowerFactor') 
<Quantitykind(1, 'meter', 'ActivePower')>

but I don't think information is stored anywhere

@andrewgsavage
Copy link
Collaborator Author

yea rdflib looks like a better way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants