public void CreateAltLinks() { double coef0 = Coef; for (int i = 0; i < Segs.Count; i++) { NGSegmentVariant seg = Segs[i]; if (seg == null) { continue; } for (int j = 0; j < seg.Links.Count; j++) { NGLink li = seg.Links[j]; if (li == null || li.Typ == NGLinkType.List) { continue; } if (li.From.Links.Count < 2) { continue; } if (li.From.Source.Typ == SentItemType.Formula) { continue; } if (li.To != null && li.To.Source.Typ == SentItemType.Formula) { continue; } foreach (NGLink l in li.From.Links) { if (l != li && l.Typ != NGLinkType.List) { if (l.To != null && l.To.Source.Typ == SentItemType.Formula) { continue; } if (l.Typ == NGLinkType.Actant) { if (li.Typ == NGLinkType.Agent || li.Typ == NGLinkType.Pacient) { continue; } } seg.Links[j] = l; seg.CalcCoef(); double coef = coef0 - 100; if (seg.Coef > 0) { this.CalcCoef(); coef = Coef; } Coef = coef0; seg.Links[j] = li; seg.CalcCoef(); if (coef >= Coef) { li.AltLink = l; break; } } } } } }
public double CalcCoef() { Coef = 0; for (int i = 0; i < Segs.Count; i++) { if (Segs[i] != null) { Coef += Segs[i].Coef; } } for (int i = 0; i < (Segs.Count - 1); i++) { NGSegmentVariant seg0 = Segs[i]; if (seg0 == null) { continue; } NGSegmentVariant seg1 = Segs[i + 1]; if (seg1 == null) { continue; } bool hasAgent = false; bool hasPacient = false; foreach (NGLink li in seg0.Links) { if (li != null && li.ToVerb == seg1.Source.BeforeVerb) { if (li.Typ == NGLinkType.Agent) { hasAgent = true; } else if (li.Typ == NGLinkType.Pacient) { hasPacient = true; foreach (NGLink lii in li.From.Links) { if ((lii != null && lii.Typ == NGLinkType.Agent && lii.Coef >= li.Coef) && lii.ToVerb == li.ToVerb) { foreach (NGLink liii in seg1.Links) { if (liii != null && liii.ToVerb == li.ToVerb && liii.Typ == NGLinkType.Agent) { if (liii.Coef < ((lii.Coef / 3))) { return(Coef = -1); } } } } } } } } foreach (NGLink li in seg1.Links) { if (li != null && li.ToVerb == seg1.Source.BeforeVerb) { if (li.Typ == NGLinkType.Agent && hasAgent) { return(Coef = -1); } else if (li.Typ == NGLinkType.Pacient && hasPacient) { return(Coef = -1); } } } } return(Coef); }
public void CreateVariants(int maxCount = 5) { Variants.Clear(); for (int i = 0; i < Items.Count; i++) { Items[i].Ind = 0; } NGSegmentVariant var = null; for (int kkk = 0; kkk < 1000; kkk++) { if (var == null) { var = new NGSegmentVariant() { Source = this } } ; else { var.Links.Clear(); } for (int i = 0; i < Items.Count; i++) { NGItem it = Items[i]; if (it.Ind < it.Links.Count) { var.Links.Add(it.Links[it.Ind]); } else { var.Links.Add(null); } } var.CalcCoef(); if (var.Coef >= 0) { Variants.Add(var); var = null; if (Variants.Count > (maxCount * 5)) { _sortVars(Variants); Variants.RemoveRange(maxCount, Variants.Count - maxCount); } } int j; for (j = Items.Count - 1; j >= 0; j--) { NGItem it = Items[j]; if ((++it.Ind) >= it.Links.Count) { it.Ind = 0; } else { break; } } if (j < 0) { break; } } _sortVars(Variants); if (Variants.Count > maxCount) { Variants.RemoveRange(maxCount, Variants.Count - maxCount); } }