home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / SentenceBreakData.java < prev    next >
Text File  |  1997-05-20  |  13KB  |  292 lines

  1. /*
  2.  * @(#)SentenceBreakData.java    1.5 97/01/17
  3.  *
  4.  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  5.  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  6.  *
  7.  * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  8.  *
  9.  *   The original version of this source code and documentation is copyrighted
  10.  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  11.  * materials are provided under terms of a License Agreement between Taligent
  12.  * and Sun. This technology is protected by multiple US and International
  13.  * patents. This notice and attribution to Taligent may not be removed.
  14.  *   Taligent is a registered trademark of Taligent, Inc.
  15.  *
  16.  * Permission to use, copy, modify, and distribute this software
  17.  * and its documentation for NON-COMMERCIAL purposes and without
  18.  * fee is hereby granted provided that this copyright notice
  19.  * appears in all copies. Please refer to the file "copyright.html"
  20.  * for further important copyright and licensing information.
  21.  *
  22.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  23.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  24.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  25.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  26.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  27.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  28.  *
  29.  */
  30.  
  31. package java.text;
  32.  
  33. /**
  34.  * The SentenceBreakData contains data used by SimpleTextBoundary
  35.  * to determine sentence breaks.
  36.  * @see #BreakIterator
  37.  */
  38. final class SentenceBreakData extends TextBoundaryData
  39. {
  40.     private static final byte other = 0;
  41.     // lower case letters, digits...
  42.     private static final byte space = 1;
  43.     // spaces...
  44.     private static final byte terminator = 2;
  45.     // period, questionmark...
  46.     private static final byte ambiguosTerm = 3;
  47.     // Ambiguos terminator
  48.     private static final byte openBracket = 4;
  49.     // open brackets
  50.     private static final byte closeBracket = 5;
  51.     // close brackets
  52.     private static final byte cjk = 6;
  53.     // Characters where the previous sentence does not have a space
  54.     // after a terminator. Common in Japanese, Chinese, and Korean
  55.     private static final byte paragraphBreak = 7;
  56.     // Paragraph break
  57.     private static final byte lowerCase = 8;
  58.     // Lower case
  59.     private static final byte upperCase = 9;
  60.     private static final byte number = 10;
  61.     // digit
  62.     private static final int COL_COUNT_BACKWARD = 11;
  63.     private static final byte quote = 11;
  64.     private static final int COL_COUNT_FORWARD = 12;
  65.     private static final byte SI = (byte)0x80;
  66.     private static final byte kSentenceForwardData[] =
  67.     {
  68.         // other        space               terminator      ambTerm
  69.         // open         close               CJK             PB
  70.         // lower        upper               digit           Quote
  71.         (byte)(0),      (byte)(0),          (byte)(0),     (byte)(0),
  72.         (byte)(0),      (byte)(0),          (byte)(0),     (byte)(0),
  73.         (byte)(0),      (byte)(0),          (byte)(0),     (byte)(0),     //0
  74.  
  75.         (byte)(SI+1),   (byte)(SI+1),       (byte)(SI+2),   (byte)(SI+5),
  76.         (byte)(SI+1),   (byte)(SI+1),       (byte)(SI+1),   (byte)(SI+4),
  77.         (byte)(SI+1),   (byte)(SI+8),       (byte)(SI+9),   (byte)(SI+1), //1
  78.  
  79.         (byte)(SI+0),   (byte)(SI+3),       (byte)(SI+2),   (byte)(SI+5),
  80.         (byte)(SI+1),   (byte)(SI+2),       (byte)(SI+0),   (byte)(SI+4),
  81.         (byte)(SI+0),   (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+2), //2
  82.  
  83.         (byte)(SI+0),   (byte)(SI+3),       (byte)(SI+0),   (byte)(SI+0),
  84.         (byte)(SI+0),   (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+4),
  85.         (byte)(SI+0),   (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+0), //3
  86.  
  87.         (byte)(SI+0),   (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+0),
  88.         (byte)(SI+0),   (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+0),
  89.         (byte)(SI+0),   (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+0), //4
  90.  
  91.         (byte)(SI+0),   (byte)(SI+6),       (byte)(SI+2),   (byte)(SI+5),
  92.         (byte)(SI+1),   (byte)(SI+5),       (byte)(SI+0),   (byte)(SI+4),
  93.         (byte)(SI+1),   (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+5), //5
  94.  
  95.         (byte)(SI+0),   (byte)(SI+6),       (byte)(SI+0),   (byte)(SI+0),
  96.         (byte)(SI+7),   (byte)(SI+1),       (byte)(SI+0),   (byte)(SI+4),
  97.         (byte)(SI+1),   (byte)(SI+0),       (byte)(SI+1),   (byte)(SI+0), //6
  98.  
  99.         (byte)(SI+0),   (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+0),
  100.         (byte)(7),      (byte)(SI+0),       (byte)(SI+0),   (byte)(SI+0),
  101.         (byte)(SI+1),   (byte)(0),          (byte)(SI+0),   (byte)(SI+0), //7
  102.  
  103.         (byte)(SI+1),   (byte)(SI+1),       (byte)(SI+2),   (byte)(SI+8),
  104.         (byte)(SI+1),   (byte)(SI+5),       (byte)(SI+0),   (byte)(SI+4),
  105.         (byte)(SI+1),   (byte)(SI+8),       (byte)(SI+9),   (byte)(SI+5), //8
  106.  
  107.         (byte)(SI+1),   (byte)(SI+1),       (byte)(SI+2),   (byte)(SI+9),
  108.         (byte)(SI+1),   (byte)(SI+5),       (byte)(SI+0),   (byte)(SI+4),
  109.         (byte)(SI+1),   (byte)(SI+1),       (byte)(SI+9),   (byte)(SI+5), //9
  110.     };
  111.  
  112.     private static final WordBreakTable kSentenceForward
  113.         = new WordBreakTable(COL_COUNT_FORWARD, kSentenceForwardData);
  114.  
  115.     private static final byte kSentenceBackwardData[] =
  116.     {
  117.         // other        space         terminator             ambTerm
  118.         // open         close         CJK                    PB
  119.         // lower        upper         digit
  120.         (byte)(0),     (byte)(0),     (byte)(0),        (byte)(0),
  121.         (byte)(0),     (byte)(0),     (byte)(0),        (byte)(0),
  122.         (byte)(0),     (byte)(0),     (byte)(0),
  123.  
  124.         (byte)(SI+1),   (byte)(SI+1),   (byte)(SI+1),   (byte)(SI+1),
  125.         (byte)(SI+1),   (byte)(SI+1),   (byte)(SI+4),   (byte)(SI+1),
  126.         (byte)(SI+2),   (byte)(SI+1),   (byte)(SI+1),
  127.  
  128.         (byte)(SI+1),   (byte)(SI+3),   (byte)(SI+0),   (byte)(SI+2),
  129.         (byte)(SI+3),   (byte)(SI+3),   (byte)(SI+4),   (byte)(SI+0),
  130.         (byte)(SI+2),   (byte)(SI+1),   (byte)(SI+1),
  131.  
  132.         (byte)(SI+1),   (byte)(SI+3),   (byte)(SI+0),   (byte)(SI+2),
  133.         (byte)(SI+3),   (byte)(SI+3),   (byte)(SI+4),   (byte)(SI+0),
  134.         (byte)(SI+2),   (byte)(SI+1),   (byte)(SI+1),
  135.  
  136.         (byte)(SI+4),   (byte)(SI+3),   (byte)(SI+0),   (byte)(SI+4),
  137.         (byte)(SI+4),   (byte)(SI+4),   (byte)(SI+4),   (byte)(SI+0),
  138.         (byte)(SI+2),   (byte)(SI+4),   (byte)(SI+4)
  139.     };
  140.  
  141.     private static final WordBreakTable kSentenceBackward
  142.     = new WordBreakTable(COL_COUNT_BACKWARD, kSentenceBackwardData);
  143.  
  144.     private static final int kRawMapping[] =
  145.     {
  146.         other, //UNASSIGNED        = 0,
  147.         upperCase, //UPPERCASE_LETTER    = 1,
  148.         lowerCase, //LOWERCASE_LETTER    = 2,
  149.         other, //TITLECASE_LETTER    = 3,
  150.         other, //MODIFIER_LETTER        = 4,
  151.         other, //OTHER_LETTER        = 5,
  152.         other, //NON_SPACING_MARK    = 6,
  153.         other, //ENCLOSING_MARK        = 7,
  154.         other, //COMBINING_SPACING_MARK    = 8,
  155.         number, //DECIMAL_DIGIT_NUMBER    = 9,
  156.         number, //LETTER_NUMBER        = 10,
  157.         number, //OTHER_NUMBER        = 11,
  158.         space, //SPACE_SEPARATOR        = 12,
  159.         space, //LINE_SEPARATOR        = 13,
  160.         space, //PARAGRAPH_SEPARATOR    = 14,            ???????
  161.         other, //CONTROL            = 15,
  162.         other, //PRIVATE_USE        = 16,
  163.         other, //FORMAT        = 17,
  164.         other, //????        = 18,
  165.         other, //SURROGATE        = 19,
  166.         other, //DASH_PUNCTUATION    = 20,
  167.         openBracket, //START_PUNCTUATION    = 21,
  168.         closeBracket, //END_PUNCTUATION        = 22,
  169.         other, //CONNECTOR_PUNCTUATION    = 23,
  170.         other, //OTHER_PUNCTUATION    = 24,
  171.         other, //MATH_SYMBOL        = 25,
  172.         other, //CURRENCY_SYMBOL        = 26,
  173.         other, //MODIFIER_SYMBOL        = 27,
  174.         other, //OTHER_SYMBOL        = 28;
  175.     };
  176.  
  177.  /* private static final int kRawMapping[] =
  178.     {
  179.         other, //00   Invalid
  180.         space, //01   SpaceWhitespace
  181.         space, //02   ZerowidthSpaceWhitespace
  182.         other, //03   ISOcontrol
  183.         space, //04   WhitespaceISOcontrol
  184.         other, //05   Dash
  185.         other, //06   Punctuation
  186.         other, //07   DashPunctuation
  187.         other, //08   HyphenPunctuation
  188.         other, //09   DashHyphenPunctuation
  189.         other, //10   PunctuationQuotationmark
  190.         other, //11   PunctuationTerminalpunctuation
  191.         other, //12   Currencysymbol
  192.         closeBracket, //13   PunctuationPairedpunctuation
  193.         closeBracket, //14   PunctuationQuotationmarkPairedpunctuation
  194.         openBracket, //15   PunctuationPairedpunctuationLeftofpair
  195.         openBracket, //16   PunctuationQuotationmarkPairedpunctuationLeftofpair
  196.         other, //17   PunctuationPairedpunctuationCombining
  197.         other, //18   PunctuationPairedpunctuationLeftofpairCombining
  198.         other, //19   Composite
  199.         number, //20   Numeric
  200.         number, //21   CompositeNumeric
  201.         other, //22   PunctuationAlphabetic
  202.         other, //23   Diacritic
  203.         other, //24   CompositeDiacritic
  204.         other, //25   PunctuationIdentifierpart
  205.         number, //26   DecimaldigitNumericIdentifierpart
  206.         number, //27   HexdigitDecimaldigitNumericIdentifierpart
  207.         other, //28   AlphabeticIdentifierpart
  208.         other, //29   CombiningAlphabeticIdentifierpart
  209.         other, //30   CompositeAlphabeticIdentifierpart
  210.         other, //31   CombiningCompositeAlphabeticIdentifierpart
  211.         number, //32   NumericAlphabeticIdentifierpart
  212.         number, //33   CompositeNumericAlphabeticIdentifierpart
  213.         other, //34   IdeographicIdentifierpart
  214.         other, //35   NumericIdeographicIdentifierpart
  215.         other, //36   CombiningDiacriticIdentifierpart
  216.         other, //37   ExtenderIdentifierpart
  217.         other, //38   CompositeExtenderIdentifierpart
  218.         other, //39   DiacriticExtenderIdentifierpart
  219.         other, //40   PunctuationDiacriticExtenderIdentifierpart
  220.         other, //41   ZerowidthWhitespaceBidicontrolIgnorablecontrol
  221.         other, //42   ZerowidthWhitespaceJoincontrolIgnorablecontrol
  222.         other, //43   ZerowidthWhitespaceFormatcontrolIgnorablecontrol
  223.         lowerCase, //44   AlphabeticIdentifierpartLower
  224.         lowerCase, //45   CompositeAlphabeticIdentifierpartLower
  225.         lowerCase, //46   HexdigitAlphabeticIdentifierpartLower
  226.         upperCase, //47   AlphabeticIdentifierpartUpper
  227.         upperCase, //48   CompositeAlphabeticIdentifierpartUpper
  228.         upperCase, //49   HexdigitAlphabeticIdentifierpartUpper
  229.         other, //50   CompositeAlphabeticIdentifierpartTitle
  230.         other, //51   Marknonspacing
  231.         other, //52   CombiningMarknonspacing
  232.         other, //53   CombiningIdentifierpartMarknonspacing
  233.         other, //54   AlphabeticIdentifierpartMarknonspacing
  234.         other, //55   CombiningAlphabeticIdentifierpartMarknonspacing
  235.         other, //56   CompositeAlphabeticIdentifierpartMarknonspacing
  236.         other, //57   CombiningCompositeAlphabeticIdentifierpartMarknonspacing
  237.         other, //58   CombiningDiacriticIdentifierpartMarknonspacing
  238.         other, //59   CombiningCompositeDiacriticIdentifierpartMarknonspacing
  239.         space, //60   WhitespaceNongraphicSeparator
  240.         other, //61   WhitespaceISOcontrolNongraphicSeparator
  241.         space, //62   SpaceWhitespaceNongraphicNobreak
  242.         space, //63   ZerowidthSpaceWhitespaceIgnorablecontrolNongraphicNobreak
  243.     }; */
  244.  
  245.     private static SpecialMapping kExceptionChar[] =
  246.     {
  247.         //note: the ranges in this table must be sorted in ascending order
  248.         //as required by the UnicodeClassMapping class.
  249.         new SpecialMapping(ASCII_HORIZONTAL_TABULATION, space),
  250.         new SpecialMapping(ASCII_LINEFEED, space),
  251.         new SpecialMapping(ASCII_FORM_FEED, terminator),
  252.  
  253.         new SpecialMapping(ASCII_EXCLAMATION_MARK, terminator),
  254.         new SpecialMapping(ASCII_QUOTATION_MARK, quote),
  255.  
  256.         new SpecialMapping(ASCII_APOSTROPHE, quote),
  257.  
  258.         new SpecialMapping(ASCII_FULL_STOP, ambiguosTerm),
  259.         new SpecialMapping(ASCII_QUESTION_MARK, terminator),
  260.         new SpecialMapping(ASCII_NONBREAKING_SPACE, other),
  261.         new SpecialMapping(PUNCTUATION_PARAGRAPH_SEPARATOR, paragraphBreak),
  262.         new SpecialMapping(PUNCTUATION_IDEOGRAPHIC_FULL_STOP, terminator),
  263.         new SpecialMapping(HIRAGANA_LETTER_SMALL_A, HIRAGANA_LETTER_VU, cjk),
  264.         new SpecialMapping(COMBINING_KATAKANA_HIRAGANA_VOICED_SOUND_MARK,
  265.                            HIRAGANA_SEMIVOICED_SOUND_MARK, cjk),         // cjk
  266.         new SpecialMapping(KATAKANA_LETTER_SMALL_A, KATAKANA_LETTER_SMALL_KE,
  267.                            cjk),   // cjk
  268.         new SpecialMapping(UNICODE_LOW_BOUND_HAN, UNICODE_HIGH_BOUND_HAN, cjk),
  269.         new SpecialMapping(CJK_COMPATIBILITY_F900, CJK_COMPATIBILITY_FA2D,cjk),
  270.         new SpecialMapping(UNICODE_ZERO_WIDTH_NON_BREAKING_SPACE, other),
  271.     };
  272.  
  273.     private static final UnicodeClassMapping kSentenceMap
  274.         = new UnicodeClassMapping(kRawMapping, kExceptionChar);
  275.  
  276.     public WordBreakTable forward()
  277.     {
  278.         return kSentenceForward;
  279.     }
  280.  
  281.     public WordBreakTable backward()
  282.     {
  283.         return kSentenceBackward;
  284.     }
  285.  
  286.     public UnicodeClassMapping map()
  287.     {
  288.         return kSentenceMap;
  289.     }
  290. }
  291.  
  292.