/// <summary> /// Absorbs the specified solution's furigana parts. /// </summary> /// <param name="other">Solution to absorb.</param> /// <param name="index">Index to add to each of the other furigana part's indexes.</param> public void EatSubsolution(FuriganaSolution other, int index) { foreach (FuriganaPart part in other.Furigana) { Furigana.Add(new FuriganaPart(part.Value, part.StartIndex + index, part.EndIndex + index)); } }
/// <summary> /// Attempts to add the given solution to the set. /// </summary> /// <param name="solution">Solution to add.</param> /// <returns>True if the solution was added. False otherwise.</returns> public bool SafeAdd(FuriganaSolution solution) { if (!solution.Check()) { // The specified solution is not valid. return(false); } if (Solutions.Any(s => s.Equals(solution))) { // We already have an equivalent solution. return(false); } // All is good. Solutions.Add(solution); return(true); }
public override bool Equals(object obj) { FuriganaSolution other = obj as FuriganaSolution; if (other != null) { // Compare both solutions. if (Vocab != other.Vocab || Furigana.Count != other.Furigana.Count) { // Not the same vocab or not the same count of furigana parts. return(false); } // If there is at least one furigana part that has no equivalent in the other // furigana solution, then the readings differ. return(Furigana.All(f1 => other.Furigana.Any(f2 => f1.Equals(f2))) && other.Furigana.All(f2 => Furigana.Any(f1 => f1.Equals(f2)))); } return(base.Equals(obj)); }
public override string ToString() { if (!Solutions.Any()) { return("???"); } StringBuilder output = new StringBuilder(); for (int i = 0; i < Solutions.Count; i++) { FuriganaSolution a = Solutions[i]; if (i < Solutions.Count - 1) { output.Append(string.Format("{0}, ", a)); } else { output.Append(a.ToString()); } } return(output.ToString()); }
public SpecialReading(string kanaReading, FuriganaSolution furigana) { KanaReading = kanaReading; Furigana = furigana; }
/// <summary> /// Checks if the solution is correctly solved. /// </summary> /// <returns>True if the furigana covers all characters without overlapping. /// False otherwise.</returns> public bool Check() { return(FuriganaSolution.Check(Vocab, Furigana)); }