public int FindChannel(string Name, string country) { List <ChannelGrabberInfo> channels = GetChannelArrayList(country); int retChan = -1; if (channels == null) { return(retChan); } ChannelGrabberInfo ch; Levenstein comparer = new Levenstein(); float bestSimilarity; float similarity; int mostSimilarChan = -1; bestSimilarity = MIN_SIMILARITY; for (int i = 0; i < channels.Count; i++) { ch = (ChannelGrabberInfo)channels[i]; if (ch.GrabberList == null) { continue; } if (Name.Equals(ch.FullName, StringComparison.OrdinalIgnoreCase)) { retChan = i; break; } if (ch.FullName.IndexOf(Name, StringComparison.OrdinalIgnoreCase) != -1) { retChan = i; } similarity = comparer.getSimilarity(Name, ch.FullName); if (similarity > bestSimilarity) { mostSimilarChan = i; bestSimilarity = similarity; } } if (retChan < 0) { return(mostSimilarChan); } return(retChan); }
public ChannelGrabberInfo[] FindChannels(string[] NameList, string country) { List <ChannelGrabberInfo> channels = GetChannelArrayList(country); ChannelGrabberInfo[] retList = new ChannelGrabberInfo[NameList.Length]; if (channels == null) { return(retList); } ChannelGrabberInfo ch; Levenstein comparer = new Levenstein(); float bestSimilarity; float similarity; for (int k = 0; k < NameList.Length; k++) { bestSimilarity = MIN_SIMILARITY; for (int i = 0; i < channels.Count; i++) { ch = (ChannelGrabberInfo)channels[i]; if (NameList[k] == ch.FullName) { retList[k] = ch; break; } if (ch.FullName.IndexOf(NameList[k]) != -1) { retList[k] = ch; break; } similarity = comparer.getSimilarity(NameList[k], ch.FullName); if (similarity > bestSimilarity) { retList[k] = ch; bestSimilarity = similarity; } } } return(retList); }
private void mpListViewChannels_SelectedIndexChanged(object sender, EventArgs e) { mpListViewMapped.BeginUpdate(); try { mpListViewMapped.Items.Clear(); if (mpListViewChannels.SelectedIndices == null) { return; } if (mpListViewChannels.SelectedIndices.Count != 1) { return; } Card card = ((CardInfo)mpComboBoxCard.SelectedItem).Card; ListViewItem selectedItem = mpListViewChannels.Items[mpListViewChannels.SelectedIndices[0]]; Channel selectedChannel = (Channel)selectedItem.Tag; IList <Channel> allChannels = Channel.ListAll(); List <ListViewItem> items = new List <ListViewItem>(); NotifyForm dlg = new NotifyForm("Searching for Similar Channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Channel channel in allChannels) { if (channel.IsRadio == false) { continue; } bool isMapped = false; IList <ChannelMap> list = channel.ReferringChannelMap(); foreach (ChannelMap map in list) { if (map.IdCard == card.IdCard) { isMapped = true; break; } } if (isMapped) { continue; } Levenstein comparer = new Levenstein(); float result = comparer.getSimilarity(selectedChannel.DisplayName, channel.DisplayName); IList <TuningDetail> details = channel.ReferringTuningDetail(); int imageIndex = GetImageIndex(details); ListViewItem item = new ListViewItem((result * 100f).ToString("f2") + "%", imageIndex); item.Tag = channel; item.SubItems.Add(channel.DisplayName); items.Add(item); } mpListViewMapped.Items.AddRange(items.ToArray()); mpListViewMapped.Sort(); dlg.Close(); } finally { mpListViewMapped.EndUpdate(); } }