comp.lang.ada
 help / color / mirror / Atom feed
* Range types
@ 2007-10-21 19:15 Christos Chryssochoidis
  2007-10-21 20:23 ` Niklas Holsti
  2007-10-21 21:53 ` anon
  0 siblings, 2 replies; 12+ messages in thread
From: Christos Chryssochoidis @ 2007-10-21 19:15 UTC (permalink / raw)


Hi,

I have a question regarding the range types in Ada. Is there any way to 
specify that a type is, say, the values 1..100 and additionally the 
values 150..200? I tried something like

> type My_Int is range 1..100, 150..200;



and

> type My_Int is range 1..100 | 150..200;


but without success. I also tried doing this within an enumeration, but 
failed again. Is it possible to define such type, consisting of multiple 
ranges?


Thanks very much for any answer.


Christos Chryssochoidis



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

* Re: Range types
  2007-10-21 19:15 Range types Christos Chryssochoidis
@ 2007-10-21 20:23 ` Niklas Holsti
  2007-10-21 21:28   ` Christos Chryssochoidis
  2007-10-21 21:53 ` anon
  1 sibling, 1 reply; 12+ messages in thread
From: Niklas Holsti @ 2007-10-21 20:23 UTC (permalink / raw)


Christos Chryssochoidis wrote:
> Hi,
> 
> I have a question regarding the range types in Ada. Is there any way to 
> specify that a type is, say, the values 1..100 and additionally the 
> values 150..200?

Brief answer: sorry, no. You cannot leave gaps in the range of 
numeric types.

You could define an enumeration type with 151 literals and write a 
"representation clause" for this type that would force the compiler 
to use the values 1 .. 100 as the internal representation of the 
first 100 literals and the values 150 .. 200 as the internal 
representation of the last 51 literals. This would override the the 
default internal representation that uses the values 0 .. 150 in 
order. But you could not do direct arithmetic (plus, minus, ...) on 
such a type because those operations are not predefined for 
enumeration types.

Perhaps you could explain why you need a type with a gap?

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



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

* Re: Range types
  2007-10-21 20:23 ` Niklas Holsti
@ 2007-10-21 21:28   ` Christos Chryssochoidis
  2007-10-22  0:06     ` Robert A Duff
  2007-10-22  7:23     ` Jacob Sparre Andersen
  0 siblings, 2 replies; 12+ messages in thread
From: Christos Chryssochoidis @ 2007-10-21 21:28 UTC (permalink / raw)
  To: Niklas Holsti

Niklas Holsti wrote:
> 
> Christos Chryssochoidis wrote:
>> Hi,
>>
>> I have a question regarding the range types in Ada. Is there any way 
>> to specify that a type is, say, the values 1..100 and additionally the 
>> values 150..200?
> 
> Brief answer: sorry, no. You cannot leave gaps in the range of numeric 
> types.
> 
> You could define an enumeration type with 151 literals and write a 
> "representation clause" for this type that would force the compiler to 
> use the values 1 .. 100 as the internal representation of the first 100 
> literals and the values 150 .. 200 as the internal representation of the 
> last 51 literals. This would override the the default internal 
> representation that uses the values 0 .. 150 in order. But you could not 
> do direct arithmetic (plus, minus, ...) on such a type because those 
> operations are not predefined for enumeration types.
> 
> Perhaps you could explain why you need a type with a gap?
> 

I would like to define a subtype of Wide_Character for a program that 
processes (unicode) text. This type would represent the Greek letters. 
Greek letters in Unicode, with all their diacritics, are located in two 
separate ranges: 0370 - 03D7 and 1F00 - 1FFF. That's 360 characters to 
write in an enumeration... Since gaps are not allowed in ranges, I 'm 
thinking instead of defining such a type, to define a function that 
would accept a Wide_Character as argument and return a boolean value 
indicating whether the given Wide_Character falls in the ranges of the 
Greek characters.

Thanks very much,

C.C.



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

* Re: Range types
  2007-10-21 19:15 Range types Christos Chryssochoidis
  2007-10-21 20:23 ` Niklas Holsti
@ 2007-10-21 21:53 ` anon
  2007-10-21 22:38   ` Christos Chryssochoidis
  1 sibling, 1 reply; 12+ messages in thread
From: anon @ 2007-10-21 21:53 UTC (permalink / raw)


--
-- From the syntax rules of RM 3.2.1, 3.2.2 and 3.5 the 
-- simple answer is no for integer scalar types.
--
-- One way to do this is to exclude the values you want 
-- in the logical of the program
--
with Ada.Text_IO ;
use Ada.Text_IO ;

procedure t is

    --
    -- creates a master constraint type
    --
    type My_Int_Base is range 1..200 ; 

    --
    -- creates an excluded type
    --
    subtype My_Int_Exclude_Subtype is My_Int_Base range 101..149 ;


    Var_0 : My_Int_Base ;

  begin

    -- set Var_0  valid

    Put_Line ( "Var_0 => 75" ) ;
    Var_0 := 75 ;

    --
    -- Verify that value of Var_0 is not excluded
    --
    if Var_0 in My_Int_Exclude_Subtype then    
      raise Constraint_Error ;
    end if ;

    --
    -- Use Var_0
    --
    Put_Line ( "    Var_0 => Valid" ) ;

    --   
    -- Set Var_0 invalid
    --
    Put_Line ( "Var_0 => 125" ) ;
    Var_0 := 125 ;

    --
    -- Verify that value of Var_0 is not excluded
    --
    if Var_0 in My_Int_Exclude_Subtype then  
      raise Constraint_Error ;
    end if ;

    --
    -- Use Var_0
    --
    Put_Line ( "    Var_0 => Valid" ) ;

  exception
    when Constraint_Error =>
      Put_Line ( "    Var_0 => Constraint_Error" ) ;
  end t ;



In <1192994157.867598@athprx04>, Christos Chryssochoidis <C.Chryssochoidis@gmail.com> writes:
>Hi,
>
>I have a question regarding the range types in Ada. Is there any way to 
>specify that a type is, say, the values 1..100 and additionally the 
>values 150..200? I tried something like
>
>> type My_Int is range 1..100, 150..200;
>
>
>
>and
>
>> type My_Int is range 1..100 | 150..200;
>
>
>but without success. I also tried doing this within an enumeration, but 
>failed again. Is it possible to define such type, consisting of multiple 
>ranges?
>
>
>Thanks very much for any answer.
>
>
>Christos Chryssochoidis




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

* Re: Range types
  2007-10-21 21:53 ` anon
@ 2007-10-21 22:38   ` Christos Chryssochoidis
  0 siblings, 0 replies; 12+ messages in thread
From: Christos Chryssochoidis @ 2007-10-21 22:38 UTC (permalink / raw)
  To: anon

Thanks! This is indeed a very good solution to the problem I posed. And 
that's what I'll probably end up doing. I thought too about defining a 
function (predicate) that would decide whether a given value falls in 
the legal ranges. But by doing the discrimination with a function, I 
wouldn't have a "concrete" type to work with...

Thanks very much,

C.C.


anon wrote:
> --
> -- From the syntax rules of RM 3.2.1, 3.2.2 and 3.5 the 
> -- simple answer is no for integer scalar types.
> --
> -- One way to do this is to exclude the values you want 
> -- in the logical of the program
> --
> with Ada.Text_IO ;
> use Ada.Text_IO ;
> 
> procedure t is
> 
>     --
>     -- creates a master constraint type
>     --
>     type My_Int_Base is range 1..200 ; 
> 
>     --
>     -- creates an excluded type
>     --
>     subtype My_Int_Exclude_Subtype is My_Int_Base range 101..149 ;
> 
> 
>     Var_0 : My_Int_Base ;
> 
>   begin
> 
>     -- set Var_0  valid
> 
>     Put_Line ( "Var_0 => 75" ) ;
>     Var_0 := 75 ;
> 
>     --
>     -- Verify that value of Var_0 is not excluded
>     --
>     if Var_0 in My_Int_Exclude_Subtype then    
>       raise Constraint_Error ;
>     end if ;
> 
>     --
>     -- Use Var_0
>     --
>     Put_Line ( "    Var_0 => Valid" ) ;
> 
>     --   
>     -- Set Var_0 invalid
>     --
>     Put_Line ( "Var_0 => 125" ) ;
>     Var_0 := 125 ;
> 
>     --
>     -- Verify that value of Var_0 is not excluded
>     --
>     if Var_0 in My_Int_Exclude_Subtype then  
>       raise Constraint_Error ;
>     end if ;
> 
>     --
>     -- Use Var_0
>     --
>     Put_Line ( "    Var_0 => Valid" ) ;
> 
>   exception
>     when Constraint_Error =>
>       Put_Line ( "    Var_0 => Constraint_Error" ) ;
>   end t ;
> 
> 
> 
> In <1192994157.867598@athprx04>, Christos Chryssochoidis <C.Chryssochoidis@gmail.com> writes:
>> Hi,
>>
>> I have a question regarding the range types in Ada. Is there any way to 
>> specify that a type is, say, the values 1..100 and additionally the 
>> values 150..200? I tried something like
>>
>>> type My_Int is range 1..100, 150..200;
>>
>>
>> and
>>
>>> type My_Int is range 1..100 | 150..200;
>>
>> but without success. I also tried doing this within an enumeration, but 
>> failed again. Is it possible to define such type, consisting of multiple 
>> ranges?
>>
>>
>> Thanks very much for any answer.
>>
>>
>> Christos Chryssochoidis
> 



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

* Re: Range types
  2007-10-21 21:28   ` Christos Chryssochoidis
@ 2007-10-22  0:06     ` Robert A Duff
  2007-10-22  7:23     ` Jacob Sparre Andersen
  1 sibling, 0 replies; 12+ messages in thread
From: Robert A Duff @ 2007-10-22  0:06 UTC (permalink / raw)


Christos Chryssochoidis <C.Chryssochoidis@gmail.com> writes:

> I would like to define a subtype of Wide_Character for a program that
> processes (unicode) text. This type would represent the Greek
> letters. Greek letters in Unicode, with all their diacritics, are
> located in two separate ranges: 0370 - 03D7 and 1F00 - 1FFF.

That's a reasonable thing to want, but Ada doesn't support that directly
-- you have to program it yourself.

>... That's 360
> characters to write in an enumeration... Since gaps are not allowed in
> ranges, I 'm thinking instead of defining such a type, to define a
> function that would accept a Wide_Character as argument and return a
> boolean value indicating whether the given Wide_Character falls in the
> ranges of the Greek characters.

Right.  And perhaps a conversion function that converts from
[Wide_?]Wide_Character to Greek_Letter, and raises an exception if it's
not a greek letter.

- Bob



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

* Re: Range types
  2007-10-21 21:28   ` Christos Chryssochoidis
  2007-10-22  0:06     ` Robert A Duff
@ 2007-10-22  7:23     ` Jacob Sparre Andersen
  2007-10-22 11:14       ` Christos Chryssochoidis
  1 sibling, 1 reply; 12+ messages in thread
From: Jacob Sparre Andersen @ 2007-10-22  7:23 UTC (permalink / raw)


Christos Chryssochoidis wrote:

> I would like to define a subtype of Wide_Character for a program
> that processes (unicode) text. This type would represent the Greek
> letters.

This sounds like what enumerated types are for.  You could do it like
this:

   type Faroese_Letter is ('a', 'A', 'b', 'B', 'd', 'D', '�', '�',
                           'e', 'E', [...],
                           'y', 'Y', '�', '�', '�', '�', '�', '�');
   -- optional representation clause

   function To_Wide_Wide_Character (Item : in Faroese_Letter)
     return Wide_Wide_Character;

   function To_Faroese_Letter (Item : in Wide_Wide_Character)
     return Faroese_Letter;

The conversion functions could make use of representation clauses,
"Image" and "Value" functions, or tables.

> Greek letters in Unicode, with all their diacritics, are
> located in two separate ranges: 0370 - 03D7 and 1F00 - 1FFF. That's
> 360 characters to write in an enumeration... Since gaps are not
> allowed in ranges, I 'm thinking instead of defining such a type, to
> define a function that would accept a Wide_Character as argument and
> return a boolean value indicating whether the given Wide_Character
> falls in the ranges of the Greek characters.

This could be done very simply using Ada.Strings.Maps.

How you should do it depends strongly on what you actually need your
Greek_Letter type for.

Greetings,

Jacob
-- 
"Only Hogwarts students really need spellcheckers"
                                -- An anonymous RISKS reader



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

* Re: Range types
  2007-10-22  7:23     ` Jacob Sparre Andersen
@ 2007-10-22 11:14       ` Christos Chryssochoidis
  2007-10-22 12:33         ` Georg Bauhaus
  2007-10-23 23:52         ` anon
  0 siblings, 2 replies; 12+ messages in thread
From: Christos Chryssochoidis @ 2007-10-22 11:14 UTC (permalink / raw)


Jacob Sparre Andersen wrote:
> Christos Chryssochoidis wrote:
> 
>> I would like to define a subtype of Wide_Character for a program
>> that processes (unicode) text. This type would represent the Greek
>> letters.
> 
> This sounds like what enumerated types are for.  You could do it like
> this:
> 
>    type Faroese_Letter is ('a', 'A', 'b', 'B', 'd', 'D', '�', '�',
>                            'e', 'E', [...],
>                            'y', 'Y', '�', '�', '�', '�', '�', '�');
>    -- optional representation clause
> 
>    function To_Wide_Wide_Character (Item : in Faroese_Letter)
>      return Wide_Wide_Character;
> 
>    function To_Faroese_Letter (Item : in Wide_Wide_Character)
>      return Faroese_Letter;
> 
> The conversion functions could make use of representation clauses,
> "Image" and "Value" functions, or tables.
> 
>> Greek letters in Unicode, with all their diacritics, are
>> located in two separate ranges: 0370 - 03D7 and 1F00 - 1FFF. That's
>> 360 characters to write in an enumeration... Since gaps are not
>> allowed in ranges, I 'm thinking instead of defining such a type, to
>> define a function that would accept a Wide_Character as argument and
>> return a boolean value indicating whether the given Wide_Character
>> falls in the ranges of the Greek characters.
> 
> This could be done very simply using Ada.Strings.Maps.
> 
> How you should do it depends strongly on what you actually need your
> Greek_Letter type for.
> 
> Greetings,
> 
> Jacob

Thanks! Ada.Strings.Wide_Maps seems very helpful for what I want to do. 
Basically, what I would like to do is to write a program that given a 
text file in utf8 encoding, which would contain ancient greek text, 
which is written with all the diacritic marks on the letters, this 
program would load the contents of the file in memory, strip the 
in-memory text contents from all the diacritics except those used in 
today's "modern" Greek, and write the modified contents to a new file of 
the user's choosing. For this it would be nice if there were some 
package for regular expressions for Ada. Then if I succeeded in the 
mentioned task,  I 'd like to do some natural language processing (NLP, 
that is linguistics processing) with my program, but I don't know if Ada 
would be an appropriate language for such a task (NLP). I've seen on the 
web references to NLP applications with functional languages or logic 
programming languages, but not many implemented with imperative 
languages... (Sorry for getting of topic...)

Thanks very much,
Christos



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

* Re: Range types
  2007-10-22 11:14       ` Christos Chryssochoidis
@ 2007-10-22 12:33         ` Georg Bauhaus
  2007-10-22 19:08           ` Christos Chryssochoidis
  2007-10-23 23:52         ` anon
  1 sibling, 1 reply; 12+ messages in thread
From: Georg Bauhaus @ 2007-10-22 12:33 UTC (permalink / raw)


On Mon, 2007-10-22 at 14:14 +0300, Christos Chryssochoidis wrote:


> For this it would be nice if there were some 
> package for regular expressions for Ada.

The Strings hierarchy actually has some RE processing routines,
at least if you consider types for character ranges and
character sets, together with subprograms that scan strings for
occurrences of characters from these sets.

If you have GNAT, a non-portable Ada solution can well be based
on the Spitbol packages, which include the most powerful
pattern matching machinery.






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

* Re: Range types
  2007-10-22 12:33         ` Georg Bauhaus
@ 2007-10-22 19:08           ` Christos Chryssochoidis
  0 siblings, 0 replies; 12+ messages in thread
From: Christos Chryssochoidis @ 2007-10-22 19:08 UTC (permalink / raw)


Thanks for the hint. I 'll have a look at both the standard packages' 
routines and the Spitbol packages.

Regards,
C.C.


Georg Bauhaus wrote:
> On Mon, 2007-10-22 at 14:14 +0300, Christos Chryssochoidis wrote:
> 
> 
>> For this it would be nice if there were some 
>> package for regular expressions for Ada.
> 
> The Strings hierarchy actually has some RE processing routines,
> at least if you consider types for character ranges and
> character sets, together with subprograms that scan strings for
> occurrences of characters from these sets.
> 
> If you have GNAT, a non-portable Ada solution can well be based
> on the Spitbol packages, which include the most powerful
> pattern matching machinery.
> 
> 
> 



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

* Re: Range types
  2007-10-22 11:14       ` Christos Chryssochoidis
  2007-10-22 12:33         ` Georg Bauhaus
@ 2007-10-23 23:52         ` anon
  2007-10-24 12:57           ` Christos Chryssochoidis
  1 sibling, 1 reply; 12+ messages in thread
From: anon @ 2007-10-23 23:52 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 7135 bytes --]

--
-- Package example:
--
-- For non Greek keyboards use Wide_Character 
--  { ["<xxxx>"]["<yyyy>"] } 
--  where <xxxx> and <yyyy> are 4-hex-digits to represents
--  the two Wide_Character values 
--
--  Example is 
--    ["03d6"]["1eee"]  -- valid Greek string
--    ["03d6"]h -- is not valid because character "h" is not
--                 a valid Greek character.
--


with Ada.Wide_Text_IO ;
use  Ada.Wide_Text_IO ;

procedure tst is

  --
  -- Internal Packages:
  --
  package Greek is


    function Is_Greek_Character ( GC : Wide_Character ) 
                                return Boolean ;


    function Is_Greek_Character_2 ( GC : Wide_Character ) 
                                return Boolean ;

    function Is_Greek_Character ( GS : Wide_String ) 
                                return Boolean ;

  end Greek ;

  --
  -- Internal Body Package 
  --
  package body Greek is

    -- --------------------------- --
    -- Use for Is_Greek_Character  --
    -- --------------------------- --

    --
    -- creates a greek constraint type
    --
    subtype Greek_Base is Wide_Character 
                                range Wide_Character'Val ( 16#370# )
                                   .. Wide_Character'Val ( 16#1FFF# ) ;

    --
    -- creates an excluded type
    --
    subtype Greek_Exclude_Subtype is Greek_Base
                                range Greek_Base'Val ( 16#03D8# )
                                   .. Greek_Base'Val ( 16#0FFF# ) ;

    -- ----------------------------- --
    -- Use for Is_Greek_Character_2  --
    -- ----------------------------- --

    --
    -- create lower greek characters type
    --
    subtype Lower_Greek_Character is Wide_Character 
                                range Wide_Character'Val ( 16#0370# )
                                   .. Wide_Character'Val ( 16#03D7# ) ;
    --
    -- create upper greek characters type
    --
    subtype Upper_Greek_Character is Wide_Character 
                               range Wide_Character 'Val ( 16#1000# )  
                                  .. Wide_Character 'Val ( 16#1FFF# ) ;




  --
  -- Is_Greek_Character 
  --
  function Is_Greek_Character ( GC : Wide_Character ) 
                              return Boolean is

    begin
      --
      -- Is character within the Greek base
      --
      if GC in Greek_Base then
        --
        -- Is character apart of the the non-Greek sub type
        --
        if GC in Greek_Exclude_Subtype then    
          return False ;
        else
          return True ;
        end if ;
      else
        return False ;
      end if ;
    end ;


  --
  -- Is_Greek_Character version number 2
  --
  function Is_Greek_Character_2 ( GC : Wide_Character ) 
                              return Boolean is

    begin
      --
      -- Could use:
      -- 
      -- when Lower_Greek_Character | Upper_Greek_Character =>
      --    return True ;
      --
      case GC is 
         when Lower_Greek_Character =>
            return True ;
         when Upper_Greek_Character =>
            return True ;
         when others =>
            return False ;
      end case ;
    end ;


  function Is_Greek_Character ( GS : Wide_String ) 
                              return Boolean is

    begin
      --
      -- Could use:
      -- 
      --
      for Index in 1 .. GS'Length loop
        --
        -- if index-character of a string is not a Greek character
        --
        if not Is_Greek_Character_2 ( GS ( Index ) ) then 
          return False ;
        end if ;
      end loop ;
      --
      -- String contains all Greek characters
      --
      return True ;
    end ;

  end Greek ;


  stz : wide_string ( 1..2 ) ;

  use Greek ;

begin
--
  put ( "Enter (2 character Greek string) => " ) ;
  get ( stz ) ;
--
  put ( "Testing => " ) ;
  put ( stz ) ;
  new_line ;  
--
  if Is_Greek_Character ( stz ) then
    put_line ( "Greek String ? => Yes" ) ;
  else
    put_line ( "Greek String ? => No" ) ;
    --
    -- Char 1 ?
    --
    if Is_Greek_Character ( stz ( 1 ) ) then
      put_line ( "Character (1) Greek ? => Yes" ) ;
    else
      put_line ( "Character (1) Greek ? => No" ) ;
    end if ;    

    --
    -- Char 2 ?
    --
    if Is_Greek_Character_2 ( stz ( 2 ) ) then
      put_line ( "Character (2) Greek ? => Yes" ) ;
    else
      put_line ( "Character (1) Greek ? => No" ) ;
    end if ;
  end if ;    
--
end tst ;



In <1193051690.350063@athprx04>, Christos Chryssochoidis <C.Chryssochoidis@gmail.com> writes:
>Jacob Sparre Andersen wrote:
>> Christos Chryssochoidis wrote:
>> 
>>> I would like to define a subtype of Wide_Character for a program
>>> that processes (unicode) text. This type would represent the Greek
>>> letters.
>> 
>> This sounds like what enumerated types are for.  You could do it like
>> this:
>> 
>>    type Faroese_Letter is ('a', 'A', 'b', 'B', 'd', 'D', '�', '�',
>>                            'e', 'E', [...],
>>                            'y', 'Y', '�', '�', '�', '�', '�', '�');
>>    -- optional representation clause
>> 
>>    function To_Wide_Wide_Character (Item : in Faroese_Letter)
>>      return Wide_Wide_Character;
>> 
>>    function To_Faroese_Letter (Item : in Wide_Wide_Character)
>>      return Faroese_Letter;
>> 
>> The conversion functions could make use of representation clauses,
>> "Image" and "Value" functions, or tables.
>> 
>>> Greek letters in Unicode, with all their diacritics, are
>>> located in two separate ranges: 0370 - 03D7 and 1F00 - 1FFF. That's
>>> 360 characters to write in an enumeration... Since gaps are not
>>> allowed in ranges, I 'm thinking instead of defining such a type, to
>>> define a function that would accept a Wide_Character as argument and
>>> return a boolean value indicating whether the given Wide_Character
>>> falls in the ranges of the Greek characters.
>> 
>> This could be done very simply using Ada.Strings.Maps.
>> 
>> How you should do it depends strongly on what you actually need your
>> Greek_Letter type for.
>> 
>> Greetings,
>> 
>> Jacob
>
>Thanks! Ada.Strings.Wide_Maps seems very helpful for what I want to do. 
>Basically, what I would like to do is to write a program that given a 
>text file in utf8 encoding, which would contain ancient greek text, 
>which is written with all the diacritic marks on the letters, this 
>program would load the contents of the file in memory, strip the 
>in-memory text contents from all the diacritics except those used in 
>today's "modern" Greek, and write the modified contents to a new file of 
>the user's choosing. For this it would be nice if there were some 
>package for regular expressions for Ada. Then if I succeeded in the 
>mentioned task,  I 'd like to do some natural language processing (NLP, 
>that is linguistics processing) with my program, but I don't know if Ada 
>would be an appropriate language for such a task (NLP). I've seen on the 
>web references to NLP applications with functional languages or logic 
>programming languages, but not many implemented with imperative 
>languages... (Sorry for getting of topic...)
>
>Thanks very much,
>Christos




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

* Re: Range types
  2007-10-23 23:52         ` anon
@ 2007-10-24 12:57           ` Christos Chryssochoidis
  0 siblings, 0 replies; 12+ messages in thread
From: Christos Chryssochoidis @ 2007-10-24 12:57 UTC (permalink / raw)


Thanks very much, for giving me in such detail the solution, anon!

Regards,

Christos Chryssochoidis

anon wrote:
> --
> -- Package example:
> --
> -- For non Greek keyboards use Wide_Character 
> --  { ["<xxxx>"]["<yyyy>"] } 
> --  where <xxxx> and <yyyy> are 4-hex-digits to represents
> --  the two Wide_Character values 
> --
> --  Example is 
> --    ["03d6"]["1eee"]  -- valid Greek string
> --    ["03d6"]h -- is not valid because character "h" is not
> --                 a valid Greek character.
> --
> 
> 
> with Ada.Wide_Text_IO ;
> use  Ada.Wide_Text_IO ;
> 
> procedure tst is
> 
>   --
>   -- Internal Packages:
>   --
>   package Greek is
> 
> 
>     function Is_Greek_Character ( GC : Wide_Character ) 
>                                 return Boolean ;
> 
> 
>     function Is_Greek_Character_2 ( GC : Wide_Character ) 
>                                 return Boolean ;
> 
>     function Is_Greek_Character ( GS : Wide_String ) 
>                                 return Boolean ;
> 
>   end Greek ;
> 
>   --
>   -- Internal Body Package 
>   --
>   package body Greek is
> 
>     -- --------------------------- --
>     -- Use for Is_Greek_Character  --
>     -- --------------------------- --
> 
>     --
>     -- creates a greek constraint type
>     --
>     subtype Greek_Base is Wide_Character 
>                                 range Wide_Character'Val ( 16#370# )
>                                    .. Wide_Character'Val ( 16#1FFF# ) ;
> 
>     --
>     -- creates an excluded type
>     --
>     subtype Greek_Exclude_Subtype is Greek_Base
>                                 range Greek_Base'Val ( 16#03D8# )
>                                    .. Greek_Base'Val ( 16#0FFF# ) ;
> 
>     -- ----------------------------- --
>     -- Use for Is_Greek_Character_2  --
>     -- ----------------------------- --
> 
>     --
>     -- create lower greek characters type
>     --
>     subtype Lower_Greek_Character is Wide_Character 
>                                 range Wide_Character'Val ( 16#0370# )
>                                    .. Wide_Character'Val ( 16#03D7# ) ;
>     --
>     -- create upper greek characters type
>     --
>     subtype Upper_Greek_Character is Wide_Character 
>                                range Wide_Character 'Val ( 16#1000# )  
>                                   .. Wide_Character 'Val ( 16#1FFF# ) ;
> 
> 
> 
> 
>   --
>   -- Is_Greek_Character 
>   --
>   function Is_Greek_Character ( GC : Wide_Character ) 
>                               return Boolean is
> 
>     begin
>       --
>       -- Is character within the Greek base
>       --
>       if GC in Greek_Base then
>         --
>         -- Is character apart of the the non-Greek sub type
>         --
>         if GC in Greek_Exclude_Subtype then    
>           return False ;
>         else
>           return True ;
>         end if ;
>       else
>         return False ;
>       end if ;
>     end ;
> 
> 
>   --
>   -- Is_Greek_Character version number 2
>   --
>   function Is_Greek_Character_2 ( GC : Wide_Character ) 
>                               return Boolean is
> 
>     begin
>       --
>       -- Could use:
>       -- 
>       -- when Lower_Greek_Character | Upper_Greek_Character =>
>       --    return True ;
>       --
>       case GC is 
>          when Lower_Greek_Character =>
>             return True ;
>          when Upper_Greek_Character =>
>             return True ;
>          when others =>
>             return False ;
>       end case ;
>     end ;
> 
> 
>   function Is_Greek_Character ( GS : Wide_String ) 
>                               return Boolean is
> 
>     begin
>       --
>       -- Could use:
>       -- 
>       --
>       for Index in 1 .. GS'Length loop
>         --
>         -- if index-character of a string is not a Greek character
>         --
>         if not Is_Greek_Character_2 ( GS ( Index ) ) then 
>           return False ;
>         end if ;
>       end loop ;
>       --
>       -- String contains all Greek characters
>       --
>       return True ;
>     end ;
> 
>   end Greek ;
> 
> 
>   stz : wide_string ( 1..2 ) ;
> 
>   use Greek ;
> 
> begin
> --
>   put ( "Enter (2 character Greek string) => " ) ;
>   get ( stz ) ;
> --
>   put ( "Testing => " ) ;
>   put ( stz ) ;
>   new_line ;  
> --
>   if Is_Greek_Character ( stz ) then
>     put_line ( "Greek String ? => Yes" ) ;
>   else
>     put_line ( "Greek String ? => No" ) ;
>     --
>     -- Char 1 ?
>     --
>     if Is_Greek_Character ( stz ( 1 ) ) then
>       put_line ( "Character (1) Greek ? => Yes" ) ;
>     else
>       put_line ( "Character (1) Greek ? => No" ) ;
>     end if ;    
> 
>     --
>     -- Char 2 ?
>     --
>     if Is_Greek_Character_2 ( stz ( 2 ) ) then
>       put_line ( "Character (2) Greek ? => Yes" ) ;
>     else
>       put_line ( "Character (1) Greek ? => No" ) ;
>     end if ;
>   end if ;    
> --
> end tst ;
> 
> 
> 
> In <1193051690.350063@athprx04>, Christos Chryssochoidis <C.Chryssochoidis@gmail.com> writes:
>> Jacob Sparre Andersen wrote:
>>> Christos Chryssochoidis wrote:
>>>
>>>> I would like to define a subtype of Wide_Character for a program
>>>> that processes (unicode) text. This type would represent the Greek
>>>> letters.
>>> This sounds like what enumerated types are for.  You could do it like
>>> this:
>>>
>>>    type Faroese_Letter is ('a', 'A', 'b', 'B', 'd', 'D', 'ð', 'Ð',
>>>                            'e', 'E', [...],
>>>                            'y', 'Y', 'ý', 'Ý', 'æ', 'Æ', 'ø', 'Ø');
>>>    -- optional representation clause
>>>
>>>    function To_Wide_Wide_Character (Item : in Faroese_Letter)
>>>      return Wide_Wide_Character;
>>>
>>>    function To_Faroese_Letter (Item : in Wide_Wide_Character)
>>>      return Faroese_Letter;
>>>
>>> The conversion functions could make use of representation clauses,
>>> "Image" and "Value" functions, or tables.
>>>
>>>> Greek letters in Unicode, with all their diacritics, are
>>>> located in two separate ranges: 0370 - 03D7 and 1F00 - 1FFF. That's
>>>> 360 characters to write in an enumeration... Since gaps are not
>>>> allowed in ranges, I 'm thinking instead of defining such a type, to
>>>> define a function that would accept a Wide_Character as argument and
>>>> return a boolean value indicating whether the given Wide_Character
>>>> falls in the ranges of the Greek characters.
>>> This could be done very simply using Ada.Strings.Maps.
>>>
>>> How you should do it depends strongly on what you actually need your
>>> Greek_Letter type for.
>>>
>>> Greetings,
>>>
>>> Jacob
>> Thanks! Ada.Strings.Wide_Maps seems very helpful for what I want to do. 
>> Basically, what I would like to do is to write a program that given a 
>> text file in utf8 encoding, which would contain ancient greek text, 
>> which is written with all the diacritic marks on the letters, this 
>> program would load the contents of the file in memory, strip the 
>> in-memory text contents from all the diacritics except those used in 
>> today's "modern" Greek, and write the modified contents to a new file of 
>> the user's choosing. For this it would be nice if there were some 
>> package for regular expressions for Ada. Then if I succeeded in the 
>> mentioned task,  I 'd like to do some natural language processing (NLP, 
>> that is linguistics processing) with my program, but I don't know if Ada 
>> would be an appropriate language for such a task (NLP). I've seen on the 
>> web references to NLP applications with functional languages or logic 
>> programming languages, but not many implemented with imperative 
>> languages... (Sorry for getting of topic...)
>>
>> Thanks very much,
>> Christos
> 



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

end of thread, other threads:[~2007-10-24 12:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-21 19:15 Range types Christos Chryssochoidis
2007-10-21 20:23 ` Niklas Holsti
2007-10-21 21:28   ` Christos Chryssochoidis
2007-10-22  0:06     ` Robert A Duff
2007-10-22  7:23     ` Jacob Sparre Andersen
2007-10-22 11:14       ` Christos Chryssochoidis
2007-10-22 12:33         ` Georg Bauhaus
2007-10-22 19:08           ` Christos Chryssochoidis
2007-10-23 23:52         ` anon
2007-10-24 12:57           ` Christos Chryssochoidis
2007-10-21 21:53 ` anon
2007-10-21 22:38   ` Christos Chryssochoidis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox