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

Fix/add missing triples #90

Merged
merged 9 commits into from
Feb 20, 2024
13 changes: 12 additions & 1 deletion qudtlib-data-gen/src/main/resources/add-to-quantitykinds.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ quantitykind:WaterVaporDiffusionCoefficient a qudt:QuantityKind;
qudt:hasDimensionVector <http://qudt.org/vocab/dimensionvector/A0E0L0I0M0H0T1D0>;
rdfs:label "Wasserdampfdiffusionsleitkoeffizient"@de, "Water vapour diffusion coefficient"@en;
qudt:informativeReference "https://www.wufi-wiki.com/mediawiki/index.php/Details:WaterVaporDiffusion"^^<http://www.w3.org/2001/XMLSchema#anyURI>;
qudt:plainTextDescription "The Water vapour diffusion coefficient describes how easy vapor diffusion happens in a given material." .
qudt:plainTextDescription "The Water vapour diffusion coefficient describes how easy vapor diffusion happens in a given material." ;
qudt:applicableUnit unit:KiloGM-PER-PA-SEC-M .

quantitykind:ThermalInsulance qudt:applicableUnit unit:M2-K-PER-W .

quantitykind:Area qudt:applicableUnit unit:KiloM2 .

quantitykind:SecondMomentOfArea qudt:applicableUnit unit:CentiM4 .

quantitykind:SecondPolarMomentOfArea qudt:applicableUnit unit:CentiM4 .

quantitykind:SecondAxialMomentOfArea qudt:applicableUnit unit:CentiM4 .
32 changes: 26 additions & 6 deletions qudtlib-data-gen/src/main/resources/add-to-units.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
@prefix quantitykind: <http://qudt.org/vocab/quantitykind/> .
@prefix prefix: <http://qudt.org/vocab/prefix/> .

quantitykind:WaterVaporDiffusionCoefficient a qudt:QuantityKind;
rdfs:isDefinedBy <http://qudt.org/2.1/vocab/quantitykind>;
qudt:hasDimensionVector <http://qudt.org/vocab/dimensionvector/A0E0L0I0M0H0T1D0>;
rdfs:label "Wasserdampfdiffusionsleitkoeffizient"@de, "Water vapour diffusion coefficient"@en;
qudt:informativeReference "https://www.wufi-wiki.com/mediawiki/index.php/Details:WaterVaporDiffusion"^^<http://www.w3.org/2001/XMLSchema#anyURI>;
qudt:plainTextDescription "The Water vapour diffusion coefficient describes how easy vapor diffusion happens in a given material." .

unit:KiloGM-PER-PA-SEC-M a qudt:Unit;
rdfs:isDefinedBy <http://qudt.org/2.1/vocab/unit>;
Expand Down Expand Up @@ -42,3 +36,29 @@ unit:M2-K-PER-W a qudt:Unit;
"метрквадратный -кельвин на ватт"@ru, " kwadratowymetrokelwin na wat"@pl;
qudt:informativeReference "https://en.wikipedia.org/wiki/R-value_(insulation)"^^<http://www.w3.org/2001/XMLSchema#anyURI>;
qudt:plainTextDescription "Common unit for the R-Value. In the context of construction, the R-value is a measure of how well a two-dimensional barrier, such as a layer of insulation, a window or a complete wall or ceiling, resists the conductive flow of heat." .


unit:KiloM2 a qudt:Unit;
rdfs:isDefinedBy <http://qudt.org/2.1/vocab/unit>;
qudt:applicableSystem sou:SI;
qudt:hasQuantityKind quantitykind:Area;
qudt:conversionMultiplier 1000000.0;
qudt:hasDimensionVector <http://qudt.org/vocab/dimensionvector/A0E0L2I0M0H0T0D0>;
qudt:symbol "km²";
qudt:ucumCode "km2"^^qudt:UCUMcs;
rdfs:label "square Kilometre"@en;
qudt:prefix prefix:Kilo;
qudt:plainTextDescription "A unit of area equal to that of a square of sides 1000 m." .

unit:CentiM4 a qudt:Unit;
rdfs:isDefinedBy <http://qudt.org/2.1/vocab/unit>;
qudt:applicableSystem sou:SI;
qudt:hasQuantityKind quantitykind:SecondMomentOfArea, quantitykind:SecondPolarMomentOfArea,
quantitykind:SecondAxialMomentOfArea;
qudt:conversionMultiplier 0.00000001;
qudt:hasDimensionVector <http://qudt.org/vocab/dimensionvector/A0E0L4I0M0H0T0D0>;
qudt:symbol "cm⁴";
qudt:ucumCode "cm4"^^qudt:UCUMcs;
rdfs:label "quartic Centimetre"@en;
qudt:prefix prefix:Centi;
qudt:plainTextDescription "0.01-fold of the SI base unit metre with the exponent 4" .
14 changes: 12 additions & 2 deletions qudtlib-model/src/main/java/io/github/qudtlib/model/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,12 @@ protected Unit(Definition definition) {
BigDecimal multiplier =
this.prefix == null
? definition.conversionMultiplier
: this.prefix.getMultiplier();
: this.prefix
.getMultiplier()
.pow(fu.getFactorUnits().get(0).getExponent());
FactorUnits fuForSclaingOf =
FactorUnits.ofFactorUnitSpec(multiplier, this.scalingOf, 1);
if (!fu.equals(fuForSclaingOf)) {
if (!fu.normalize().equals(fuForSclaingOf.normalize())) {
throw new IllegalArgumentException(
String.format(
"Unit %s has conflicting definition of factor units (%s) and scalingOf (%s, which implies factor units %s)",
Expand Down Expand Up @@ -456,6 +458,10 @@ public boolean matches(FactorUnits factorUnits) {
}

public boolean hasFactorUnits() {
if (this.factorUnits == null) {
// defensive check for calculations during instantiation
return false;
}
return this.factorUnits.hasFactorUnits();
}

Expand All @@ -474,6 +480,10 @@ public FactorUnits normalize() {
} else if (this.isScaled()) {
return this.scalingOf.normalize().scale(this.getConversionMultiplier(this.scalingOf));
}
if (this.factorUnits == null) {
// defensive branch for use during initialization
return FactorUnits.ofUnit(this);
}
return this.factorUnits;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ public void writeOut(
writer.startRDF();
writer.handleNamespace(
QudtNamespaces.qudt.getAbbreviationPrefix(), QudtNamespaces.qudt.getBaseIri());
writer.handleNamespace(
QudtNamespaces.prefix.getAbbreviationPrefix(), QudtNamespaces.prefix.getBaseIri());
writer.handleNamespace(
QudtNamespaces.unit.getAbbreviationPrefix(), QudtNamespaces.unit.getBaseIri());
writer.handleNamespace(
QudtNamespaces.systemOfUnits.getAbbreviationPrefix(),
QudtNamespaces.systemOfUnits.getBaseIri());
writer.handleNamespace("rdfs", RDFS.NAMESPACE);
writer.handleNamespace(
QudtNamespaces.quantityKind.getAbbreviationPrefix(),
QudtNamespaces.quantityKind.getBaseIri());
writer.handleNamespace("quantitykind", QudtNamespaces.quantityKind.getBaseIri());
try {
for (Statement st : con.getStatements(null, null, null)) {
if (statementPredicate.test(st)) {
Expand Down Expand Up @@ -646,6 +646,13 @@ private void save(UnitForContribution unitForContribution, RepositoryConnection
RDFS.LABEL,
ToolImpl.stringLiteral(label.getString(), label.getLanguageTag().orElse(null)));
}
addIfPresent(
mb,
QUDT.prefix,
unit.getPrefix()
.map(p -> p.getIri())
.map(iri -> SimpleValueFactory.getInstance().createIRI(iri))
.orElse(null));
saveCommonMetadata(mb, unitForContribution.getMetadata());
Model model = mb.build();
System.err.println("Adding these triples: ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ private static List<Unit> filterPossibleBasesByQkIfOnlyOneFactor(
baseUnits.stream()
.filter(
bu ->
factorUnits
.getFactorUnits()
.get(0)
.getUnit()
.getQuantityKinds()
.stream()
Qudt.allQuantityKinds().stream()
.filter(
qk ->
qk.getDimensionVectorIri()
.equals(
factorUnits
.getDimensionVectorIri()))
.allMatch(
qk ->
bu.getQuantityKinds()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public String joinWithFallback(
return safeString(prefixIfFirstNull) + second;
}
} else if (second == null) {
return safeString(prefixIfFirstNull) + second;
return first + safeString(suffixIfSecondNull);
}
return first + safeString(joinString) + second;
}
Expand Down
Loading