Skip to content

Commit

Permalink
Use QUDT for the full quantity encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed May 24, 2012
1 parent 190fc11 commit 06c4f96
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions activities.groovy
Expand Up @@ -68,18 +68,34 @@ sql.eachRow(allMolregno) { row ->
// now do the units: check if we need to use QUDT and if we normalize
units = row.standard_units
if (unitMappings.containsKey(units)) {
// use qudt:QuantityValue
quantityValue = factory.createURI(ACT + "a" + row.activity_id + "/standardValue")
con.add(actURI, factory.createURI(ONTO + "hasStandardValue"), quantityValue)
con.add(quantityValue, RDF.TYPE, factory.createURI("http://qudt.org/schema/qudt#QuantityValue"))
if (normalizationMappings.containsKey(type)) {
// use a normalized value
originalUnit = unitFactory.getUnit(unitMappings[units])
originalQuantity = new Quantity(row.standard_value, originalUnit);
normalizedUnit = unitFactory.getUnit(unitMappings[normalizationMappings[type][units]])
normalizedQuantity = originalQuantity.convertTo(normalizedUnit)
con.add(actURI, factory.createURI(ONTO + "standardValue"), factory.createLiteral(normalizedQuantity.value))
con.add(actURI, factory.createURI(ONTO + "standardUnitsClass"), factory.createURI(normalizedQuantity.unit.resource.toString()))
con.add(quantityValue,
factory.createURI("http://qudt.org/schema/qudt#numericValue"),
factory.createLiteral((double)normalizedQuantity.value)
)
con.add(quantityValue,
factory.createURI("http://qudt.org/schema/qudt#unit"),
factory.createURI(normalizedQuantity.unit.resource.toString())
)
} else {
// use QUDT on the original value
con.add(actURI, factory.createURI(ONTO + "standardValue"), factory.createLiteral((float)row.standard_value))
con.add(actURI, factory.createURI(ONTO + "standardUnitsClass"), factory.createURI(unitMappings[units]))
con.add(quantityValue,
factory.createURI("http://qudt.org/schema/qudt#numericValue"),
factory.createLiteral((float)row.standard_value)
)
con.add(quantityValue,
factory.createURI("http://qudt.org/schema/qudt#unit"),
factory.createURI(unitMappings[units])
)
}
} else {
// use the old approach
Expand Down

0 comments on commit 06c4f96

Please sign in to comment.