private bool IsRelatedTo(Grapheme grapheme) { if (this.relatedGraphemes.Contains(grapheme)) { return(true); } return(false); }
public Grapheme ToGrapheme(string letters) { var graphemes = this.ToGraphemes(letters); Grapheme graphemeSum = Grapheme.Empty(); foreach (Grapheme grapheme in graphemes) { graphemeSum.MergeWith(grapheme); } return(graphemeSum); }
private IEnumerable <Codepoint[]> GenerateNormalizationCodepointVariations(Grapheme grapheme) { var result = this.GenerateCodepointVariations(grapheme.Normalize(NormalizationForm.FormC).ToArray()) .Concat(this.GenerateCodepointVariations(grapheme.Normalize(NormalizationForm.FormD).ToArray())); if (this.includeKForm) { result = result .Concat(this.GenerateCodepointVariations(grapheme.Normalize(NormalizationForm.FormKC).ToArray())) .Concat(this.GenerateCodepointVariations(grapheme.Normalize(NormalizationForm.FormKD).ToArray())); } return(result); }
public void AcceptDrop(Grapheme grapheme) { if (!this.enabled) { return; } GD.Print(this.Name); if (this.IsRelatedTo(grapheme)) { this.selectedGraphemesCorrect.Add(grapheme); } else { this.selectedGraphemesIncorrect.Add(grapheme); } this.GetParent <Main>().SetActivePhoneme(this); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { foreach (NodePath graphemePath in this.relatedGraphemePaths) { Grapheme grapheme = null; grapheme = GetNode <Grapheme>(graphemePath); if (grapheme is Grapheme realGrapheme) { this.relatedGraphemes.Add(realGrapheme); } else { GD.Print("Invalid RelatedGraphemes for: " + this.Name); } } if (!this.enabled) { this.Frame = 1; this.permanentlyDisabled = true; } }
public override void _Input(InputEvent @event) { if (@event is InputEventMouseMotion eventMouseMotion && this.activeDragNode != this && this.activeDragNode is Grapheme dragNode) { dragNode.Translate(eventMouseMotion.Relative); } if (@event is InputEventMouseButton eventMouseButton && this.activeDragNode == this && eventMouseButton.Pressed == true && eventMouseButton.ButtonIndex == 1) { Physics2DDirectSpaceState spaceState = GetWorld2d().DirectSpaceState; Godot.Collections.Array graphemeCheck = spaceState.IntersectPoint(eventMouseButton.Position, maxResults: 1, collideWithAreas: true, collisionLayer: 2); if (graphemeCheck.Count > 0) { Area2D graphemeCollider = (Area2D)((Godot.Collections.Dictionary)graphemeCheck[0])["collider"]; Grapheme grapheme = graphemeCollider.GetParent <Grapheme>(); this.Drag(grapheme); } } if (@event is InputEventMouseButton eventMouseButtonRelease && this.activeDragNode != this && eventMouseButtonRelease.Pressed == false && eventMouseButtonRelease.ButtonIndex == 1) { this.Drop(eventMouseButtonRelease.Position); } }
public RxNode <TLetter> MapGrapheme(Grapheme grapheme, bool caseSensitive) { var singleCodepoints = new HashSet <TLetter>(); var compoundCodepoints = new HashSet <TLetter[]>(ArrayContentEqualityComparer <TLetter> .Default); foreach (var letterCodepoints in this.GenerateCasedNormalizationLetterVariations(grapheme, caseSensitive)) { Debug.Assert(letterCodepoints.Length > 0); if (letterCodepoints.Length == 1) { singleCodepoints.Add(letterCodepoints[0]); } else { compoundCodepoints.Add(letterCodepoints); } } return(compoundCodepoints .Select(l => l.Select(c => new RxMatch <TLetter>(c)).JoinConcatenation()) .Append(new RxMatch <TLetter>(singleCodepoints)) .JoinAlternation()); }
public void Drag(Grapheme node) { this.activeDragNode = node; node.DragStart(); }
protected override IEnumerable <byte[]> GenerateCasedNormalizationLetterVariations(Grapheme grapheme, bool caseSensitive) { return(this .GenerateCasedNormalizationCodepointVariations(grapheme, caseSensitive) .Select(c => c.ToUtf8Bytes().ToArray())); }
protected override IEnumerable <Codepoint[]> GenerateCasedNormalizationLetterVariations(Grapheme grapheme, bool caseSensitive) { return(this.GenerateCasedNormalizationCodepointVariations(grapheme, caseSensitive)); }
protected abstract IEnumerable <TLetter[]> GenerateCasedNormalizationLetterVariations(Grapheme grapheme, bool caseSensitive);
protected IEnumerable <Codepoint[]> GenerateCasedNormalizationCodepointVariations(Grapheme grapheme, bool caseSensitive) { return(caseSensitive ? this.GenerateNormalizationCodepointVariations(grapheme) : this.GenerateNormalizationCodepointVariations(grapheme.ToLowerInvariant()) .Concat(this.GenerateNormalizationCodepointVariations(grapheme.ToUpperInvariant()))); }
public List <Grapheme> ToGraphemes(string word) { var vowels = new List <Grapheme>(word.Length); var graphemes = new List <Grapheme>(word.Length); Grapheme?lasVowel = null; Grapheme?lastNotSilent = null; int consonantsInRow = 0; foreach (char letter in word) { Grapheme current = this.ToGrapheme(letter); graphemes.Add(current); switch (current.Type) { case GraphemeType.Silent: continue; case GraphemeType.Vowel: { vowels.Add(current); if (lasVowel != null) { if (consonantsInRow < 2) { lasVowel.Flags |= (uint)VowelFlag.OpenSyllable; } } lasVowel = current; consonantsInRow = 0; break; } default: consonantsInRow++; break; } if (lastNotSilent != null) { if (lastNotSilent.Type == GraphemeType.Vowel) { current.Flags |= current.Type == GraphemeType.Vowel ? (uint)VowelFlag.PreviousVowel : (uint)ConsonantFlag.PreviousVowel; } if (current.Type == GraphemeType.Vowel) { lastNotSilent.Flags |= lastNotSilent.Type == GraphemeType.Vowel ? (uint)VowelFlag.NextVowel : (uint)ConsonantFlag.NextVowel; } } lastNotSilent = current; } if (vowels.Count > 0) { if (vowels.Count <= 2) { vowels[0].Flags |= (uint)VowelFlag.Stressed; } else { vowels[^ 3].Flags |= (uint)VowelFlag.Stressed;
public IActionResult OnPost() { try { MatchCollection units = Regex.Matches(currentText, @"\{(\d*\|){2}.*?\}"); string document_edited = units[0].Value.Split('|')[0].Replace("{", ""); string text_edited = units[0].Value.Split('|')[1]; var files = new DirectoryInfo(Path.Combine(_environment.ContentRootPath, "database", "documents")).GetFiles(); Document editedDocument = new Document(); foreach (var file in files) { using (StreamReader r = new StreamReader(file.FullName)) { Document analyzedDocument = JsonConvert.DeserializeObject <Document>(r.ReadToEnd()); if (analyzedDocument.documentID == document_edited) { editedDocument = analyzedDocument; } } } foreach (Clause clause in editedDocument.texts.Where(t => t.textID == text_edited).ToList()[0].clauses) { List <string> forEditing = units.Select(c => c.Value).Where(v => Regex.Replace(v.Split('|')[2], @"(\s.*|\})", "") == clause.clauseID).ToList(); for (int i = 0; i < forEditing.Count; i++) { if (Regex.IsMatch(forEditing[i], @"\{(\d*\|){2}(\d*)(\s.*?\}|\})")) { try { List <string> addedFields = forEditing[i].Split(" => ")[1].Replace("{", "").Split(";<br />").ToList(); List <Dictionary <string, List <Value> > > newFields = new List <Dictionary <string, List <Value> > >(); Dictionary <string, List <Value> > addedField = new Dictionary <string, List <Value> >(); for (int j = 0; j < addedFields.Count; j++) { if (addedFields[j] != "") { List <string> currentFields = addedFields[j].Replace(" ;}", "").Split(";").ToList(); for (int f = 0; f < currentFields.Count; f++) { if (currentFields[f] != "}") { string field = currentFields[f].Split(':')[0]; string values = currentFields[f].Split(':')[1]; List <Value> addedValues = new List <Value>(); if (values.Contains(',')) { List <string> splitValues = values.Split(",").ToList(); for (int k = 0; k < splitValues.Count; k++) { addedValues.Add(new Value(splitValues[k].Trim())); } } else { addedValues.Add(new Value(values.Trim())); } addedField[field] = addedValues; } } } } newFields.Add(addedField); clause.clauseFields = newFields; } catch (IndexOutOfRangeException) { try { if (clause.clauseFields.Count < 1) { continue; } else { clause.clauseFields.Clear(); } } catch (NullReferenceException) { continue; } } } else if (Regex.IsMatch(forEditing[i], @"\{(\d*\|){4}(\d*)(\s.*?\}|\})")) { string realizationID = Regex.Replace(forEditing[i].Split('|')[3], @"(\s.*|\})", ""); string graphemeID = Regex.Replace(forEditing[i].Split('|')[4], @"(\s.*|\})", ""); Grapheme grapheme = clause.realizations.Where(r => r.realizationID == realizationID).Select(r => r.letters).ToList()[0].Where(g => g.graphemeID == graphemeID).ToList()[0]; try { List <string> addedFields = forEditing[i].Split(" => ")[1].Replace("{", "").Split(";<br />").ToList(); List <Dictionary <string, List <Value> > > newFields = new List <Dictionary <string, List <Value> > >(); Dictionary <string, List <Value> > addedField = new Dictionary <string, List <Value> >(); for (int j = 0; j < addedFields.Count; j++) { List <string> currentFields = addedFields[j].Replace(" ;}", "").Split(";").ToList(); for (int f = 0; f < currentFields.Count; f++) { if (currentFields[f] != "}") { string field = currentFields[f].Split(':')[0]; string values = currentFields[f].Split(':')[1]; List <Value> addedValues = new List <Value>(); if (values.Contains(',')) { List <string> splitValues = values.Split(",").ToList(); for (int k = 0; k < splitValues.Count; k++) { addedValues.Add(new Value(splitValues[k].Trim())); } } else { addedValues.Add(new Value(values.Trim())); } addedField[field] = addedValues; } } } newFields.Add(addedField); grapheme.graphemeFields = newFields; } catch (IndexOutOfRangeException) { try { if (grapheme.graphemeFields.Count < 1) { continue; } else { grapheme.graphemeFields.Clear(); } } catch (NullReferenceException) { continue; } } } else if (Regex.IsMatch(forEditing[i], @"\{(\d*\|){3}(\d*)(\s.*?\}|\})")) { Realization realization = clause.realizations.Where(r => r.realizationID == Regex.Replace(forEditing[i].Split('|')[3], @"(\s.*|\})", "")).ToList()[0]; try { List <string> addedFields = forEditing[i].Split(" => ")[1].Split("***").ToList(); List <Dictionary <string, List <Value> > > newFields = new List <Dictionary <string, List <Value> > >(); for (int j = 0; j < addedFields.Count; j++) { Dictionary <string, List <Value> > addedTagging = new Dictionary <string, List <Value> >(); if (addedFields[j] != "") { List <string> tagging = addedFields[j].Split(";<br />").ToList(); for (int f = 0; f < tagging.Count; f++) { if (tagging[f] != "}") { List <string> fieldsToAdd = tagging[f].Split(" ;").ToList(); for (int n = 0; n < fieldsToAdd.Count; n++) { if (fieldsToAdd[n] != "" && fieldsToAdd[n] != ";") { List <string> splitFields = fieldsToAdd[n].Split(';').ToList(); for (int s = 0; s < splitFields.Count; s++) { if (splitFields[s] != ";" && splitFields[s] != "") { string field = splitFields[s].Split(':')[0]; string values = splitFields[s].Split(':')[1].Replace(";", ""); List <Value> addedValues = new List <Value>(); if (values.Contains(',')) { List <string> splitValues = values.Split(",").ToList(); for (int k = 0; k < splitValues.Count; k++) { addedValues.Add(new Value(splitValues[k].Trim())); } } else { addedValues.Add(new Value(values.Trim())); } addedTagging[field] = addedValues; } } } } } } } newFields.Add(addedTagging); } realization.realizationFields = newFields; realization.realizationFields = realization.realizationFields.Where(d => d.Count != 0).ToList(); } catch (IndexOutOfRangeException) { try { if (realization.realizationFields.Count < 1) { continue; } else { realization.realizationFields.Clear(); } } catch { continue; } } } } } string documentInJSON = editedDocument.Jsonize(); var documentDBFile = Path.Combine(_environment.ContentRootPath, "database", "documents", editedDocument.documentID + "_" + editedDocument.documentName + ".json"); FileStream fs = new FileStream(documentDBFile, FileMode.Create); using (StreamWriter w = new StreamWriter(fs)) { w.Write(documentInJSON); } } catch { } docList = getDocs(); fieldsList = getFields(); return(RedirectToPage()); }