Class Pin1Yin1


  • public class Pin1Yin1
    extends java.lang.Object
    Pin1Yin1 (罗马拼音 - Online Internet Translation Service).

    This class is named after the server Pin1Yin1.com - and it queries that address for Chinese Translations.

    IMPORTANT NOTE: This class uses "itself" as a result-return object. Specifically, when a result from the server is returned, the answers are encapsulated in an instance of a class Pin1Yin1 instantiation.
    
    Pin1Yin1 response = Pin1Yin1.getResponse("中国政府网_中央人民政府门户网站", false);
    System.out.println("Here are the respose vocabulary words:\n" + response.toString());
    


    • Field Summary

      Fields 
      Modifier and Type Field Description
      String[] engl
      These are the English Translations of each word; some Chinese Words are translated into multiple english words.
      String JSON
      Unless specifically requested, this variable is null.
      static String PIN1_YIN1_URL
      PinYin URL
      String[] pron
      The Pronunciation of each element in the "Word Boundaries" version.
      String[] pronSINGLE_WORD
      This is a 1-to-1 mapping between the chinese characters in the query, and their mandarin pronunciation.
      String[] simp
      The Simplified Conversion - in this version, characters are grouped by "Word Boundaries"
      String simpSENTENCE
      This is the original query-string - in Simplified Chinese.
      String[] trad
      The traditional conversion - In this version, also, characters are grouped by "Word Boundaries"
      String tradSENTENCE
      This is the original query-string in Traditional Chinese
      int[] wordGroups
      This is just an array of integers that was actually returned from the server.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Pin1Yin1 getResponse​(String chineseText, boolean saveJSON)
      This translates a sentence from Mandarin into English.
      static void main​(String[] argv)
      Run the translation from the command-line.
      String toString()
      This converts 'this' result to a String
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • PIN1_YIN1_URL

        🡇    
        public static final java.lang.String PIN1_YIN1_URL
        PinYin URL
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
        public static final String PIN1_YIN1_URL = "https://pin1yin1.com/pinyin/convert/?c=";
        
      • simpSENTENCE

        🡅  🡇    
        public final java.lang.String simpSENTENCE
        This is the original query-string - in Simplified Chinese.

        NOTE: How accurate the traditional/simplified conversion is is not known, and probably not exact.
        Code:
        Exact Field Declaration Expression:
        public final String simpSENTENCE;
        
      • tradSENTENCE

        🡅  🡇    
        public final java.lang.String tradSENTENCE
        This is the original query-string in Traditional Chinese
        Code:
        Exact Field Declaration Expression:
        public final String tradSENTENCE;
        
      • simp

        🡅  🡇    
        public final java.lang.String[] simp
        The Simplified Conversion - in this version, characters are grouped by "Word Boundaries"
        Code:
        Exact Field Declaration Expression:
        public final String[] simp;
        
      • pron

        🡅  🡇    
        public final java.lang.String[] pron
        The Pronunciation of each element in the "Word Boundaries" version.
        Code:
        Exact Field Declaration Expression:
        public final String[] pron;
        
      • trad

        🡅  🡇    
        public final java.lang.String[] trad
        The traditional conversion - In this version, also, characters are grouped by "Word Boundaries"
        Code:
        Exact Field Declaration Expression:
        public final String[] trad;
        
      • engl

        🡅  🡇    
        public final java.lang.String[] engl
        These are the English Translations of each word; some Chinese Words are translated into multiple english words.
        Code:
        Exact Field Declaration Expression:
        public final String[] engl;
        
      • pronSINGLE_WORD

        🡅  🡇    
        public final java.lang.String[] pronSINGLE_WORD
        This is a 1-to-1 mapping between the chinese characters in the query, and their mandarin pronunciation. Specifically, each element in this array contains a single ('one') syllable of pinyin romanization - a.k.a. one chinese character's pronunciation. The array final String[] pron contains as many syllables as the "Grouped By" Chinese Word does.
        Code:
        Exact Field Declaration Expression:
        public final String[] pronSINGLE_WORD;
        
      • wordGroups

        🡅  🡇    
        public final int[] wordGroups
        This is just an array of integers that was actually returned from the server. It identifies the number of Chinese Characters that are in each Chinese Word.
        Code:
        Exact Field Declaration Expression:
        public final int[] wordGroups;
        
      • JSON

        🡅  🡇    
        public final java.lang.String JSON
        Unless specifically requested, this variable is null. It is the JSON as a String returned from the server
        Code:
        Exact Field Declaration Expression:
        public final String JSON;
        
    • Method Detail

      • main

        🡅  🡇    
        public static void main​(java.lang.String[] argv)
                         throws java.io.IOException
        Run the translation from the command-line.
        Throws:
        java.io.IOException
        Code:
        Exact Method Body:
         System.out.println(getResponse((argv.length == 1) ? argv[0] : sampleText, true).toString());
        
      • getResponse

        🡅  🡇    
        public static Pin1Yin1 getResponse​(java.lang.String chineseText,
                                           boolean saveJSON)
                                    throws java.io.IOException
        This translates a sentence from Mandarin into English. The response object is an instance of this exact class.
        Parameters:
        chineseText - This is a text String input, and is expected to be in Mandarin. The server does not seem to mind whether the input is in "Simplified" or "Traditional."
        saveJSON - If this is true, the field public final String JSON will contain the original JSON string retrieved from the server. If this is FALSE, the JSON field will be null.
        Returns:
        An instance of this class, with all of the constant final fields filled in.
        Throws:
        java.io.IOException
        Code:
        Exact Method Body:
         return new Pin1Yin1(chineseText, saveJSON);
        
      • toString

        🡅    
        public java.lang.String toString()
        This converts 'this' result to a java.lang.String
        Overrides:
        toString in class java.lang.Object
        Code:
        Exact Method Body:
         StringBuilder sb = new StringBuilder();
         if (JSON != null) sb.append(JSON + "\n");
         sb.append("Simp: " + simpSENTENCE + "\n" + "Trad: " + tradSENTENCE);
        
         sb.append("\nSimp-Words:\t");
         for (String s : simp) sb.append(s + ", ");
         int len = sb.length();
         sb.delete(len - 2, len); // DELETE THE ENDING COMMA-SPACE 
        
         sb.append("\nPron-Words:\t");
         for (String s : pron) sb.append(s + ", ");
         len = sb.length();
         sb.delete(len - 2, len); // DELETE THE ENDING COMMA-SPACE 
        
         sb.append("\nTrad-Words:\t");
         for (String s : trad) sb.append(s + ", ");
         len = sb.length();
         sb.delete(len - 2, len); // DELETE THE ENDING COMMA-SPACE 
        
         sb.append("\nEngl-Words:\t");
         for (String s : engl) sb.append("[" + s + "] ");
        
         return sb.toString();