<commit_before>u8R""__RAW_STRING__(

local U = require "togo.utility"
local O = require "Quanta.Object"
local Match = require "Quanta.Match"
local M = U.module(...)

U.class(M)

M.Quantity = {
{
	name = "dimensionless",
	translation_preference = 0,
	convert = function(self, m)
		m.qindex = self.index
		m.magnitude = 0
	end,
},
{
	name = "mass",
	translation_preference = 3,
	convert = function(self, m)
		-- TODO: 1u/cm³ density in measurement?
		m.qindex = self.index
	end,
},
{
	name = "volume",
	translation_preference = 2,
	convert = function(self, m)
		-- TODO
		m.qindex = self.index
	end,
},
{
	name = "transitional",
	translation_preference = 1,
	convert = function(self, m)
		-- TODO
		m.qindex = self.index
	end,
},
}
M.QuantityIndex = {}
M.Unit = {}

do
	for i, q in ipairs(M.Quantity) do
		q.index = i
		q.UnitByMagnitude = {}
		M.Quantity[q.name] = q
		M.QuantityIndex[q.name] = i
	end

	local function define_units(quantity, orders)
		U.assert(quantity)
		for _, order in pairs(orders) do
			local names = order[1]
			names = U.is_type(names, "string") and {names} or names

			local def = {
				name = names[1],
				qindex = quantity.index,
				quantity = quantity,
				magnitude = U.is_type(order[2], "number") and order[2] or 0,
				convert = U.is_type(order[2], "function") and order[2] or nil,
			}
			def.is_si = def.convert == nil
			if def.is_si and not quantity.UnitByMagnitude[def.magnitude] then
				quantity.UnitByMagnitude[def.magnitude] = def
			end

			for _, name in pairs(names) do
				local name_hash = O.hash_value(name)
				U.assert(not M.Unit[name_hash])
				M.Unit[name_hash] = def
			end
		end
	end

	define_units(M.Quantity.dimensionless, {
		{"" ,  0},
		{"u",  0}, -- FIXME: this should probably not be allowed in the future
	})

	define_units(M.Quantity.mass, {
		-- SI
		{"kg",  3},
		{"g" ,  0},
		{"mg", -3},
		{"µg", -6},
		{"ng", -9},

		-- U.S. customary units
		{"oz", function(value)
			return value * 28.349523
		end},
		{"lb", function(value)
			return value * 453.592370
		end},
	})

	define_units(M.Quantity.volume, {
		-- SI
		{{"l" , "L" },  3},
		{{"ml", "mL"},  0},<commit_msg>lib/core/measurement/Measurement.lua: added ratio quantity and quantity tangibility property.<commit_after>u8R""__RAW_STRING__(

local U = require "togo.utility"
local O = require "Quanta.Object"
local Match = require "Quanta.Match"
local M = U.module(...)

U.class(M)

M.Quantity = {
{
	name = "dimensionless",
	translation_preference = 0,
	convert = function(self, m)
		m.qindex = self.index
		m.magnitude = 0
	end,
},
{
	name = "ratio",
	translation_preference = 0,
	convert = function(self, m)
		-- TODO
		m.qindex = self.index
		m.magnitude = 0
	end,
},
{
	name = "mass",
	tangible = true,
	translation_preference = 3,
	convert = function(self, m)
		-- TODO: 1u/cm³ density in measurement?
		m.qindex = self.index
	end,
},
{
	name = "volume",
	tangible = true,
	translation_preference = 2,
	convert = function(self, m)
		-- TODO
		m.qindex = self.index
	end,
},
{
	name = "transitional",
	translation_preference = 1,
	convert = function(self, m)
		-- TODO
		m.qindex = self.index
	end,
},
}
M.QuantityIndex = {}
M.Unit = {}

do
	for i, q in ipairs(M.Quantity) do
		q.index = i
		q.UnitByMagnitude = {}
		M.Quantity[q.name] = q
		M.QuantityIndex[q.name] = i
	end

	local function define_units(quantity, orders)
		U.assert(quantity)
		for _, order in pairs(orders) do
			local names = order[1]
			names = U.is_type(names, "string") and {names} or names

			local def = {
				name = names[1],
				qindex = quantity.index,
				quantity = quantity,
				magnitude = U.is_type(order[2], "number") and order[2] or 0,
				convert = U.is_type(order[2], "function") and order[2] or nil,
			}
			def.is_si = def.convert == nil
			if def.is_si and not quantity.UnitByMagnitude[def.magnitude] then
				quantity.UnitByMagnitude[def.magnitude] = def
			end

			for _, name in pairs(names) do
				local name_hash = O.hash_value(name)
				U.assert(not M.Unit[name_hash])
				M.Unit[name_hash] = def
			end
		end
	end

	define_units(M.Quantity.dimensionless, {
		{"" ,  0},
		{"u",  0}, -- FIXME: this should probably not be allowed in the future
	})

	define_units(M.Quantity.ratio, {
		{"ratio",  0},
	})

	define_units(M.Quantity.mass, {
		-- SI
		{"kg",  3},
		{"g" ,  0},
		{"mg", -3},
		{"µg", -6},
		{"ng", -9},

		-- U.S. customary units
		{"oz", function(value)
			return value * 28.349523
		end},
		{"lb", function(value)
			return value * 453.592370
		end},
	})

	define_units(M.Quantity.volume, {
		-- SI
		{{"l" , "L" },  3},
		{{"ml", "mL"},  0},
{'fraction_non_alphanumeric': 0.16019205587079877, 'fraction_numerical': 0.01811436054124836, 'mean_word_length': 3.114003590664273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '671599', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1771, 'n_words': 430}