Package Torello.Languages
Class Pin1Yin1
- java.lang.Object
-
- Torello.Languages.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 aclass Pin1Yin1
instantiation.Pin1Yin1 response = Pin1Yin1.getResponse("中国政府网_中央人民政府门户网站", false); System.out.println("Here are the respose vocabulary words:\n" + response.toString());
Hi-Lited Source-Code:- View Here: Torello/Languages/Pin1Yin1.java
- Open New Browser-Tab: Torello/Languages/Pin1Yin1.java
File Size: 8,536 Bytes Line Count: 247 '\n' Characters Found
-
-
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
PinYinURL
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 Chineseint[]
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 aString
-
-
-
Field Detail
-
PIN1_YIN1_URL
public static final java.lang.String PIN1_YIN1_URL
PinYinURL
- 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.
-
tradSENTENCE
public final java.lang.String tradSENTENCE
This is the original query-string in Traditional Chinese
-
simp
public final java.lang.String[] simp
The Simplified Conversion - in this version, characters are grouped by "Word Boundaries"
-
pron
public final java.lang.String[] pron
The Pronunciation of each element in the "Word Boundaries" version.
-
trad
public final java.lang.String[] trad
The traditional conversion - In this version, also, characters are grouped by "Word Boundaries"
-
engl
public final java.lang.String[] engl
These are the English Translations of each word; some Chinese Words are translated into multiple english words.
-
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 arrayfinal String[] pron
contains as many syllables as the "Grouped By" Chinese Word does.
-
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.
-
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
-
-
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("P1: " + P1 + "\nP2: " + P2 + "\nP3: " + P3); // System.exit(1); 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 fieldpublic 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 ajava.lang.String
- Overrides:
toString
in classjava.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();
-
-