home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / text / SentenceBreakData.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  17.7 KB  |  363 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)SentenceBreakData.java    1.17 98/08/11
  3.  *
  4.  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  5.  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  6.  *
  7.  * Portions copyright (c) 1996-1998 Sun Microsystems, Inc.
  8.  * All Rights Reserved.
  9.  *
  10.  * The original version of this source code and documentation
  11.  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  12.  * subsidiary of IBM. These materials are provided under terms
  13.  * of a License Agreement between Taligent and Sun. This technology
  14.  * is protected by multiple US and International patents.
  15.  *
  16.  * This notice and attribution to Taligent may not be removed.
  17.  * Taligent is a registered trademark of Taligent, Inc.
  18.  *
  19.  * Permission to use, copy, modify, and distribute this software
  20.  * and its documentation for NON-COMMERCIAL purposes and without
  21.  * fee is hereby granted provided that this copyright notice
  22.  * appears in all copies. Please refer to the file "copyright.html"
  23.  * for further important copyright and licensing information.
  24.  *
  25.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  26.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  27.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  28.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  29.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  30.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  31.  *
  32.  */
  33.  
  34. package java.text;
  35.  
  36. /**
  37.  * The SentenceBreakData contains data used by SimpleTextBoundary
  38.  * to determine sentence breaks.
  39.  * @see #BreakIterator
  40.  */
  41. final class SentenceBreakData extends TextBoundaryData
  42. {
  43.     private static final byte other = 0;
  44.     // lower case letters, digits...
  45.     private static final byte space = 1;
  46.     // spaces...
  47.     private static final byte terminator = 2;
  48.     // period, questionmark...
  49.     private static final byte ambiguosTerm = 3;
  50.     // Ambiguos terminator
  51.     private static final byte openBracket = 4;
  52.     // open brackets
  53.     private static final byte closeBracket = 5;
  54.     // close brackets
  55.     private static final byte cjk = 6;
  56.     // Characters where the previous sentence does not have a space
  57.     // after a terminator. Common in Japanese, Chinese, and Korean
  58.     private static final byte paragraphBreak = 7;
  59.     // Paragraph break
  60.     private static final byte lowerCase = 8;
  61.     // Lower case
  62.     private static final byte upperCase = 9;
  63.     private static final byte number = 10;
  64.  
  65.     private static final byte quote = 11;
  66.     private static final byte nsm = 12;
  67.     private static final byte EOS = 13;
  68.  
  69.     // digit
  70.     private static final int COL_COUNT = 14;
  71.  
  72.     private static final byte SI = (byte)0x80;
  73.     private static final byte STOP = (byte) 0;
  74.     private static final byte SI_STOP = (byte)SI + STOP;
  75.  
  76.     public SentenceBreakData() {
  77.         super(kSentenceForward, kSentenceBackward, kSentenceMap);
  78.     }
  79.  
  80.     private static final byte kSentenceForwardData[] =
  81.     {
  82.         // other       space          terminator     ambTerm
  83.         // open        close          CJK            PB
  84.         // lower       upper          digit          Quote
  85.         // nsm            EOS
  86.  
  87.         // 0
  88.         STOP,          STOP,          STOP,          STOP,
  89.         STOP,          STOP,          STOP,          STOP,
  90.         STOP,          STOP,          STOP,          STOP,
  91.         STOP,          STOP,
  92.  
  93.         // 1
  94.         (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+2),  (byte)(SI+5),
  95.         (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+4),
  96.         (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+1),
  97.         (byte)(SI+1),  SI_STOP,
  98.  
  99.         // 2
  100.         SI_STOP,       (byte)(SI+3),  (byte)(SI+2),  (byte)(SI+5),
  101.         SI_STOP,       (byte)(SI+2),  SI_STOP,       (byte)(SI+4),
  102.         SI_STOP,       SI_STOP,       SI_STOP,       (byte)(SI+2),
  103.         (byte)(SI+2),  SI_STOP,
  104.  
  105.         // 3
  106.         SI_STOP,       (byte)(SI+3),  SI_STOP,       SI_STOP,
  107.         SI_STOP,       SI_STOP,       SI_STOP,       (byte)(SI+4),
  108.         SI_STOP,       SI_STOP,       SI_STOP,       SI_STOP,
  109.         (byte)(SI+3),  SI_STOP,
  110.  
  111.         // 4
  112.         SI_STOP,       SI_STOP,       SI_STOP,       SI_STOP,
  113.         SI_STOP,       SI_STOP,       SI_STOP,       SI_STOP,
  114.         SI_STOP,       SI_STOP,       SI_STOP,       SI_STOP,
  115.         SI_STOP,       SI_STOP,
  116.  
  117.         // 5
  118.         (byte)(SI+1),  (byte)(SI+6),  (byte)(SI+2),  (byte)(SI+5),
  119.         (byte)(SI+1),  (byte)(SI+5),  SI_STOP,       (byte)(SI+4),
  120.         (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+5),
  121.         (byte)(SI+5),  SI_STOP,
  122.  
  123.         // 6
  124.         SI_STOP,       (byte)(SI+6),  SI_STOP,       SI_STOP,
  125.         (byte)(SI+7),  (byte)(SI+1),  SI_STOP,       (byte)(SI+4),
  126.         (byte)(SI+1),  SI_STOP,       (byte)(SI+1),  SI_STOP,
  127.         (byte)(SI+6),  SI_STOP,
  128.  
  129.         // 7
  130.         SI_STOP,       SI_STOP,       SI_STOP,       SI_STOP,
  131.         (byte)(7),     SI_STOP,       SI_STOP,       SI_STOP,
  132.         (byte)(SI+1),  STOP,          SI_STOP,       SI_STOP,
  133.         (byte)(SI+7),  SI_STOP,
  134.  
  135.         // 8
  136.         (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+2),  (byte)(SI+8),
  137.         (byte)(SI+1),  (byte)(SI+5),  (byte)(SI+1),  (byte)(SI+4),
  138.         (byte)(SI+1),  (byte)(SI+8),  (byte)(SI+9),  (byte)(SI+5),
  139.         (byte)(SI+8),  SI_STOP,
  140.  
  141.         // 9
  142.         (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+2),  (byte)(SI+9),
  143.         (byte)(SI+1),  (byte)(SI+5),  (byte)(SI+1),  (byte)(SI+4),
  144.         (byte)(SI+1),  (byte)(SI+1),  (byte)(SI+9),  (byte)(SI+5),
  145.         (byte)(SI+9),  SI_STOP
  146.     };
  147.  
  148.     private static final WordBreakTable kSentenceForward
  149.         = new WordBreakTable(COL_COUNT, kSentenceForwardData);
  150.  
  151.     private static final byte kSentenceBackwardData[] =
  152.     {
  153.         // other       space          terminator     ambTerm
  154.         // open        close          CJK            PB
  155.         // lower       upper          digit          quote
  156.         // nsm            EOS
  157.  
  158.         // 0
  159.         STOP,          STOP,          STOP,          STOP,
  160.         STOP,          STOP,          STOP,          STOP,
  161.         STOP,          STOP,          STOP,          STOP,
  162.         STOP,          STOP,
  163.  
  164.         // 1
  165.         (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+2),
  166.         (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+3),  STOP,
  167.         (byte)(SI+2),  (byte)(SI+3),  (byte)(SI+2),  (byte)(SI+2),
  168.         (byte)(SI+1),  STOP,
  169.  
  170.         // 2
  171.         (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+2),
  172.         (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+3),  STOP,
  173.         (byte)(SI+2),  (byte)(SI+3),  (byte)(SI+2),  (byte)(SI+2),
  174.         (byte)(SI+2),  STOP,
  175.  
  176.         // 3
  177.         (byte)(SI+2),  (byte)(SI+4),  (byte)(SI+2),  (byte)(SI+2),
  178.         (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+3),  STOP,
  179.         (byte)(SI+3),  (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+2),
  180.         (byte)(SI+3),  STOP,
  181.  
  182.         // 4
  183.         (byte)(SI+2),  (byte)(SI+4),  SI_STOP,       SI_STOP,
  184.         (byte)(SI+2),  (byte)(SI+2),  (byte)(SI+3),  STOP,
  185.         (byte)(SI+2),  (byte)(SI+3),  (byte)(SI+2),  (byte)(SI+2),
  186.         (byte)(SI+4),  STOP
  187.     };
  188.  
  189.     private static final WordBreakTable kSentenceBackward
  190.         = new WordBreakTable(COL_COUNT, kSentenceBackwardData);
  191.  
  192.     private static final int kRawMapping[] =
  193.     {
  194.         other,        // UNASSIGNED             = 0,
  195.         upperCase,    // UPPERCASE_LETTER       = 1,
  196.         lowerCase,    // LOWERCASE_LETTER       = 2,
  197.         other,        // TITLECASE_LETTER       = 3,
  198.         other,        // MODIFIER_LETTER        = 4,
  199.         other,        // OTHER_LETTER           = 5,
  200.         nsm,          // NON_SPACING_MARK       = 6,
  201.         nsm,          // ENCLOSING_MARK         = 7,
  202.         other,        // COMBINING_SPACING_MARK = 8,
  203.         number,       // DECIMAL_DIGIT_NUMBER   = 9,
  204.         number,       // LETTER_NUMBER          = 10,
  205.         number,       // OTHER_NUMBER           = 11,
  206.         space,        // SPACE_SEPARATOR        = 12,
  207.         space,        // LINE_SEPARATOR         = 13,
  208.         space,        // PARAGRAPH_SEPARATOR    = 14,            ???????
  209.         other,        // CONTROL                = 15,
  210.         other,        // PRIVATE_USE            = 16,
  211.         other,        // FORMAT                 = 17,
  212.         other,        // ????                   = 18,
  213.         other,        // SURROGATE              = 19,
  214.         other,        // DASH_PUNCTUATION       = 20,
  215.         openBracket,  // START_PUNCTUATION      = 21,
  216.         closeBracket, // END_PUNCTUATION        = 22,
  217.         other,        // CONNECTOR_PUNCTUATION  = 23,
  218.         other,        // OTHER_PUNCTUATION      = 24,
  219.         other,        // MATH_SYMBOL            = 25,
  220.         other,        // CURRENCY_SYMBOL        = 26,
  221.         other,        // MODIFIER_SYMBOL        = 27,
  222.         other,        // OTHER_SYMBOL           = 28;
  223.     };
  224.  
  225.     private static final SpecialMapping kExceptionChar[] =
  226.     {
  227.         //note: the ranges in this table must be sorted in ascending order
  228.         //as required by the UnicodeClassMapping class.
  229.         new SpecialMapping(ASCII_HORIZONTAL_TABULATION, space),
  230.         new SpecialMapping(ASCII_LINEFEED, space),
  231.         new SpecialMapping(ASCII_FORM_FEED, terminator),
  232.         new SpecialMapping(ASCII_CARRIAGE_RETURN, space),
  233.  
  234.         new SpecialMapping(ASCII_EXCLAMATION_MARK, terminator),
  235.         new SpecialMapping(ASCII_QUOTATION_MARK, quote),
  236.  
  237.         new SpecialMapping(ASCII_APOSTROPHE, quote),
  238.  
  239.         new SpecialMapping(ASCII_FULL_STOP, ambiguosTerm),
  240.         new SpecialMapping(ASCII_QUESTION_MARK, terminator),
  241.         new SpecialMapping(ASCII_NONBREAKING_SPACE, other),
  242.         new SpecialMapping(PUNCTUATION_LINE_SEPARATOR, space),
  243.         new SpecialMapping(PUNCTUATION_PARAGRAPH_SEPARATOR, paragraphBreak),
  244.         new SpecialMapping(PUNCTUATION_IDEOGRAPHIC_FULL_STOP, terminator),
  245.         new SpecialMapping(HIRAGANA_LETTER_SMALL_A, HIRAGANA_LETTER_VU, cjk),
  246.         new SpecialMapping(COMBINING_KATAKANA_HIRAGANA_VOICED_SOUND_MARK,
  247.                            HIRAGANA_SEMIVOICED_SOUND_MARK, cjk),         // cjk
  248.         new SpecialMapping(KATAKANA_LETTER_SMALL_A, KATAKANA_LETTER_SMALL_KE,
  249.                            cjk),   // cjk
  250.         new SpecialMapping(UNICODE_LOW_BOUND_HAN, UNICODE_HIGH_BOUND_HAN, cjk),
  251.         new SpecialMapping(CJK_COMPATIBILITY_F900, CJK_COMPATIBILITY_FA2D,cjk),
  252.         new SpecialMapping(UNICODE_ZERO_WIDTH_NON_BREAKING_SPACE, other),
  253.         new SpecialMapping(FULLWIDTH_EXCLAMATION_MARK, terminator),
  254.         new SpecialMapping(FULLWIDTH_FULL_STOP, ambiguosTerm),
  255.         new SpecialMapping(FULLWIDTH_QUESTION_MARK, terminator),
  256.         new SpecialMapping(END_OF_STRING, EOS)
  257.     };
  258.  
  259.     private static final boolean SentenceExceptionFlags[] = {
  260.         false,            // kNonCharacter         = 0,
  261.         false,            // kUppercaseLetter      = 1,
  262.         false,            // kLowercaseLetter      = 2,
  263.         false,            // kTitlecaseLetter      = 3,
  264.         false,            // kModifierLetter       = 4,
  265.         true,             // kOtherLetter          = 5,
  266.         true,             // kNonSpacingMark       = 6,
  267.         false,            // kEnclosingMark        = 7,
  268.         false,            // kCombiningSpacingMark = 8,
  269.         false,            // kDecimalNumber        = 9,
  270.         false,            // kLetterNumber         = 10,
  271.         false,            // kOtherNumber          = 11,
  272.         true,             // kSpaceSeparator       = 12,
  273.         true,             // kLineSeparator        = 13,
  274.         true,             // kParagraphSeparator   = 14,
  275.         true,             // kControlCharacter     = 15,
  276.         true,             // kFormatCharacter      = 16,
  277.         false,            // UNDEFINED             = 17,
  278.         false,            // kPrivateUseCharacter  = 18,
  279.         false,            // kSurrogate            = 19,
  280.         false,            // kDashPunctuation      = 20,
  281.         false,            // kOpenPunctuation      = 21,
  282.         false,            // kClosePunctuation     = 22,
  283.         false,            // kConnectorPunctuation = 23,
  284.         true,             // kOtherPunctuation     = 24,
  285.         false,            // kMathSymbol           = 25,
  286.         false,            // kCurrencySymbol       = 26,
  287.         false,            // kModifierSymbol       = 27,
  288.         false             // kOtherSymbol          = 28
  289.     };
  290.  
  291.     private static final int kSentenceAsciiValues[] = {
  292.         //  null    soh     stx     etx     eot     enq     ask     bell
  293.             other,  other,  other,  other,  other,  other,  other,  other,
  294.         //  bs      ht      lf     vt     ff          cr     so     si
  295.             other,  space,  space, other, terminator, space, other, other,
  296.         //  dle     dc1     dc2     dc3     dc4     nak     syn     etb
  297.             other,  other,  other,  other,  other,  other,  other,  other,
  298.         //  can     em      sub     esc     fs      gs      rs      us
  299.             other,  other,  other,  other,  other,  other,  other,  other,
  300.         //  sp      !           "      #      $      %      &      '
  301.             space,  terminator, quote, other, other, other, other, quote,
  302.         //  (            )             *      +      ,      -      .             /
  303.             openBracket, closeBracket, other, other, other, other, ambiguosTerm, other,
  304.         //  0       1       2       3       4       5       6       7
  305.             number, number, number, number, number, number, number, number,
  306.         //  8       9       :       ;       <       =       >       ?
  307.             number, number, other,  other,  other,  other,  other,  terminator,
  308.         //  @       A          B          C          D          E          F          G
  309.             other,  upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase,
  310.         //  H          I          J          K          L          M          N          O
  311.             upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase,
  312.         //  P          Q          R          S          T          U          V          W
  313.             upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase,
  314.         //  X          Y          Z          [            \      ]             ^      _
  315.             upperCase, upperCase, upperCase, openBracket, other, closeBracket, other, other,
  316.         //  `       a          b          c          d          e          f          g
  317.             other,  lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase,
  318.         //  h          i          j          k          l          m          n          o
  319.             lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase,
  320.         //  p          q          r          s          t          u          v          w
  321.             lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase,
  322.         //  x          y          z          {            |      }             ~      del
  323.             lowerCase, lowerCase, lowerCase, openBracket, other, closeBracket, other, other,
  324.         //  ctrl    ctrl    ctrl    ctrl    ctrl    ctrl    ctrl    ctrl
  325.             other,  other,  other,  other,  other,  other,  other,  other,
  326.         //  ctrl    ctrl    ctrl    ctrl    ctrl    ctrl    ctrl    ctrl
  327.             other,  other,  other,  other,  other,  other,  other,  other,
  328.         //  ctrl    ctrl    ctrl    ctrl    ctrl    ctrl    ctrl    ctrl
  329.             other,  other,  other,  other,  other,  other,  other,  other,
  330.         //  ctrl    ctrl    ctrl    ctrl    ctrl    ctrl    ctrl    ctrl
  331.             other,  other,  other,  other,  other,  other,  other,  other,
  332.         //  nbsp      inv-!     cents     pounds    currency  yen       broken-bar  section
  333.             other,  other,  other,  other,  other,  other,  other,  other,
  334.         //  umlaut    copyright super-a   gui-left  not       soft-hyph registered  macron
  335.             other,  other,  lowerCase, openBracket, other, other, other, other,
  336.         //  degree    +/-       super-2   super-3   acute     micro     paragraph  bullet
  337.             other,  other,  number, number, other,  lowerCase, other, other,
  338.         //  cedilla   super-1   super-o   gui-right 1/4       1/2       3/4      inv-?
  339.             other,  lowerCase, other, closeBracket, number, number, number, other,
  340.         //  A-grave   A-acute   A-hat     A-tilde   A-umlaut A-ring    AE        C-cedilla
  341.             upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase,
  342.         //  E-grave   E-acute   E-hat     E-umlaut  I-grave   I-acute   I-hat    I-umlaut
  343.             upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase,
  344.         //  Edh       N-tilde   O-grave   O-acute   O-hat     O-tilde   O-umlaut times
  345.             upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, other,
  346.         //  O=slash   U-grave   U-acute   U-hat     U-umlaut  Y-acute   Thorn    ess-zed
  347.             upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, upperCase, lowerCase,
  348.         //  a-grave   a-acute   a-hat     a-tilde   a-umlaut  a-ring    ae       c-cedilla
  349.             lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase,
  350.         //  e-grave   e-acute   e-hat     e-umlaut  i-grave   i-acute   i-hat    i-umlaut
  351.             lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase,
  352.         //  edh       n-tilde   o-grave   o-acute   o-hat     o-tilde   o-umlaut  over
  353.             lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, other,
  354.         //  o-slash   u-grave   u-acute   u-hat     u-umlaut  y-acute   thorn    y=umlaut
  355.             lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase, lowerCase
  356.     };
  357.  
  358.     private static final UnicodeClassMapping kSentenceMap
  359.         = new UnicodeClassMapping(kRawMapping, kExceptionChar, SentenceExceptionFlags,
  360.         kSentenceAsciiValues);
  361. }
  362.  
  363.