📄 verb.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package velephant.business;import java.util.ArrayList;/** * * @author Doan Chien Thang */public class Verb implements Comparable { /** * All the conjunctions of the verb, each element is a string which * describe all the conjunctions of all persons in a tense. For example, * with the verb "aller", we have: * conjugaisons = [ * "aller", * "vais, vas, va, allons, allez, vont", * "irai, iras, ira, irons, irez, iront", * etc,. * ] */ private String[] conjugaisons = new String[10]; public Verb(String conjugaisons[]) { this.conjugaisons = conjugaisons; } public Verb(String conjStr) { String s[] = conjStr.split(","); System.out.println(s.length); System.out.println(s[0]); conjugaisons[Tense.INFINITIF] = s[0]; for (int i = 1; i <= 7; i++) { String conjugaison = ""; for (int j = 1; j < 6; j++) conjugaison += s[(i - 1) * 6 + j] + ", ";// System.out.println(i); conjugaison += s[i * 6]; conjugaisons[i] = conjugaison; } conjugaisons[Tense.PARTICIPE_PRESENT] = s[43]; conjugaisons[Tense.PARTICIPE_PASSE] = s[44] + ", " + s[45] + ", " + s[46] + ", " + s[47]; } /** * Get the infinitive form of the verb * @return The infinitive form of the verb */ public String infinitif() { return conjugaisons[Tense.INFINITIF]; } /** * Get the conjugaison (in String-form) of the verb by tense. For example, * with the verb "aller" and tense = 1 (indicatif present), the result is * "vais, vas, va, allons, allez, vont". * @param tense The tense which we want to get the conjugaison * @return The conjugaison correspondent with the tense */ public String getConjugaisonByTense(int tense) { return conjugaisons[tense]; } /** * Set the conjugaison (in String-form) of the verb by tense. * @param tense The tense which we want to get the conjugaison * @param conjugaisonByTense The conjugaison which we want to set */ public void setConjugaisonByTense(int tense, String conjugaisonByTense) { conjugaisons[tense] = conjugaisonByTense; } public void setConjugaisons(String conjugaisons[]) { this.conjugaisons = conjugaisons; } /** * This method is used for export the data to the dictionary. For example, * with the verb "aller", the result of this method is "aller, vais, vas, * va, allons, allez, irai, iras, ira, irons, irez, iront,..., allées" * @return The compressed string represent all the conjunction */ public String compactForm() { String result = ""; for (int i = 0; i < conjugaisons.length; i++) result += (i < conjugaisons.length - 1) ? conjugaisons[i] + "," : conjugaisons[i]; return result; } @Override public String toString() { return this.infinitif(); } /** * This method returns the "printable format", the format which is used * to show all the conjunctions in all tenses of a verb. * @return A string represents all conjugaisons in the "printable format" */ public String printableFormat() { String result = "<html><body style=\"padding:10px 0px 0px 10px;" + "font-family:tahoma; font-size:10px\">"; result += "<h3 style=\"color:blue\">Conjugaisons du verbe " + infinitif() + "</h3>"; result += "<div style=\"padding:10;" + "margin-right:15\">Indicatif présent : " + conjugaisons[Tense.INDICATIF_PRESENT] + "<br /><br />"; result += "Futur simple : " + conjugaisons[Tense.FUTUR_SIMPLE] + "<br /><br />"; result += "Passé : " + conjugaisons[Tense.PASSE] + "<br /><br />"; result += "Imparfait : " + conjugaisons[Tense.IMPARFAIT] + "<br /><br />"; result += "Présent du subjonctif : " + conjugaisons[Tense.PRESENT_DU_SUBJONCTIF] + "<br /><br />"; result += "Imparfait du subjonctif : " + conjugaisons[Tense.IMPARFAIT_DU_SUBJONCTIF] + "<br /><br />"; result += "Conditionnel : " + conjugaisons[Tense.CONDITIONNEL] + "<br /><br />"; result += "Participe présent : " + conjugaisons[Tense.PARTICIPE_PRESENT] + "<br /><br />"; result += "Participe passé : " + conjugaisons[Tense.PARTICIPE_PASSE] + "<br /><br />"; return result + "</div></body></html>"; } public static boolean isValid(int tense, String inputToTest) { inputToTest = inputToTest.toLowerCase().trim(); String reg1 = "([a-z]+,\\s){5}[a-z]+"; String reg2 = "([a-z]+,\\s){3}[a-z]+"; String reg3 = "[a-z]+"; if (tense >= 1 && tense <= 7) return inputToTest.matches(reg1); else if (tense == 8) return inputToTest.matches(reg2); return inputToTest.matches(reg3); } public String getDictForm() { String result = ",\"" + conjugaisons[0] + ","; for (int i = 1; i < conjugaisons.length; i++) { for (int j = 0; j < conjugaisons[i].length(); j++) { if (conjugaisons[i].charAt(j) != ' ') result += conjugaisons[i].charAt(j); } result += (i < conjugaisons.length - 1) ? "," : ""; } return (result + "\"").trim(); } public int getTense(String conj) { for (int i = 0; i < this.conjugaisons.length; i++) if (conjugaisons[i].contains(conj)) return i; return -1; } public int getPerson(String conj) { return -1; } public int compareTo(Object o) { Verb v = (Verb)o; return this.infinitif().compareTo(v.infinitif()); } public ArrayList<Conjugaison> getConjugaisons(int idx) { ArrayList<Conjugaison> conjs = new ArrayList<Conjugaison>(); for (int i = 0; i < this.conjugaisons.length; i++) { String s[] = conjugaisons[i].split(","); for (int j = 0; j < s.length; j++) { s[j] = s[j].trim(); conjs.add(new Conjugaison(s[j], idx, i, j + 1, this)); } } return conjs; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -