/** * <summary> Constructor of VectorizedNerInstanceGenerator which takes input a {@link VectorizedDictionary}, a window size * and a word format and sets corresponding attributes with these inputs.</summary> * <param name="fsm">Morphological analyzer used to create multi-word expressions.</param> * <param name="wordNet">WordNet for checking multii-word and single-word expressions.</param> * <param name="dictionary">Dictionary in the vector form. Each word is stored in vector form in this dictionary.</param> * <param name="windowSize">Number of previous (next) words to be considered in adding attributes.</param> * <param name="format">Word vector format.</param> */ public VectorizedSemanticInstanceGenerator(FsmMorphologicalAnalyzer fsm, WordNet.WordNet wordNet, VectorizedDictionary dictionary, int windowSize, WordFormat format) : base(fsm, wordNet) { this._format = format; this._dictionary = dictionary; this.windowSize = windowSize; }
public string GetRandomWord(LongRandom rand, string subtype, string className, WordFormat format) { int subIndex = LookForSubtype(subtype); if (subIndex == -1) { return Error("SubtypeNotFound->"+subtype); } int index = PickByWeight(className, rand); if (className == "") { if (subIndex > Words[index].Length - 1) { return Error("SubtypeOutOfRange"); } return Format(Words[index][subIndex], format); } else { if (!this.Classes.ContainsKey(className)) { return Error("ClassNotFound->"+className); } return Format(Words[this.Classes[className][index]][subIndex], format); } }
/** * <summary> Constructor of VectorizedNerInstanceGenerator which takes input a {@link VectorizedDictionary}, a window size * and a word format and sets corresponding attributes with these inputs.</summary> * <param name="dictionary">Dictionary in the vector form. Each word is stored in vector form in this dictionary.</param> * <param name="windowSize">Number of previous (next) words to be considered in adding attributes.</param> * <param name="format">Word vector format.</param> */ public VectorizedShallowParseInstanceGenerator(VectorizedDictionary dictionary, int windowSize, WordFormat format) { this._format = format; this._dictionary = dictionary; this.windowSize = windowSize; }
public void importRuleButtonPressed(int buttonIndex) { if (buttonIndex >= otherPartOfSpeech.Length) { return; } GameObject template = otherPartOfSpeech[buttonIndex]; Debug.Log(template.transform.childCount); for (int i = 0; i < template.transform.childCount; i++) { RuleBannerPageSix bannerScriptOld = template.transform.GetChild(i).GetComponent <RuleBannerPageSix>(); GameObject instanceBanner = (GameObject)Instantiate(prefabedBanner, thisPanel.transform); RuleBannerPageSix bannerScriptNew = instanceBanner.GetComponent <RuleBannerPageSix>(); bannerScriptNew.description.text = bannerScriptOld.description.text; WordFormat newWordFormat = new WordFormat(); // Copy the fields that is primary type or need not deep copy newWordFormat.numOfSyllable = bannerScriptOld.format.numOfSyllable; newWordFormat.arabicStyle = bannerScriptOld.format.arabicStyle; newWordFormat.consonantWithSemivowel = bannerScriptOld.format.consonantWithSemivowel; newWordFormat.specialVowel = bannerScriptOld.format.specialVowel; newWordFormat.specialConsonant = bannerScriptOld.format.specialConsonant; newWordFormat.vowelHolders = bannerScriptOld.format.vowelHolders; // Deep copy other field Phoneme newLeading = new Phoneme(); newLeading.addPhone(bannerScriptOld.format.specialLeading); Phoneme newEnding = new Phoneme(); newEnding.addPhone(bannerScriptOld.format.specialEnding); newWordFormat.specialLeading = newLeading; newWordFormat.specialEnding = newEnding; // Deep copy accent rules if (bannerScriptOld.format.accentRules != null && bannerScriptOld.format.accentRules.Length > 0) { WordFormat.AccentRule[] newAccentRuleList = new WordFormat.AccentRule[bannerScriptOld.format.accentRules.Length]; for (int j = 0; j < newAccentRuleList.Length; j++) { WordFormat.AccentRule newAccentRule = new WordFormat.AccentRule(); WordFormat.AccentRule oldAccentRule = bannerScriptOld.format.accentRules[j]; newAccentRule.backword = oldAccentRule.backword; newAccentRule.position = oldAccentRule.position; newAccentRule.accents = new AccentPhone[oldAccentRule.accents.Length]; for (int k = 0; k < newAccentRule.accents.Length; k++) { newAccentRule.accents[k] = oldAccentRule.accents[k]; } newAccentRuleList[j] = newAccentRule; } newWordFormat.accentRules = newAccentRuleList; } bannerScriptNew.format = newWordFormat; } }
public static string GetExtention(WordFormat WordFormatType) { string result = string.Empty; foreach (var i in WordFormatDictionary) { if (i.Key.ToString().Contains(WordFormatType.ToString())) { result = i.Value; } } return(result); }
private Morphome[] getOnePartOfSpeech(GameObject panel) { List <Morphome> result = new List <Morphome>(); for (int i = 0; i < panel.transform.childCount; i++) { Transform go = panel.transform.GetChild(i); RuleBannerPageSix script = go.GetComponent <RuleBannerPageSix>(); WordFormat format = script.format; result.Add(getFormat(format)); } return(result.ToArray()); }
/// <summary> /// Converts MS Doc type to other formats. /// </summary> /// <param name="WordDocFilePath"></param> /// <param name="OutPutFileFormat"></param> public static void ConvertWord(string WordDocFilePath, WordFormat OutPutFileFormat) { Word.Application WordApp = new Word.Application(); Object FilePath = WordDocFilePath; Object ReadOnly = true; Object Missing = Type.Missing; //This will be passed when ever we don’t want to pass value //Open document from file Word.Document WordDoc = WordApp.Documents.Open(ref FilePath, ref Missing, ref ReadOnly, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing); WordDoc.SaveAs2(FilePath + DictionaryLib.GetExtention(OutPutFileFormat), (Word.WdSaveFormat)OutPutFileFormat, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing); Object SaveChanges = false; WordDoc.Close(ref SaveChanges, ref Missing, ref Missing); //Quit the word application WordApp.Quit(ref Missing, ref Missing, ref Missing); }
public static string Capitalize(this string str, WordFormat capFormat) { if (capFormat == WordFormat.Proper) { char[] temp = new char[str.Length]; char prev = ' '; char c = ' '; for (int i = 0; i < str.Length; i++) { prev = c; c = str[i]; if (prev.PermitsCap() && char.IsLetter(c)) { temp[i] = char.ToUpper(c); } else { temp[i] = c; } } return new string(temp); } else if (capFormat == WordFormat.Capitalized) { if (str.Length > 1) return str.Substring(0, 1).ToUpper() + str.Substring(1); return str.ToUpper(); } else if (capFormat == WordFormat.AllCaps) { return str.ToUpper(); } else { return str; } }
public string GetRandomWordMultiClass(LongRandom rand, string subtype, WordFormat format, params string[] classNames) { int subIndex = LookForSubtype(subtype); if (subIndex == -1) { return Error("SubtypeNotFound->" + subtype); } for (int i = 0; i < classNames.Length; i++) { if (!this.Classes.ContainsKey(classNames[i])) { return Error("ClassNotFound->" + classNames[i]); } } List<int> mcList = GetMultiClassList(classNames); if (mcList.Count == 0) { return Error("EmptyMultiClass"); } int index = PickByWeight(mcList, rand); return Format(Words[mcList[index]][subIndex], format); }
private string Format(string input, WordFormat format) { switch (format) { case WordFormat.AllCaps: return input.ToUpper(); case WordFormat.Proper: return input.Substring(0, 1).ToUpper() + input.Substring(1); case WordFormat.None: default: return input; } }
public string GetWordByIndex(int index, string subtype, WordFormat format) { int subIndex = LookForSubtype(subtype); if (subIndex == -1) { return Error("SubtypeNotFound->" + subtype); } if (subIndex > Words[index].Length - 1) { return Error("InadequateSubtypeCount"); } return Format(Words[index][subIndex], format); }
/// <summary> /// Retuns the string representation of this Word in specified format /// </summary> public string ToString(WordFormat format) { return(format.Format(this)); }
private Morphome getFormat(WordFormat format) { Morphome result = new Morphome(); result.SyllableNumber = format.numOfSyllable; // Get info if the format is in arabic style if (format.arabicStyle) { result.AfroAsian = true; result.Affixed = false; result.SpecialPhone = false; result.SemivoweledConsonant = format.consonantWithSemivowel; result.ClusteredConsonant = format.consonantCluster; result.HolderVowels = convertPhonemes(format.vowelHolders); } // Get info if the format is not arabic style else { result.AfroAsian = false; result.SemivoweledConsonant = false; result.ClusteredConsonant = false; result.Affixed = false; result.SpecialPhone = false; // Set affix if (format.specialLeading != null && format.specialLeading.phones.Length > 0) { result.Affixed = true; result.Prefix = convertPhoneme(format.specialLeading); } if (format.specialEnding != null && format.specialEnding.phones.Length > 0) { result.Affixed = true; result.Suffix = convertPhoneme(format.specialEnding); } // Set special phone if (format.specialVowel != null && format.specialVowel.Length > 0) { result.SpecialPhone = true; result.SpecialVowels = convertPhonemes(format.specialVowel); } if (format.specialConsonant != null && format.specialConsonant.Length > 0) { result.SpecialPhone = true; result.SpecialConsonants = convertPhonemes(format.specialConsonant); } // Set accent rule if (format.accentRules != null && format.accentRules.Length > 0) { List <Morphome.ToneRequiement> ruleList = new List <Morphome.ToneRequiement>(); for (int k = 0; k < format.accentRules.Length; k++) { WordFormat.AccentRule accentRule = format.accentRules[k]; Morphome.ToneRequiement tone = new Morphome.ToneRequiement(); if (accentRule.backword) { int position = result.SyllableNumber - accentRule.position; tone.Position = position; } else { tone.Position = accentRule.position; } if (tone.Position <= 0 || tone.Position > result.SyllableNumber) { continue; } Phone[] potentials = new Phone[accentRule.accents.Length]; for (int kk = 0; kk < potentials.Length; kk++) { Phone potential = new Phone(); potential.converProtoPhone(accentRule.accents[kk]); potentials[kk] = potential; } tone.Accents = potentials; ruleList.Add(tone); } result.Tones = ruleList.ToArray(); } } return(result); }
// Save the newly created rule public void onSaveButtonPressed() { aFormat = new WordFormat(); aFormat.numOfSyllable = syllableNum; if (arabicFormatToggle.isOn) { aFormat.arabicStyle = true; aFormat.consonantWithSemivowel = useSemivoweledConsonant.isOn; aFormat.consonantCluster = useClusteredConsonant.isOn; List <Phoneme> forVowelHolder = new List <Phoneme>(); for (int i = 0; i < arabicFormatContent.transform.childCount; i++) { ToBePickedScript script = arabicFormatContent.transform.GetChild(i).GetComponent <ToBePickedScript>(); if (script.aVowelPhoneme == null) { aFormat.arabicStyle = false; aFormat.consonantWithSemivowel = false; aFormat.consonantCluster = false; break; } forVowelHolder.Add(script.aVowelPhoneme); } aFormat.vowelHolders = forVowelHolder.ToArray(); } else { aFormat.arabicStyle = false; // Get accent rules if (accentNum > 0) { List <WordFormat.AccentRule> aList = new List <WordFormat.AccentRule>(); for (int i = 0; i < accentPanel.transform.childCount; i++) { AddAccentPageSix script = accentPanel.transform.GetChild(i).GetComponent <AddAccentPageSix>(); WordFormat.AccentRule wfar = new WordFormat.AccentRule(); if (script.coundBack.options.ToArray()[script.coundBack.value].text.Equals("Backward")) { wfar.backword = true; } else { wfar.backword = false; } try { if (script.positionField.text.Equals("")) { wfar.position = int.Parse(script.holder.text); } else { wfar.position = int.Parse(script.positionField.text); } if (wfar.position > syllableNum) { continue; } Manager manager = UnityEngine.Object.FindObjectOfType <Manager>(); LanguageManager languageManager = manager.languageManager; AccentPhone[] accents = languageManager.accents; if (script.accentType.value.Equals("all")) { wfar.accents = accents; } else { List <AccentPhone> potentialAccent = new List <AccentPhone>(); foreach (AccentPhone actp in accents) { string value = script.accentType.options.ToArray()[script.accentType.value].text; string IPA = actp.IPA; string contour = actp.Contour; string level = actp.Level; if (value.Equals(IPA) || value.Equals(contour) || value.Equals(level)) { potentialAccent.Add(actp); } } wfar.accents = potentialAccent.ToArray(); } aList.Add(wfar); } catch (Exception e) { continue; } } aFormat.accentRules = aList.ToArray(); } // Get special affix if (specialAffixToggle.isOn) { if (specialPrefixToggle.isOn && prefixPhoneme != null && prefixPhoneme.phones.Length > 0) { aFormat.specialLeading = prefixPhoneme; } if (specialSuffixToggle.isOn && suffixPhoneme != null && suffixPhoneme.phones.Length > 0) { aFormat.specialEnding = suffixPhoneme; } } // Get special phone if (specialPhoneToggle.isOn) { if (specialVowelToggle.isOn && specialPickedVowel != null && specialPickedVowel.Length > 0) { aFormat.specialVowel = specialPickedVowel; } if (specialConsonantToggle.isOn && specialPickedConsonant != null && specialPickedConsonant.Length > 0) { aFormat.specialConsonant = specialPickedConsonant; } } // Create a rule banner // prefabedRuleBanner // RuleBannerPageSix } if (oldBanner != null) { oldBanner.format = aFormat; oldBanner.description.text = aFormat.getDescription(); } if (oldBanner == null && fromThisPanel != null) { GameObject instanceBanner = (GameObject)Instantiate(prefabedRuleBanner, fromThisPanel.transform); RuleBannerPageSix instanceScript = instanceBanner.GetComponent <RuleBannerPageSix>(); instanceScript.format = aFormat; instanceScript.description.text = aFormat.getDescription(); } Destroy(this.transform.gameObject); }