public override int GetHashCode() { int code = 23; code += code * 31 + Morphemes.Select(m => m.Id).GetSequenceHashCode(); code += code * 31 + RootMorphemeIndex.GetHashCode(); code += code * 31 + Category?.GetHashCode() ?? 0; return(code); }
public void AddMorpheme(Morpheme morpheme) { if (Morphemes == null) { throw new HangerdException("Morphemes has not been loaded."); } if (Morphemes.Any(m => m.Morpheme.Id == morpheme.Id)) { throw new HangerdException("该词素已添加"); } Morphemes.Add(new WordMorpheme(morpheme, Morphemes.Count)); }
public void RemoveMorpheme(string morphemeId) { if (Morphemes == null) { throw new HangerdException("Morphemes has not been loaded."); } var removedMorpheme = Morphemes.FirstOrDefault(m => m.Morpheme.Id == morphemeId); if (removedMorpheme == null) { throw new HangerdException("词素信息不存在"); } Morphemes.Remove(removedMorpheme); foreach (var morpheme in Morphemes.Where(m => m.Order > removedMorpheme.Order)) { morpheme.ModifyOrder(morpheme.Order - 1); } }
public override string ToString() { return(string.Format("[{0}]", string.Join(" ", Morphemes.Select((m, i) => i == RootMorphemeIndex ? "*" + m : m.ToString())))); }
public bool Equals(WordAnalysis other) { return(other != null && Morphemes.Select(m => m.Id).SequenceEqual(other.Morphemes.Select(m => m.Id)) && RootMorphemeIndex == other.RootMorphemeIndex && Category == other.Category); }