Re: Ontopia now supports numbers in tolog

Aad Kamsteeg <[email protected]> Tue, 6 Sep 2011 09:25:33 +0200
Newsgroups gmane.text.xml.xtm.general
Message-ID <[email protected]>
Peter-Paul,

Perfect! Just what's needed. (Yes, I'm as enthusiastic about these new functionalities as you are).

:-) Aad

On 5 sep. 2011, at 13:13 PM, Peter-Paul Kruijsen wrote:

> Hi all,
> 
> Over the past years Ontopia was not able to work with numbers. Sorting e.g. a list of occurrence values could result in '123', '45', '6', '78'. For one of our customers, we needed an implementation that would sort these as '6', '45', '78', '123', as well as an implementation for adding, subtracting, multiplying and diving numbers. 
> 
> I have just committed NumbersModule to Ontopia [1]. It will be available in the upcoming 5.2.0 release. With this addition, tolog queries can now work with numbers. It supports these predicates:
> 
> * value(string, result): Parses a string (e.g. an occurrence value) into a number. Pattern and locale are optional, e.g. to parse '€ 5.026,34' for us Europeans.
> * format(number, result): Formats a number into a string. Pattern and locale are optional, e.g. to format a number as '42.6 %'.
> * absolute(result, number): Calculates the absolute value of a number.
> * add(result, number, number): Adds numbers. Providing more than 2 input values is allowed.
> * subtract(result, number, number): Subtracts numbers. Providing more than 2 input values is allowed.
> * multiply(result, number, number): Multiplies numbers. Providing more than 2 input values is allowed.
> * divide(result, number, number): Divides numbers. Providing more than 2 input values is allowed.
> * min(result, number, number): Calculates the minimum value. Providing more than 2 input values is allowed.
> * max(result, number, number): Calculates the maximum value. Providing more than 2 input values is allowed.
> 
> To work with these predicates, you need to include the next line in your tolog query: 
>  import "http://psi.ontopia.net/tolog/numbers/" as numbers
> 
> You can then use the predicates with the 'numbers' prefix, like this:
>  import "http://psi.ontopia.net/tolog/numbers/" as numbers
>  select $name, $percentage, $quotient from
>  topic-name($object, $objectname),
>  value($objectname, $name),
>  value-1($object, $o1),
>  value-2($object, $o2),
>  numbers:value($o1, $value1, "#,##0.00", "NL"),
>  numbers:value($o2, $value2, "#,##0.00", "NL"),
>  numbers:min($min, $value1, $value2),
>  numbers:max($max, $value1, $value2),
>  numbers:subtract($diff, $max, $min),
>  numbers:divide($quotient, $diff, $min),
>  $quotient > 0.05,
>  numbers:format($quotient, $percentage, "#0.00 %", "NL")
>  order by $quotient DESC?
> 
> This roughly translates to:
>  Give me all objects whose occurrences 'value-1' and 'value-2' differ more than 5% and sort them by this difference
> 
> With an LTM file like this (yes, with . as thousands separator and , as decimal separator):
> 
>  [object-1 = "Object 1"]
>  [object-2 = "Object 2"]
>  [object-3 = "Object 3"]
>  [object-4 = "Object 4"]
>  [object-5 = "Object 5"]
>  [object-6 = "Object 6"]
> 
>  {object-1, value-1, [[480.000]]}
>  {object-1, value-2, [[520.000]]}
> 
>  {object-2, value-1, [[1.600.000]]}
>  {object-2, value-2, [[1.542.781,18]]}
> 
>  {object-3, value-1, [[16.000]]}
>  {object-3, value-2, [[47.500,00]]}
> 
>  {object-4, value-1, [[400.000]]}
>  {object-4, value-2, [[400.000]]}
> 
>  {object-5, value-1, [[67.524,75]]}
>  {object-5, value-2, [[84.520,00]]}
> 
>  {object-6, value-1, [[110.000,00]]}
>  {object-6, value-2, [[100.000,00]]}
> 
> The results will be (leaving out the 'quotient' column):
> 
>  name, percentage
>  'Object 3', '196,88 %'
>  'Object 5', '25,17 %'
>  'Object 6', '10,00 %'
>  'Object 1', '8,33 %'
> 
> Hope some of you will be as enthusiastic about these new functionalities as I am.
> 
> Peter-Paul
> 
> [1]: http://code.google.com/p/ontopia/source/detail?r=2182
> _______________________________________________
> topicmapmail mailing list
> topicmapmail-Zo64W7twoUFWk0Htik3J/[email protected]
> http://www.infoloom.com/mailman/listinfo/topicmapmail