JAVA: Metadata changes, introduction of PhoneNumberOfflineGeocoder class and small...
authorlararennie@google.com <lararennie@google.com@ee073f10-1060-11df-b6a4-87a95322a99c>
Tue, 24 May 2011 07:57:29 +0000 (07:57 +0000)
committerlararennie@google.com <lararennie@google.com@ee073f10-1060-11df-b6a4-87a95322a99c>
Tue, 24 May 2011 07:57:29 +0000 (07:57 +0000)
git-svn-id: http://libphonenumber.googlecode.com/svn/trunk@206 ee073f10-1060-11df-b6a4-87a95322a99c

28 files changed:
java/release_notes.txt
java/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java
java/src/com/google/i18n/phonenumbers/PhoneNumberOfflineGeocoder.java [new file with mode: 0644]
java/src/com/google/i18n/phonenumbers/Phonenumber.java
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CY
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GF
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GQ
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JM
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KP
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MQ
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PA
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PW
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PY
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SB
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SR
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TO
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UY
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VI
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VU
java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java
java/test/com/google/i18n/phonenumbers/PhoneNumberOfflineGeocoderTest.java [new file with mode: 0644]
resources/PhoneNumberMetaData.xml

index 59f43ef..1963e56 100644 (file)
@@ -1,3 +1,13 @@
+May 24th, 2011
+* Code changes:
+ - Phonenumber now implements Serializable.
+ - findNumbers doesn't accept numbers with mis-matched brackets as phone-numbers
+ - An offline phone number geocoder has been added. The current implementation just returns the
+   region name for the phone number; more detailed geocoding will be added later.
+* Metadata changes:
+ - New countries: GF, KP, NC, PA, PF, PW, PY, SB, SR, TO, UY, VU
+ - Updates: CY, CZ, ES, GB, GQ, JM, MQ, TN, VI
+
 May 9th, 2011
 * Code changes:
  - Fixed potential for a null-ptr exception in getExampleNumber
index 09eb35c..68ad3ad 100644 (file)
@@ -70,14 +70,38 @@ final class PhoneNumberMatcher implements Iterator<PhoneNumberMatch> {
       Pattern.compile("(?:(?:[0-3]?\\d/[01]?\\d)|(?:[01]?\\d/[0-3]?\\d))/(?:[12]\\d)?\\d{2}");
 
   /**
+   * Pattern to check that brackets match. Opening brackets should be closed within a phone number.
+   * This also checks that there is something inside the brackets. Having no brackets at all is also
+   * fine.
+   */
+  private static final Pattern MATCHING_BRACKETS;
+
+  /**
    * Matches white-space, which may indicate the end of a phone number and the start of something
    * else (such as a neighbouring zip-code).
    */
   private static final Pattern GROUP_SEPARATOR = Pattern.compile("\\p{Z}+");
 
   static {
-    /* Builds the PATTERN regular expression. The building blocks below exist to make the pattern
-     * more easily understood. */
+    /* Builds the MATCHING_BRACKETS and PATTERN regular expressions. The building blocks below exist
+     * to make the pattern more easily understood. */
+
+    String openingParens = "(\\[\uFF08\uFF3B";
+    String closingParens = ")\\]\uFF09\uFF3D";
+    String nonParens = "[^" + openingParens + closingParens + "]";
+
+    /* Limit on the number of pairs of brackets in a phone number. */
+    String bracketPairLimit = limit(0, 3);
+    /*
+     * An opening bracket at the beginning may not be closed, but subsequent ones should be.  It's
+     * also possible that the leading bracket was dropped, so we shouldn't be surprised if we see a
+     * closing bracket first. We limit the sets of brackets in a phone number to four.
+     */
+    MATCHING_BRACKETS = Pattern.compile(
+        "(?:[" + openingParens + "])?" + "(?:" + nonParens + "+" + "[" + closingParens + "])?" +
+        nonParens + "+" +
+        "(?:[" + openingParens + "]" + nonParens + "+[" + closingParens + "])" + bracketPairLimit +
+        nonParens + "*");
 
     /* Limit on the number of leading (plus) characters. */
     String leadLimit = limit(0, 2);
@@ -97,7 +121,7 @@ final class PhoneNumberMatcher implements Iterator<PhoneNumberMatch> {
     /* A digits block without punctuation. */
     String digitSequence = "\\p{Nd}" + limit(1, digitBlockLimit);
     /* Punctuation that may be at the start of a phone number - brackets and plus signs. */
-    String leadClass = "[(\\[" + PhoneNumberUtil.PLUS_CHARS + "]";
+    String leadClass = "[" + openingParens + PhoneNumberUtil.PLUS_CHARS + "]";
 
     /* Phone number pattern allowing optional punctuation. */
     PATTERN = Pattern.compile(
@@ -321,6 +345,11 @@ final class PhoneNumberMatcher implements Iterator<PhoneNumberMatch> {
    */
   private PhoneNumberMatch parseAndVerify(String candidate, int offset) {
     try {
+      // Check the candidate doesn't contain any formatting which would indicate that it really
+      // isn't a phone number.
+      if (!MATCHING_BRACKETS.matcher(candidate).matches()) {
+        return null;
+      }
       PhoneNumber number = util.parse(candidate, preferredRegion);
       if (leniency.verify(number, util)) {
         return new PhoneNumberMatch(offset, candidate, number);
diff --git a/java/src/com/google/i18n/phonenumbers/PhoneNumberOfflineGeocoder.java b/java/src/com/google/i18n/phonenumbers/PhoneNumberOfflineGeocoder.java
new file mode 100644 (file)
index 0000000..fcd1be2
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.i18n.phonenumbers;
+
+import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
+
+import java.util.Locale;
+
+/**
+ * A offline geocoder which provides geographical information related to a phone number.
+ *
+ * @author Shaopeng Jia
+ */
+public class PhoneNumberOfflineGeocoder {
+  private static PhoneNumberOfflineGeocoder instance = null;
+  private PhoneNumberUtil phoneUtil;
+
+  /**
+   * For testing purposes, we allow the phone number util variable to be injected.
+   */
+  PhoneNumberOfflineGeocoder(PhoneNumberUtil phoneUtil) {
+    this.phoneUtil = phoneUtil;
+  }
+
+  /**
+   * Gets a {@link PhoneNumberOfflineGeocoder} instance to carry out international phone number
+   * geocoding.
+   *
+   * <p> The {@link PhoneNumberOfflineGeocoder} is implemented as a singleton. Therefore, calling
+   * this method multiple times will only result in one instance being created.
+   * 
+   * @return  a {@link PhoneNumberOfflineGeocoder} instance
+   */
+  public static synchronized PhoneNumberOfflineGeocoder getInstance() {
+    if (instance == null) {
+      instance = new PhoneNumberOfflineGeocoder(PhoneNumberUtil.getInstance());
+    }
+    return instance;
+  }
+
+  /**
+   * Returns the customary display name in the given language for the given territory the phone
+   * number is from.
+   */
+  private String getCountryNameForNumber(PhoneNumber number, Locale language) {
+    String regionCode = phoneUtil.getRegionCodeForNumber(number);
+    return (regionCode == null || regionCode.equals("ZZ"))
+        ? "" : new Locale("", regionCode).getDisplayCountry(language);
+  }
+
+  /**
+   * Returns a text description in the given language for the given phone number. The
+   * description might consist of the name of the country where the phone number is from and/or the
+   * name of the geographical area the phone number is from.
+   *
+   * @param number  the phone number for which we want to get a text description
+   * @param language  the language in which the description should be written
+   * @return  a text description in the given language for the given phone number
+   */
+  public String getDescriptionForNumber(PhoneNumber number, Locale language) {
+    // TODO: Implement logic to figure out fine-grained geographical information based
+    // on area code here.
+    return getCountryNameForNumber(number, language);
+  }
+}
index 788703c..3f7d23e 100644 (file)
 
 package com.google.i18n.phonenumbers;
 
+import java.io.Serializable;
+
 public final class Phonenumber {
   private Phonenumber() {}
-  public static class PhoneNumber {
+  public static class PhoneNumber implements Serializable {
+    private static final long serialVersionUID = 1L;
     public enum CountryCodeSource {
       FROM_NUMBER_WITH_PLUS_SIGN,
       FROM_NUMBER_WITH_IDD,
index 03e18fb..fb374ed 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CY and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CY differ
index 0d263a1..43ec39e 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ differ
index 17bf185..2ae03c9 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES differ
index 843c00c..d1ae758 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB differ
index fd17d8d..b84bf20 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GF and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GF differ
index a94a26e..2444a74 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GQ and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GQ differ
index 23edbe7..dce03a8 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JM and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JM differ
index dbc742e..aa771a1 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KP and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KP differ
index bf62c3e..889f649 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MQ and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MQ differ
index c8091d1..cfa92c5 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC differ
index ed88608..ad660fc 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PA and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PA differ
index bbdd91b..cd67c8b 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF differ
index 1b99676..f51d0d1 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PW and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PW differ
index ab59e41..628bd87 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PY and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PY differ
index a640f68..5524740 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SB and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SB differ
index c1dc5a1..a215045 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SR and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SR differ
index 7a24c41..b4c0747 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TN and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TN differ
index 10728f3..256eebf 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TO and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TO differ
index b717cb1..ebf41e1 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UY and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UY differ
index e658ba1..3f93a89 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VI and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VI differ
index 2c79ade..40c22cd 100644 (file)
Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VU and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VU differ
index 704e5d4..0c55964 100644 (file)
@@ -221,6 +221,25 @@ public class PhoneNumberMatcherTest extends TestCase {
     assertEquals(number, matchWithSpaces.rawString());
   }
 
+  public void testNonMatchingBracketsAreInvalid() throws Exception {
+    // The digits up to the ", " form a valid US number, but it shouldn't be matched as one since
+    // there was a non-matching bracket present.
+    assertTrue(hasNoMatches(phoneUtil.findNumbers(
+        "80.585 [79.964, 81.191]", "US")));
+
+    // The trailing "]" is thrown away before parsing, so the resultant number, while a valid US
+    // number, does not have matching brackets.
+    assertTrue(hasNoMatches(phoneUtil.findNumbers(
+        "80.585 [79.964]", "US")));
+
+    assertTrue(hasNoMatches(phoneUtil.findNumbers(
+        "80.585 ((79.964)", "US")));
+
+    // This case has too many sets of brackets to be valid.
+    assertTrue(hasNoMatches(phoneUtil.findNumbers(
+        "(80).(585) (79).(9)64", "US")));
+  }
+
   public void testNoMatchIfRegionIsNull() throws Exception {
     // Fail on non-international prefix if region code is null.
     assertTrue(hasNoMatches(phoneUtil.findNumbers(
diff --git a/java/test/com/google/i18n/phonenumbers/PhoneNumberOfflineGeocoderTest.java b/java/test/com/google/i18n/phonenumbers/PhoneNumberOfflineGeocoderTest.java
new file mode 100644 (file)
index 0000000..facd3c4
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.i18n.phonenumbers;
+
+import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
+import junit.framework.TestCase;
+
+import java.util.Locale;
+
+/**
+ * Unit tests for PhoneNumberOfflineGeocoder.java
+ *
+ * @author Shaopeng Jia
+ */
+public class PhoneNumberOfflineGeocoderTest extends TestCase {
+  private PhoneNumberOfflineGeocoder geocoder;
+  static final String TEST_META_DATA_FILE_PREFIX =
+      "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting";
+
+  // Set up some test numbers to re-use.
+  private static final PhoneNumber US_NUMBER1 =
+      new PhoneNumber().setCountryCode(1).setNationalNumber(6502530000L);
+  private static final PhoneNumber BS_NUMBER1 =
+      new PhoneNumber().setCountryCode(1).setNationalNumber(2423651234L);
+  private static final PhoneNumber AU_NUMBER =
+      new PhoneNumber().setCountryCode(61).setNationalNumber(236618300L);
+  private static final PhoneNumber NUMBER_WITH_INVALID_COUNTRY_CODE =
+      new PhoneNumber().setCountryCode(999).setNationalNumber(2423651234L);
+
+  public PhoneNumberOfflineGeocoderTest() {
+    PhoneNumberUtil.resetInstance();
+    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(
+        TEST_META_DATA_FILE_PREFIX,
+        CountryCodeToRegionCodeMapForTesting.getCountryCodeToRegionCodeMap());
+    geocoder = new PhoneNumberOfflineGeocoder(phoneUtil);
+  }
+
+  public void testGetCompactDescriptionForNumber() {
+    assertEquals("United States",
+        geocoder.getDescriptionForNumber(US_NUMBER1, Locale.ENGLISH));
+    assertEquals("Stati Uniti",
+        geocoder.getDescriptionForNumber(US_NUMBER1, Locale.ITALIAN));
+    assertEquals("Bahamas",
+        geocoder.getDescriptionForNumber(BS_NUMBER1, Locale.ENGLISH));
+    assertEquals("Australia",
+        geocoder.getDescriptionForNumber(AU_NUMBER, Locale.ENGLISH));
+    assertEquals("", geocoder.getDescriptionForNumber(NUMBER_WITH_INVALID_COUNTRY_CODE,
+                                                      Locale.ENGLISH));
+  }
+}
index 58f3107..2b8dd96 100644 (file)
     <territory id="CY" countryCode="357" internationalPrefix="00">
       <availableFormats>
         <!-- Format from http://www.cyprusyellowpages.com/-->
-        <numberFormat pattern="([27-9]\d)(\d{6})">
+        <numberFormat pattern="(\d{2})(\d{6})">
           <format>$1 $2</format>
         </numberFormat>
       </availableFormats>
       <generalDesc>
-        <nationalNumberPattern>[27-9]\d{7}</nationalNumberPattern>
+        <nationalNumberPattern>[257-9]\d{7}</nationalNumberPattern>
         <possibleNumberPattern>\d{8}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
         <exampleNumber>22345678</exampleNumber>
       </fixedLine>
       <mobile>
-        <!-- Universal Access Service numbers (7777 xxxx) are included here, as they are classified
-             as Mobile in the Cyprus national numbering plan. -->
-        <nationalNumberPattern>
-          7777\d{4}|
-          9(?:
-            [69]\d|
-            7[67]
-          )\d{5}
-        </nationalNumberPattern>
+        <!-- Includes paging numbers. -->
+        <nationalNumberPattern>9[5-79]\d{6}</nationalNumberPattern>
         <exampleNumber>96123456</exampleNumber>
       </mobile>
       <tollFree>
-        <nationalNumberPattern>8000\d{4}</nationalNumberPattern>
+        <nationalNumberPattern>800\d{5}</nationalNumberPattern>
         <exampleNumber>80001234</exampleNumber>
       </tollFree>
       <premiumRate>
-        <nationalNumberPattern>9009\d{4}</nationalNumberPattern>
-        <exampleNumber>90091234</exampleNumber>
+        <nationalNumberPattern>90[09]\d{5}</nationalNumberPattern>
+        <exampleNumber>90012345</exampleNumber>
       </premiumRate>
+      <sharedCost>
+        <nationalNumberPattern>80[1-9]\d{5}</nationalNumberPattern>
+        <exampleNumber>80112345</exampleNumber>
+      </sharedCost>
       <personalNumber>
         <nationalNumberPattern>700\d{5}</nationalNumberPattern>
         <exampleNumber>70012345</exampleNumber>
       </personalNumber>
+      <uan>
+        <!-- Using for Corporate Network numbers and Universal Service numbers. -->
+        <nationalNumberPattern>
+          (?:
+            50|
+            77
+          )\d{6}
+        </nationalNumberPattern>
+        <exampleNumber>77123456</exampleNumber>
+      </uan>
     </territory>
 
     <!-- Christmas Islands. -->
       </fixedLine>
       <mobile>
         <nationalNumberPattern>
-          60[1-8]\d{6}|
-          7[2379]\d{7}
+          (?:
+            60[1-8]|
+            7(?:
+              0[25]|
+              [2379]\d
+            )
+          )\d{6}
         </nationalNumberPattern>
         <exampleNumber>601123456</exampleNumber>
       </mobile>
         <exampleNumber>800123456</exampleNumber>
       </tollFree>
       <premiumRate>
-        <nationalNumberPattern>90[0689]\d{6}</nationalNumberPattern>
+        <!-- Includes premium rate dial-up. -->
+        <nationalNumberPattern>
+          9(?:
+            0[05689]|
+            76
+          )\d{6}
+        </nationalNumberPattern>
         <exampleNumber>900123456</exampleNumber>
       </premiumRate>
       <sharedCost>
         <nationalNumberPattern>70[01]\d{6}</nationalNumberPattern>
         <exampleNumber>700123456</exampleNumber>
       </personalNumber>
+      <voip>
+        <nationalNumberPattern>9[17]0\d{6}</nationalNumberPattern>
+        <exampleNumber>910123456</exampleNumber>
+      </voip>
     </territory>
 
     <!-- Germany -->
         <possibleNumberPattern>\d{9}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
-        <nationalNumberPattern>[89][1-8]\d{7}</nationalNumberPattern>
-        <exampleNumber>812345678</exampleNumber>
+        <nationalNumberPattern>
+          (?:
+            8(?:
+              [13]0|
+              [28][0-8]|
+              [47][1-9]|
+              5[01346-9]|
+              6[0457-9]
+            )|
+            9(?:
+              [1238][0-8]|
+              [47][1-9]|
+              [56]\d
+            )
+          )\d{6}
+        </nationalNumberPattern>
+        <exampleNumber>810123456</exampleNumber>
       </fixedLine>
       <mobile>
         <nationalNumberPattern>6\d{8}</nationalNumberPattern>
                nationalPrefix="0" preferredExtnPrefix=" x" nationalPrefixFormattingRule="$NP$FG"
                mainCountryForCode="true">
       <availableFormats>
-        <!-- 2d, 55, 56, 70, 76 with 10 digits. -->
+        <!-- 2d, 55, 56, 70 and 76 pager numbers (excludes 7624) with 10 digits. -->
         <numberFormat pattern="(\d{2})(\d{4})(\d{4})">
           <leadingDigits>
             2|
             5[56]|
-            7[06]
+            7(?:
+              0|
+              6[013-9]
+            )
+          </leadingDigits>
+          <leadingDigits>
+            2|
+            5[56]|
+            7(?:
+              0|
+              6(?:
+                [013-9]|
+                2[0-35-9]
+              )
+            )
           </leadingDigits>
           <format>$1 $2 $3</format>
         </numberFormat>
           <leadingDigits>1</leadingDigits>
           <format>$1 $2</format>
         </numberFormat>
-        <!-- 7ddd (not 70, 76) with 10 digits. -->
+        <!-- 7ddd (not 70, 76) with 10 digits. Note: DOES include 7624 when used for IM. -->
         <numberFormat pattern="(7\d{3})(\d{6})">
-          <leadingDigits>7[1-5789]</leadingDigits>
+          <leadingDigits>
+            7(?:
+              [1-5789]|
+              62
+            )
+          </leadingDigits>
+          <leadingDigits>
+            7(?:
+              [1-5789]|
+              624
+            )
+          </leadingDigits>
           <format>$1 $2</format>
         </numberFormat>
         <!-- 800 1111 : UK ChildLine. -->
     </territory>
 
     <!-- French Guiana (French Dept. of) -->
-    <territory id="GF" countryCode="594" internationalPrefix="00">
+    <!-- http://www.itu.int/oth/T020200004C/en -->
+    <!-- http://www.arcep.fr/index.php?id=2137&bloc=0594&CMD=RESULTS_NUMEROTATION -->
+    <!-- Using a national prefix here as online numbers are formatted with it.  -->
+    <territory id="GF" countryCode="594" internationalPrefix="00"
+               nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG">
+      <availableFormats>
+        <numberFormat pattern="(\d{3})(\d{2})(\d{2})(\d{2})">
+          <format>$1 $2 $3 $4</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[56]\d{8}</nationalNumberPattern>
+        <possibleNumberPattern>\d{9}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <nationalNumberPattern>
+          594(?:
+            10|
+            2[012457-9]|
+            3[0-57-9]|
+            4[3-9]|
+            5[7-9]|
+            6[0-3]|
+            9[014]
+          )\d{4}
+        </nationalNumberPattern>
+        <exampleNumber>594101234</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>
+          694(?:
+            [04][0-7]|
+            1[0-5]|
+            2[0-46-9]|
+            38|
+            9\d
+          )\d{4}
+        </nationalNumberPattern>
+        <exampleNumber>694201234</exampleNumber>
+      </mobile>
+      <!-- The 876 prefix is mentioned in the plan, but the plan is from 2006 and in France VOIP
+           numbers were changed from 087 to the 09 prefix in 2009. It is likely this occurred here
+           too. -->
     </territory>
 
     <!-- Guernsey -->
     <!-- http://www.itu.int/oth/T0202000041/en -->
     <territory id="GQ" countryCode="240" internationalPrefix="00">
       <availableFormats>
-        <numberFormat pattern="(\d{2})(\d{3})(\d{4})">
+        <numberFormat pattern="(\d{3})(\d{3})(\d{3})">
           <leadingDigits>[235]</leadingDigits>
           <format>$1 $2 $3</format>
         </numberFormat>
       </availableFormats>
       <generalDesc>
         <nationalNumberPattern>[23589]\d{8}</nationalNumberPattern>
-        <!-- The 6 here refers to the old number pattern - numbers written down may still be this
-             length although they can no longer be dialled. -->
-        <possibleNumberPattern>\d{6,9}</possibleNumberPattern>
+        <possibleNumberPattern>\d{9}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
         <nationalNumberPattern>
       <fixedLine>
         <nationalNumberPattern>
           876(?:
-            (?:
-              5[0-26]|
-              6\d
-            )\d{5}|
-            (?:
-              7(?:
-                0[2-689]|
-                [1-6]\d|
-                8[056]|
-                9[45]
-              )|
-              9(?:
-                0[1-8]|
-                1[02378]|
-                [2-8]\d|
-                9[2-468]
-              )
-            )\d{4}
-          )
+            5(?:
+              0[12]|
+              1[0-468]|
+              2[35]|
+              63
+            )|
+            6(?:
+              0[1-3579]|
+              1[027]|
+              2[3-5]|
+              34|
+              [45]0|
+              63|
+              7[05]|
+              8[04]|
+              9[4-9]
+            )
+            7(?:
+              0[2-689]|
+              [1-6]\d|
+              8[056]|
+              9[45]
+            )|
+            9(?:
+              0[1-8]|
+              1[02378]|
+              [2-8]\d|
+              9[2-468]
+            )
+          )\d{4}
         </nationalNumberPattern>
         <exampleNumber>8765123456</exampleNumber>
       </fixedLine>
       <mobile>
-        <!-- Adding 27, 28 and 31 as extra prefixes, as they have been found to be valid by sending
-             SMSs and looking at online number lookup sites. -->
+        <!-- Adding 27, 28, 31, 527 and 566 as extra prefixes, as they have been found to be valid
+             by sending SMSs and looking at online number lookup sites. -->
         <nationalNumberPattern>
           876(?:
             (?:
               2[178]|
               [348]\d|
-              5[78]
             )\d|
+            5(?:
+              27|
+              66|
+              [78]\d
+            )|
             7(?:
               0[07]|
               7\d|
     </territory>
 
     <!--  Korea, Dem. People's Rep. of -->
-    <territory id="KP" countryCode="850" internationalPrefix="00"
-               nationalPrefix="0">
+    <!-- http://en.wikipedia.org/wiki/%2B850 -->
+    <territory id="KP" countryCode="850" internationalPrefix="00|99"
+               nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG">
+      <availableFormats>
+        <numberFormat pattern="(\d{3})(\d{3})(\d{4})">
+          <leadingDigits>1</leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+        <numberFormat pattern="(\d)(\d{3})(\d{4})">
+          <leadingDigits>2</leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{2})(\d{3})(\d{3})">
+          <leadingDigits>8</leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>
+          1\d{9}|
+          [28]\d{7}
+        </nationalNumberPattern>
+        <possibleNumberPattern>
+          \d{6,8}|
+          \d{10}
+        </possibleNumberPattern>
+      </generalDesc>
+      <noInternationalDialling>
+        <!-- For numbers starting with 2, only the 2381 range can be dialed internationally. -->
+        <nationalNumberPattern>
+          2(?:
+            [0-24-9]\d{2}|
+            3(?:
+              [0-79]\d|
+              8[02-9]
+            )
+          )\d{4}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{8}</possibleNumberPattern>
+        <exampleNumber>23821234</exampleNumber>
+      </noInternationalDialling>
+      <fixedLine>
+        <!-- Covers only numbers from Pyongyang and Rason Economic Special Zone. According to
+             wikipedia, other ranges of phone numbers are top secret, unpublished, and not dialable
+             from overseas. -->
+        <nationalNumberPattern>
+          2\d{7}|
+          85\d{6}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{6,8}</possibleNumberPattern>
+        <exampleNumber>21234567</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>19[123]\d{7}</nationalNumberPattern>
+        <possibleNumberPattern>\d{10}</possibleNumberPattern>
+        <exampleNumber>1921234567</exampleNumber>
+      </mobile>
     </territory>
 
     <!-- Korea (Rep. of) -->
 
     <!-- Martinique (French Dept. of) -->
     <!-- http://www.itu.int/oth/T0202000086/en -->
+    <!-- http://www.arcep.fr/index.php?id=2137&bloc=0596&CMD=RESULTS_NUMEROTATION -->
     <territory id="MQ" countryCode="596" internationalPrefix="00"
                nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG">
       <availableFormats>
       <fixedLine>
         <nationalNumberPattern>
           596(?:
-            3[0789]|
-            4[28]|
+            0[2-5]|
+            [12]0|
+            3[05-9]|
+            4[024-8]|
             [5-7]\d|
-            9[67]
+            89|
+            9[4-8]
           )\d{4}
         </nationalNumberPattern>
         <exampleNumber>596301234</exampleNumber>
       <mobile>
         <nationalNumberPattern>
           696(?:
-            [2-49]\d|
-            7[0-4]|
-            8[0-6]
+            [0-479]\d|
+            5[01]|
+            8[0-689]
           )\d{4}
         </nationalNumberPattern>
         <exampleNumber>696201234</exampleNumber>
     </territory>
 
     <!-- New Caledonia (Territoire français d'outre-mer) -->
-    <territory id="NC" countryCode="687" internationalPrefix="00"
-               nationalPrefix="0">
+    <!-- http://www.itu.int/oth/T0202000098/en -->
+    <territory id="NC" countryCode="687" internationalPrefix="00">
+      <availableFormats>
+        <!-- From www.1012.nc, the local yellow pages. -->
+        <numberFormat pattern="(\d{2})(\d{2})(\d{2})">
+          <format>$1.$2.$3</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[2-47-9]\d{5}</nationalNumberPattern>
+        <possibleNumberPattern>\d{6}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <!-- Including the 88 prefix for public payphones. -->
+        <nationalNumberPattern>
+          (?:
+            2[03-9]|
+            35|
+            4[1-7]|
+            88
+          )\d{4}
+        </nationalNumberPattern>
+        <exampleNumber>201234</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>
+          (?:
+            7[4-9]|
+            8[0-79]|
+            9\d
+          )\d{4}
+        </nationalNumberPattern>
+        <exampleNumber>751234</exampleNumber>
+      </mobile>
+      <shortCode>
+        <!-- OPT: Office des Postes et Télécommunications de Nouvelle Calédonie -->
+        <nationalNumberPattern>
+          1(?:
+            0(?:
+              0[06]|
+              1[02-46]|
+              20|
+              3[0125]|
+              42|
+              5[058]|
+              77
+            )|
+            [5-8]
+          )
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{2,4}</possibleNumberPattern>
+        <exampleNumber>15</exampleNumber>
+      </shortCode>
     </territory>
 
     <!-- Niger -->
     </territory>
 
     <!-- Panama -->
+    <!-- http://www.asep.gob.pa/telecom/pnn/default.asp - last read May 19th 2011. -->
+    <!-- http://en.wikipedia.org/wiki/%2B507 - although it omits the fact that mobile phones are 8
+         digits long. -->
     <territory id="PA" countryCode="507" internationalPrefix="00"
                nationalPrefix="0">
-    </territory>
-
-    <!-- Peru -->
-    <!-- http://www.itu.int/oth/T02020000A6/en -->
-    <!-- http://en.wikipedia.org/wiki/+51 -->
-    <territory id="PE" countryCode="51" internationalPrefix="19(?:1[124]|77|90)00"
-               nationalPrefix="0" nationalPrefixFormattingRule="($FG)"
-               preferredExtnPrefix=" Anexo ">
       <availableFormats>
-        <numberFormat pattern="(1)(\d{7})">
-          <leadingDigits>1</leadingDigits>
-          <format>$1 $2</format>
-        </numberFormat>
-        <numberFormat pattern="([4-8]\d)(\d{6})">
-          <leadingDigits>[4-8]</leadingDigits>
-          <format>$1 $2</format>
+        <numberFormat pattern="(\d{3})(\d{4})">
+          <leadingDigits>[1-57-9]</leadingDigits>
+          <format>$1-$2</format>
         </numberFormat>
-        <!-- Formatting from common usage found on the internet, supported by ITU doc. -->
-        <numberFormat pattern="(9\d{2})(\d{3})(\d{3})"
-                      nationalPrefixFormattingRule="$FG">
-          <leadingDigits>9</leadingDigits>
-          <format>$1 $2 $3</format>
+        <numberFormat pattern="(\d{4})(\d{4})">
+          <leadingDigits>6</leadingDigits>
+          <format>$1-$2</format>
         </numberFormat>
       </availableFormats>
       <generalDesc>
-        <nationalNumberPattern>[14-9]\d{7,8}</nationalNumberPattern>
-        <possibleNumberPattern>\d{6,9}</possibleNumberPattern>
+        <nationalNumberPattern>[1-9]\d{6,7}</nationalNumberPattern>
+        <possibleNumberPattern>\d{7,8}</possibleNumberPattern>
       </generalDesc>
+      <!-- Note that numbers starting with 101, 106, 131, 151, 156 and 168 have not been assigned to
+           any rule below since we are not sure what the "servicios 102/103" refer to here. -->
       <fixedLine>
+        <!-- Note that "servicios 101/104" in the plan refer to "Local Basic Communications Service"
+             and "Public and Semipublic Terminal Service", represented here as fixed-line. -->
+        <!-- The range 194-XXXX has been added since a number was found online with this prefix and
+             proved to be diallable. -->
         <nationalNumberPattern>
           (?:
-            1\d|
-            4[1-4]|
-            5[1-46]|
-            6[1-7]|
-            7[2-46]|
-            8[2-4]
-          )\d{6}
-        </nationalNumberPattern>
-        <possibleNumberPattern>\d{6,8}</possibleNumberPattern>
-        <exampleNumber>11234567</exampleNumber>
-      </fixedLine>
-      <mobile>
-        <nationalNumberPattern>9\d{8}</nationalNumberPattern>
-        <possibleNumberPattern>\d{9}</possibleNumberPattern>
-        <exampleNumber>912345678</exampleNumber>
-      </mobile>
-    </territory>
-
-    <!-- French Polynesia (Tahiti) (Territoire français d'outre-mer) -->
-    <territory id="PF" countryCode="689" internationalPrefix="00">
-    </territory>
-
-    <!-- Papua New Guinea -->
+            1(?:
+              0[02-579]|
+              19|
+              23|
+              3[03]|
+              4[479]|
+              5[57]|
+              65|
+              7[016-8]|
+              8[58]|
+              9[1-49]
+            )|
+            2(?:
+              [0235679]\d|
+              1[0-7]|
+              4[04-9]|
+              8[028]
+            )|
+            3(?:
+              0[0-7]|
+              1[14-7]|
+              2[0-3]|
+              3[03]|
+              4[0457]|
+              5[56]|
+              6[068]|
+              7[078]|
+              80|
+              9[0-79]
+            )|
+            4(?:
+              3[013-59]|
+              4\d|
+              7[0-689]
+            )|
+            5(?:
+              [01]\d|
+              2[0-7]|
+              [56]0|
+              79
+            )|
+            7(?:
+              09|
+              2[0-267]|
+              [34]0|
+              5[6-9]|
+              7[0-24-7]|
+              8[89]|
+              99
+            )|
+            8(?:
+              [34]\d|
+              5[0-5]|
+              8[02]
+            )|
+            9(?:
+              0[78]|
+              1[0178]|
+              2[0378]|
+              3[379]|
+              40|
+              5[0489]|
+              6[06-9]|
+              7[046-9]|
+              8[36-8]|
+              9[1-9]
+            )
+          )\d{4}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>2001234</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <!-- Note that "servicios 106/107" in the plan refer to mobile services. We also include
+             service "210", "Servicio de Busca Personas". -->
+        <nationalNumberPattern>
+          (?:
+            161|
+            21[89]|
+            8(?:
+              1[01]|
+              7[23]
+            )
+          )\d{4}|
+          6(?:
+            [04-8]\d|
+            1[0-5]|
+            2[0-4]|
+            3[7-9]|
+            9[0-8]
+          )\d{5}
+        </nationalNumberPattern>
+        <exampleNumber>60012345</exampleNumber>
+      </mobile>
+      <tollFree>
+        <nationalNumberPattern>80[09]\d{4}</nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>8001234</exampleNumber>
+      </tollFree>
+      <premiumRate>
+        <!-- Value-added services are represented as "400" in the plan. -->
+        <nationalNumberPattern>
+          (?:
+            779|
+            8(?:
+              2[235]|
+              60|
+              7[578]|
+              86|
+              95
+            )|
+            9(?:
+              0[0-2]|
+              81
+            )
+          )\d{4}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>8601234</exampleNumber>
+      </premiumRate>
+      <shortCode>
+        <nationalNumberPattern>
+          10[2-4]|
+          911
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{3}</possibleNumberPattern>
+        <exampleNumber>102</exampleNumber>
+      </shortCode>
+    </territory>
+
+    <!-- Peru -->
+    <!-- http://www.itu.int/oth/T02020000A6/en -->
+    <!-- http://en.wikipedia.org/wiki/+51 -->
+    <territory id="PE" countryCode="51" internationalPrefix="19(?:1[124]|77|90)00"
+               nationalPrefix="0" nationalPrefixFormattingRule="($FG)"
+               preferredExtnPrefix=" Anexo ">
+      <availableFormats>
+        <numberFormat pattern="(1)(\d{7})">
+          <leadingDigits>1</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <numberFormat pattern="([4-8]\d)(\d{6})">
+          <leadingDigits>[4-8]</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <!-- Formatting from common usage found on the internet, supported by ITU doc. -->
+        <numberFormat pattern="(9\d{2})(\d{3})(\d{3})"
+                      nationalPrefixFormattingRule="$FG">
+          <leadingDigits>9</leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[14-9]\d{7,8}</nationalNumberPattern>
+        <possibleNumberPattern>\d{6,9}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <nationalNumberPattern>
+          (?:
+            1\d|
+            4[1-4]|
+            5[1-46]|
+            6[1-7]|
+            7[2-46]|
+            8[2-4]
+          )\d{6}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{6,8}</possibleNumberPattern>
+        <exampleNumber>11234567</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>9\d{8}</nationalNumberPattern>
+        <possibleNumberPattern>\d{9}</possibleNumberPattern>
+        <exampleNumber>912345678</exampleNumber>
+      </mobile>
+    </territory>
+
+    <!-- French Polynesia (Tahiti) (Territoire français d'outre-mer) -->
+    <!-- http://www.itu.int/oth/T020200004D/en -->
+    <territory id="PF" countryCode="689" internationalPrefix="00">
+      <availableFormats>
+        <numberFormat pattern="(\d{2})(\d{2})(\d{2})">
+          <format>$1 $2 $3</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[2-9]\d{5}</nationalNumberPattern>
+        <possibleNumberPattern>\d{6}</possibleNumberPattern>
+      </generalDesc>
+      <noInternationalDialling>
+        <nationalNumberPattern>
+          (?:
+            36|
+            44
+          )\d{4}
+        </nationalNumberPattern>
+        <exampleNumber>441234</exampleNumber>
+      </noInternationalDialling>
+      <fixedLine>
+        <!-- Includes "voice-server" prefixes and pay-phone. The 41 range has been made more
+             specific to exclude Mobile MSRN. -->
+        <nationalNumberPattern>
+          (?:
+            36\d|
+            4(?:
+              [02-9]\d|
+              1[02-9]
+            )|
+            [5689]\d{2}
+          )\d{3}
+        </nationalNumberPattern>
+        <exampleNumber>401234</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>
+          (?:
+            [27]\d{3}|
+            3[0-49]\d{2}|
+            411[3-6]
+          )\d{2}
+        </nationalNumberPattern>
+        <exampleNumber>212345</exampleNumber>
+      </mobile>
+    </territory>
+
+    <!-- Papua New Guinea -->
     <!-- http://www.itu.int/oth/T02020000A4/en -->
     <!-- http://en.wikipedia.org/wiki/%2B675 -->
     <territory id="PG" countryCode="675" internationalPrefix="00">
     </territory>
 
     <!-- Palau -->
-    <territory id="PW" countryCode="680" internationalPrefix="011">
+    <!-- http://www.itu.int/oth/T02020000A2/en -->
+    <territory id="PW" countryCode="680" internationalPrefix="01[12]">
+      <availableFormats>
+        <numberFormat pattern="(\d{3})(\d{4})">
+          <format>$1 $2</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[2-8]\d{6}</nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <nationalNumberPattern>
+          2552255|
+          (?:
+            277|
+            345|
+            488|
+            5(?:
+              35|
+              44|
+              87
+            )|
+            6(?:
+              22|
+              54|
+              79
+            )|
+            7(?:
+              33|
+              47
+            )|
+            8(?:
+              24|
+              55|
+              76
+            )
+          )\d{4}
+        </nationalNumberPattern>
+        <exampleNumber>2771234</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>
+          (?:
+            6[234689]0|
+            77[45789]
+          )\d{4}
+        </nationalNumberPattern>
+        <exampleNumber>6201234</exampleNumber>
+      </mobile>
+      <!-- Emergency call service. -->
+      <shortCode>
+        <nationalNumberPattern>911</nationalNumberPattern>
+        <possibleNumberPattern>\d{3}</possibleNumberPattern>
+        <exampleNumber>911</exampleNumber>
+      </shortCode>
     </territory>
 
     <!-- Paraguay -->
-    <territory id="PY" countryCode="595" internationalPrefix="002"
-               nationalPrefix="0">
+    <!-- http://en.wikipedia.org/wiki/Telephone_numbers_in_Paraguay -->
+    <!-- http://www.itu.int/oth/T02020000A5/en -->
+    <!-- http://www.copaco.com.py/seccion/codigos -->
+    <territory id="PY" countryCode="595" internationalPrefix="00" nationalPrefix="0">
+      <availableFormats>
+        <!-- CONATEL plan. -->
+        <numberFormat pattern="(\d{2})(\d{5,7})" nationalPrefixFormattingRule="($FG)">
+          <leadingDigits>
+            (?:
+              [26]1|
+              3[289]|
+              4[124678]|
+              7[123]|
+              8[1236]
+            )
+          </leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{3})(\d{3,6})" nationalPrefixFormattingRule="$NP$FG">
+          <leadingDigits>[2-9]0</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{3})(\d{6})" nationalPrefixFormattingRule="$NP$FG">
+          <leadingDigits>9[1-9]</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <!-- Format seen in examples found online. -->
+        <numberFormat pattern="(\d{2})(\d{3})(\d{4})">
+          <leadingDigits>8700</leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+        <!-- "Fall-back" rule for the rest of the fixed-line numbers that have 3-digit area codes.
+         -->
+        <numberFormat pattern="(\d{3})(\d{4,6})" nationalPrefixFormattingRule="($FG)">
+          <leadingDigits>[2-8][1-9]</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>
+          5[0-5]\d{4,7}|
+          [2-46-9]\d{5,8}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{5,9}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <nationalNumberPattern>
+          (?:
+            [26]1|
+            3[289]|
+            4[124678]|
+            7[123]|
+            8[1236]
+          )\d{5,7}|
+          (?:
+            2(?:
+              2[4568]|
+              7[15]|
+              9[1-5]
+            )|
+            3(?:
+              18|
+              3[167]|
+              4[2357]|
+              51
+            )|
+            4(?:
+              18|
+              2[45]|
+              3[12]|
+              5[13]|
+              64|
+              71|
+              9[1-47]
+            )|
+            5(?:
+              [1-4]\d|
+              5[0234]
+            )|
+            6(?:
+              3[1-3]|
+              44|
+              7[1-4678]
+            )|
+            7(?:
+              17|
+              4[0-4]|
+              6[1-578]|
+              75|
+              8[0-8]
+            )|
+            858
+          )\d{5,6}
+        </nationalNumberPattern>
+        <exampleNumber>212345678</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>
+          9(?:
+            61|
+            7[12356]|
+            8[1-5]|
+            9[1235]
+          )\d{6}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{9}</possibleNumberPattern>
+        <exampleNumber>961456789</exampleNumber>
+      </mobile>
+      <voip>
+        <nationalNumberPattern>8700[0-4]\d{4}</nationalNumberPattern>
+        <possibleNumberPattern>\d{9}</possibleNumberPattern>
+        <exampleNumber>870012345</exampleNumber>
+      </voip>
+      <uan>
+        <nationalNumberPattern>[2-9]0\d{4,7}</nationalNumberPattern>
+        <possibleNumber>\d{6,9}</possibleNumber>
+        <exampleNumber>201234567</exampleNumber>
+      </uan>
+      <shortCode>
+        <nationalNumberPattern>1[1-4]\d</nationalNumberPattern>
+        <possibleNumberPattern>\d{3}</possibleNumberPattern>
+        <exampleNumber>123</exampleNumber>
+      </shortCode>
     </territory>
 
     <!-- Qatar -->
     </territory>
 
     <!-- Solomon Islands -->
-    <territory id="SB" countryCode="677" internationalPrefix="00">
+    <!-- http://www.itu.int/oth/T02020000BF/en -->
+    <territory id="SB" countryCode="677" internationalPrefix="0[01]">
+      <!-- No formatting rules. A single group is used to format the numbers. -->
+      <generalDesc>
+        <nationalNumberPattern>[1-8]\d{4,6}</nationalNumberPattern>
+        <possibleNumberPattern>\d{5,7}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <!-- Although not mentioned in the 2011 update, it seems likely that the range 67300-67699
+             is still used for Sasamunga, Shortland, Poitete and Ringgi as per the 2010 plan. -->
+        <nationalNumberPattern>
+          (?:
+            1[4-79]|
+            [23]\d|
+            4[01]|
+            5[03]|
+            6[0-37]
+          )\d{3}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{5}</possibleNumberPattern>
+        <exampleNumber>40123</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>
+          7(?:
+            4\d|
+            5[025-7]
+          )\d{4}|
+          8[48]\d{5}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>7421234</exampleNumber>
+      </mobile>
+      <tollFree>
+        <nationalNumberPattern>1[38]\d{3}</nationalNumberPattern>
+        <possibleNumberPattern>\d{5}</possibleNumberPattern>
+        <exampleNumber>18123</exampleNumber>
+      </tollFree>
+      <voip>
+        <nationalNumberPattern>5[12]\d{3}</nationalNumberPattern>
+        <possibleNumberPattern>\d{5}</possibleNumberPattern>
+        <exampleNumber>51123</exampleNumber>
+      </voip>
+      <shortCode>
+        <nationalNumberPattern>
+          1(?:
+            0[02-79]|
+            1[12]|
+            2[0-26]|
+            4[189]|
+            68
+          )|
+          9(?:
+            [01]1|
+            22|
+            33|
+            55|
+            77|
+            88|
+            99
+          )
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{3}</possibleNumberPattern>
+        <exampleNumber>100</exampleNumber>
+      </shortCode>
     </territory>
 
     <!-- Seychelles -->
     </territory>
 
     <!-- Suriname -->
+    <!-- http://www.itu.int/oth/T02020000C5/en -->
     <territory id="SR" countryCode="597" internationalPrefix="00">
+      <availableFormats>
+        <!-- Following conventions used in the Suriname Yellow Pages. -->
+        <numberFormat pattern="(\d{3})(\d{3})">
+          <leadingDigits>
+            [2-4]|
+            5[2-58]
+          </leadingDigits>
+          <format>$1-$2</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{2})(\d{2})(\d{2})">
+          <leadingDigits>56</leadingDigits>
+          <format>$1-$2-$3</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{3})(\d{4})">
+          <leadingDigits>[6-8]</leadingDigits>
+          <format>$1-$2</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[2-8]\d{5,6}</nationalNumberPattern>
+        <possibleNumberPattern>\d{6,7}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <!-- Includes non-geographic WLL-CDMA Fixed Lines. -->
+        <nationalNumberPattern>
+          (?:
+            2[1-3]|
+            3[0-7]|
+            4\d|
+            5[2-58]|
+            68\d
+          )\d{4}
+        </nationalNumberPattern>
+        <exampleNumber>211234</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <!-- Adding 74 from numbers found online. -->
+        <nationalNumberPattern>
+          (?:
+            7[1245]|
+            8[1-9]
+          )\d{5}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>7412345</exampleNumber>
+      </mobile>
+      <voip>
+        <nationalNumberPattern>56\d{4}</nationalNumberPattern>
+        <possibleNumberPattern>\d{6}</possibleNumberPattern>
+        <exampleNumber>561234</exampleNumber>
+      </voip>
+      <shortCode>
+        <nationalNumberPattern>1\d{2,3}</nationalNumberPattern>
+        <possibleNumberPattern>\d{3,4}</possibleNumberPattern>
+        <exampleNumber>1234</exampleNumber>
+      </shortCode>
     </territory>
 
     <!-- Sao Tome and Principe -->
       <mobile>
         <nationalNumberPattern>
           (?:
-            2[0-7]|
-            40|
-            9\d
+            [29]\d|
+            4[01]
           )\d{6}
         </nationalNumberPattern>
         <exampleNumber>20123456</exampleNumber>
     </territory>
 
     <!-- Tonga -->
-    <territory id="TO" countryCode="676" internationalPrefix="00">
+    <!-- http://www.itu.int/oth/T02020000D3/en -->
+    <!-- http://www.wtng.info/wtng-676-to.html -->
+    <territory id="TO" countryCode="676" internationalPrefix="00" leadingZeroPossible="true">
+      <availableFormats>
+        <numberFormat pattern="(\d{2})(\d{3})">
+          <leadingDigits>
+            [1-6]|
+            7[0-4]|
+            8[05]
+          </leadingDigits>
+          <format>$1-$2</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{3})(\d{4})">
+          <leadingDigits>
+            7[5-9]|
+            8[7-9]
+          </leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{4})(\d{3})">
+          <leadingDigits>0</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[02-8]\d{4,6}</nationalNumberPattern>
+        <possibleNumberPattern>\d{5,7}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <nationalNumberPattern>
+          (?:
+            2\d|
+            3[1-8]|
+            4[1-4]|
+            [56]0|
+            7[0149]|
+            8[05]
+          )\d{3}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{5}</possibleNumberPattern>
+        <exampleNumber>20123</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <!-- TCC mobile numbers were given a prefix of "77" in 2009, although this is not mentioned
+             in their ITU document. Numbers with a prefix of "75" have also been found. -->
+        <nationalNumberPattern>
+          (?:
+            7[578]|
+            8[7-9]
+          )\d{5}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>7715123</exampleNumber>
+      </mobile>
+      <tollFree>
+        <nationalNumberPattern>0800\d{3}</nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>0800222</exampleNumber>
+      </tollFree>
     </territory>
 
     <!-- Turkey -->
     </territory>
 
     <!-- Uruguay -->
-    <territory id="UY" countryCode="598" internationalPrefix="00"
-               nationalPrefix="0">
+    <!-- http://www.itu.int/oth/T02020000E0/en -->
+    <!-- http://www.ursec.gub.uy -->
+    <!-- http://en.wikipedia.org/wiki/Telephone_numbers_in_Uruguay -->
+    <!-- International long-distance providers can be dialled by dialling 01 followed by a carrier
+         code JK, where J = [3-9] and K is any digit. -->
+    <territory id="UY" countryCode="598" internationalPrefix="0(?:1[3-9]\d|0)"
+               preferredInternationalPrefix="00" nationalPrefix="0" preferredExtnPrefix=" int. ">
+      <availableFormats>
+        <!-- Following paginasamarillas.com.uy formatting. -->
+        <numberFormat pattern="(\d{4})(\d{4})">
+          <leadingDigits>[24]</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <!-- Including the national prefix here since URSEC does when formatting these. -->
+        <numberFormat pattern="(\d{2})(\d{3})(\d{3})" nationalPrefixFormattingRule="$NP$FG">
+          <leadingDigits>9[1-9]</leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{3})(\d{4})" nationalPrefixFormattingRule="$NP$FG">
+          <leadingDigits>[89]0</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[2489]\d{6,7}</nationalNumberPattern>
+        <possibleNumberPattern>\d{7,8}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <nationalNumberPattern>
+          2\d{7}|
+          4[2-7]\d{6}
+        </nationalNumberPattern>
+        <exampleNumber>21231234</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>9[13-9]\d{6}</nationalNumberPattern>
+        <possibleNumberPattern>\d{8}</possibleNumberPattern>
+        <exampleNumber>94231234</exampleNumber>
+      </mobile>
+      <tollFree>
+        <nationalNumberPattern>80[05]\d{4}</nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>8001234</exampleNumber>
+      </tollFree>
+      <premiumRate>
+        <nationalNumberPattern>90[0-8]\d{4}</nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>9001234</exampleNumber>
+      </premiumRate>
+      <shortCode>
+        <nationalNumberPattern>
+          1(?:
+            0[4-9]|
+            1[2368]|
+            2[0-3568]
+          )|
+          911
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{3}</possibleNumberPattern>
+        <exampleNumber>104</exampleNumber>
+      </shortCode>
     </territory>
 
     <!-- Uzbekistan -->
           340(?:
             2(?:
               01|
-              2[07]|
+              2[067]|
               36|
               44|
               77
           340(?:
             2(?:
               01|
-              2[07]|
+              2[067]|
               36|
               44|
               77
     </territory>
 
     <!-- Vanuatu -->
+    <!-- http://www.itu.int/oth/T02020000E2/en -->
     <territory id="VU" countryCode="678" internationalPrefix="00">
+      <!-- Should be formatted in one block, apart from the mobile numbers. -->
+      <availableFormats>
+        <numberFormat pattern="(\d{3})(\d{4})">
+          <leadingDigits>[57]</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>[2-578]\d{4,6}</nationalNumberPattern>
+        <possibleNumberPattern>\d{5,7}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <nationalNumberPattern>
+          (?:
+            2[2-9]\d|
+            3(?:
+              [67]\d|
+              8[0-8]
+            )|
+            48[4-9]|
+            88\d
+          )\d{2}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{5}</possibleNumberPattern>
+        <exampleNumber>22123</exampleNumber>
+      </fixedLine>
+      <mobile>
+        <nationalNumberPattern>
+          (?:
+            5(?:
+              7[2-5]|
+              [3-69]\d
+            )|
+            7[013-7]\d
+          )\d{4}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{7}</possibleNumberPattern>
+        <exampleNumber>5912345</exampleNumber>
+      </mobile>
+      <!-- Using this for non-geographical numbers. -->
+      <uan>
+        <nationalNumberPattern>30\d{3}</nationalNumberPattern>
+        <possibleNumberPattern>\d{5}</possibleNumberPattern>
+        <exampleNumber>30123</exampleNumber>
+      </uan>
     </territory>
 
     <!-- Wallis and Futuna (Territoire français d'outre-mer) -->