ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Chinese numeral conversion
@ 2009-12-23  1:43 Yanrui Li
  2009-12-23  1:46 ` Yanrui Li
  0 siblings, 1 reply; 3+ messages in thread
From: Yanrui Li @ 2009-12-23  1:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 888 bytes --]

Hi Hans,

I modified the part of Chinese numeral conversion in core-con.lua script.
The attachment is the patch. After many tests as the following I think the
patch is right even though it looks dirty.

%%%%
\definefont[song][name:adobesongstdlight]\song
\starttext

\startluacode
local function test (cs)
    j = 1
    for i = 1, 9 do
        tex.print (j .. ': ' .. '\\chinesenumerals{' .. j .. '}\\par')
        j = j * 10 + 1
    end
    tex.print ('\\blank')
end

test ('\\chinesenumerals')
test ('\\chinesecapnumerals')
test ('\\chineseallnumerals')
\stopluacode

This is test for chinese zero:

\startluacode
j = 1
for i = 1, 9 do
    tex.print (j .. ': ' .. '\\chinesenumerals{' .. j .. '}\\par')
    if i % 2 == 0 then
        j = j * 10
    else
        j = j * 10 + 1
    end
end
\stopluacode

\stoptext


The pdf in attachments is output result.

-- 
Best regards,

Li Yanrui

[-- Attachment #1.2: Type: text/html, Size: 1185 bytes --]

[-- Attachment #2: core-con.lua.patch --]
[-- Type: application/octet-stream, Size: 3492 bytes --]

--- /opt/context/tex/texmf-local/tex/context/base/core-con.lua	2009-12-22 23:07:49.000000000 +0800
+++ core-con.lua	2009-09-06 05:16:40.000000000 +0800
@@ -309,7 +309,7 @@
 
 local vector = {
     normal = {
-                [0] = "〇",
+                [0] = "○",
                 [1] = "一",
                 [2] = "二",
                 [3] = "三",
@@ -343,7 +343,7 @@
         [100000000] = "亿",
     },
     all = {
-                [0] = "〇",
+                [0] = "○",
                 [1] = "一",
                 [2] = "二",
                 [3] = "三",
@@ -371,56 +371,39 @@
             break
         elseif n >= 100000000 then
             local m = floor(n/100000000)
-            result[#result+1] = tochinese(m)
+            if m > 1 then result[#result+1] = tochinese(m) end
             result[#result+1] = vector[100000000]
-	    local z =  n - m * 100000000
-	    if z > 0 and z < 10000000 then result[#result+1] = vector[0] end
             n = n % 100000000
         elseif n >= 10000000 then
- 	    local m = floor(n/10000)
-            result[#result+1] = tochinese(m)
+            result[#result+1] = tochinese(floor(n/10000))
             result[#result+1] = vector[10000]
-	    local z =  n - m * 10000 
-	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 1000000 then
-	    local m = floor(n/10000)
-            result[#result+1] = tochinese(m)
+            result[#result+1] = tochinese(floor(n/10000))
             result[#result+1] = vector[10000]
-	    local z =  n - m * 10000 
-	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 100000 then
-	    local m = floor(n/10000)
-            result[#result+1] = tochinese(m)
+            result[#result+1] = tochinese(floor(n/10000))
             result[#result+1] = vector[10000]
-	    local z = n - m * 10000
-	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end	    
             n = n % 10000
         elseif n >= 10000 then
             local m = floor(n/10000)
-            result[#result+1] = vector[m]
+            if m > 1 then result[#result+1] = vector[m] end
             result[#result+1] = vector[10000]
-	    local z =  n - m * 10000
-	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 1000 then
             local m = floor(n/1000)
-            result[#result+1] = vector[m]
+            if m > 1 then result[#result+1] = vector[m] end
             result[#result+1] = vector[1000]
-	    local z =  n - m * 1000
-	    if z > 0 and z < 100 then result[#result+1] = vector[0] end
             n = n % 1000
         elseif n >= 100 then
             local m = floor(n/100)
-            result[#result+1] = vector[m]
+            if m > 1 then result[#result+1] = vector[m] end
             result[#result+1] = vector[100]
-	    local z = n - m * 100
-	    if z > 0 and z < 10 then result[#result+1] = vector[0] end
             n = n % 100
         elseif n >= 10 then
             local m = floor(n/10)
-            if m > 1 and vector[m*10] then
+            if vector[m*10] then
                 result[#result+1] = vector[m*10]
             else
                 result[#result+1] = vector[m]
@@ -432,9 +415,6 @@
             break
         end
     end
-    if (result[1] == vector[1] and result[2] == vector[10]) then
-	result[1] = ""
-    end
     return concat(result)
 end
 

[-- Attachment #3: ch-n.pdf --]
[-- Type: application/pdf, Size: 9446 bytes --]

[-- Attachment #4: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Chinese numeral conversion
  2009-12-23  1:43 Chinese numeral conversion Yanrui Li
@ 2009-12-23  1:46 ` Yanrui Li
  2009-12-23  2:05   ` Yanrui Li
  0 siblings, 1 reply; 3+ messages in thread
From: Yanrui Li @ 2009-12-23  1:46 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 794 bytes --]

2009/12/23 Yanrui Li <liyanrui.m2@gmail.com>

> Hi Hans,
>
> I modified the part of Chinese numeral conversion in core-con.lua script.
> The attachment is the patch. After many tests as the following I think the
> patch is right even though it looks dirty.
>
> %%%%
> \definefont[song][name:adobesongstdlight]\song
> \starttext
>
> \startluacode
> local function test (cs)
>     j = 1
>     for i = 1, 9 do
>         tex.print (j .. ': ' .. '\\chinesenumerals{' .. j .. '}\\par')
>         j = j * 10 + 1
>     end
>     tex.print ('\\blank')
> end
>
>
sorry, this function should be:

 local function test (cs)
    j = 1
    for i = 1, 9 do
        tex.print (j .. ': ' .. cs .. '{' .. j .. '}\\par')
        j = j * 10 + 1
    end
    tex.print ('\\blank')
end


-- 
Best regards,

Li Yanrui

[-- Attachment #1.2: Type: text/html, Size: 1288 bytes --]

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Chinese numeral conversion
  2009-12-23  1:46 ` Yanrui Li
@ 2009-12-23  2:05   ` Yanrui Li
  0 siblings, 0 replies; 3+ messages in thread
From: Yanrui Li @ 2009-12-23  2:05 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 512 bytes --]

2009/12/23 Yanrui Li <liyanrui.m2@gmail.com>

>
>
> 2009/12/23 Yanrui Li <liyanrui.m2@gmail.com>
>
> Hi Hans,
>>
>> I modified the part of Chinese numeral conversion in core-con.lua script.
>> The attachment is the patch. After many tests as the following I think the
>> patch is right even though it looks dirty.
>
>
> sorry, this function should be:
>
>
sorry again.

I just discovered it is wrong with the numbers biger than 100000. Now I made
a new patch and new output result.

-- 
Best regards,

Li Yanrui

[-- Attachment #1.2: Type: text/html, Size: 1109 bytes --]

[-- Attachment #2: core-con.lua.patch --]
[-- Type: application/octet-stream, Size: 3514 bytes --]

--- /opt/context/tex/texmf-context/tex/context/base/core-con.lua	2009-12-21 15:26:29.000000000 +0800
+++ core-con.lua	2009-12-23 10:02:02.000000000 +0800
@@ -309,7 +309,7 @@
 
 local vector = {
     normal = {
-                [0] = "○",
+                [0] = "〇",
                 [1] = "一",
                 [2] = "二",
                 [3] = "三",
@@ -343,7 +343,7 @@
         [100000000] = "亿",
     },
     all = {
-                [0] = "○",
+                [0] = "〇",
                 [1] = "一",
                 [2] = "二",
                 [3] = "三",
@@ -371,39 +371,56 @@
             break
         elseif n >= 100000000 then
             local m = floor(n/100000000)
-            if m > 1 then result[#result+1] = tochinese(m) end
+            result[#result+1] = tochinese(m,name)
             result[#result+1] = vector[100000000]
+	    local z =  n - m * 100000000
+	    if z > 0 and z < 10000000 then result[#result+1] = vector[0] end
             n = n % 100000000
         elseif n >= 10000000 then
-            result[#result+1] = tochinese(floor(n/10000))
+ 	    local m = floor(n/10000)
+            result[#result+1] = tochinese(m,name)
             result[#result+1] = vector[10000]
+	    local z =  n - m * 10000 
+	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 1000000 then
-            result[#result+1] = tochinese(floor(n/10000))
+	    local m = floor(n/10000)
+            result[#result+1] = tochinese(m,name)
             result[#result+1] = vector[10000]
+	    local z =  n - m * 10000 
+	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 100000 then
-            result[#result+1] = tochinese(floor(n/10000))
+	    local m = floor(n/10000)
+            result[#result+1] = tochinese(m,name)
             result[#result+1] = vector[10000]
+	    local z = n - m * 10000
+	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end	    
             n = n % 10000
         elseif n >= 10000 then
             local m = floor(n/10000)
-            if m > 1 then result[#result+1] = vector[m] end
+            result[#result+1] = vector[m]
             result[#result+1] = vector[10000]
+	    local z =  n - m * 10000
+	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 1000 then
             local m = floor(n/1000)
-            if m > 1 then result[#result+1] = vector[m] end
+            result[#result+1] = vector[m]
             result[#result+1] = vector[1000]
+	    local z =  n - m * 1000
+	    if z > 0 and z < 100 then result[#result+1] = vector[0] end
             n = n % 1000
         elseif n >= 100 then
             local m = floor(n/100)
-            if m > 1 then result[#result+1] = vector[m] end
+            result[#result+1] = vector[m]
             result[#result+1] = vector[100]
+	    local z = n - m * 100
+	    if z > 0 and z < 10 then result[#result+1] = vector[0] end
             n = n % 100
         elseif n >= 10 then
             local m = floor(n/10)
-            if vector[m*10] then
+            if m > 1 and vector[m*10] then
                 result[#result+1] = vector[m*10]
             else
                 result[#result+1] = vector[m]
@@ -415,6 +432,9 @@
             break
         end
     end
+    if (result[1] == vector[1] and result[2] == vector[10]) then
+	result[1] = ""
+    end
     return concat(result)
 end
 

[-- Attachment #3: ch-n.pdf --]
[-- Type: application/pdf, Size: 11136 bytes --]

[-- Attachment #4: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-12-23  2:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-23  1:43 Chinese numeral conversion Yanrui Li
2009-12-23  1:46 ` Yanrui Li
2009-12-23  2:05   ` Yanrui Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).