public void addToMatchedList(WitnessRecord key,List<WitnessRecord> value) { if (!MatchedList.ContainsKey(key)) { MatchedList.Add(key, value); } }
public void addToPartialMerge(WitnessRecord record) { //PartialMerge.Add(record); if(!PartialMerge.Contains(record)) PartialMerge.Insert(0, record); }
public void addNoMerge(WitnessRecord record) { NoMerge.Add(record); }
public void addToFullMerge(WitnessRecord record) { if(!FullMerge.Contains(record)) FullMerge.Add(record); }
public void addNewWitness(WitnessRecord record) { ActualRecords.Add(record); }
private WitnessList FindBestMatchInFullList(WitnessRecord W1Record, WitnessRecord W2Record, bool bNoSplit) { var revWitnesList = ConstraintMatching(W1Record, W2Record, bNoSplit); var W1RecordLen = W1Record.GetWitnessRecordItems().Count; var W2RecordLen = W2Record.GetWitnessRecordItems().Count; var revRecordLen = revWitnesList.FullMergeWintess[0].GetWitnessRecordItems().Count; if (!((revRecordLen > W1RecordLen) && (revRecordLen > W2RecordLen))) { revWitnesList.addToPartialMerge(W1Record); revWitnesList.addToPartialMerge(W2Record); revWitnesList.FullMergeWintess.Clear(); } return revWitnesList; }
private WitnessRecord CreateWitnessRecord(List<string> recorditem) { WitnessName = "Witness_" + WitnessNumber; WitnessNumber++; var witness = new WitnessRecord(WitnessName); bool bLastItem = false; int listLength = recorditem.Count; for (int i = 0; i < listLength; i++) { if ((i + 1) == listLength) bLastItem = true; WitnessRecordItem props = new WitnessRecordItem(recorditem[i], WitnessName, bLastItem); witness.addItemToList(props); } return witness; }
private void AddNewWitness(List<string> items) { WitnessName = "Witness_" + WitnessNumber; WitnessNumber++; WitnessRecord witness = new WitnessRecord(WitnessName); bool bLastItem = false; int listLength = items.Count; for (int i = 0; i < listLength; i++) { if ((i + 1) == listLength) bLastItem = true; WitnessRecordItem props = new WitnessRecordItem(items[i], WitnessName, bLastItem); witness.addItemToList(props); } wintessList.addNewWitness(witness); }
protected WitnessList ConstraintMatching(WitnessRecord WitnessOne, WitnessRecord WitnessTwo, bool bIgnoreIfSplit) { WitnessList newWitnessList = new WitnessList(ref wintessList); List<string> newRecordItems = new List<string>(); List<string> subWitnessitems = null; bool bSplit = false; int iLastVistedPos = 0; string lastMatchdString = string.Empty; try { foreach (var WOneRecordItem in WitnessOne.GetWitnessRecordItems()) { string witnessItem_W1 = WOneRecordItem.getWitness(); bool bFirstItem_W1 = WOneRecordItem.IsFirstItem; bool bLastItem_W1 = WOneRecordItem.isLastItem; bool bNextItem_W1 = false; int ItemIndex; if (!bFirstItem_W1 && !bLastItem_W1) bNextItem_W1 = true; bool bItemMatched = isItemMatched(witnessItem_W1, WitnessTwo, out ItemIndex); var WitnessTwoItemsList = WitnessTwo.GetWitnessRecordItems(); if (bItemMatched) { int stPos = WitnessTwo.LastVistedItem + 1; var WitnessTwoItems = WitnessTwoItemsList[ItemIndex]; string witnessItem_W2 = WitnessTwoItems.getWitness(); bool bFirstItem_W2 = WitnessTwoItems.IsFirstItem; bool bLastItem_W2 = WitnessTwoItems.isLastItem; bool bNextItem_W2 = false; string witnessGroup = WitnessTwoItems.WitnessGroup; lastMatchdString = witnessItem_W2; if (!bFirstItem_W2 && !bLastItem_W2) { bNextItem_W2 = true; } if ((bFirstItem_W1 && bFirstItem_W2) || (bNextItem_W1 && bFirstItem_W2) || (bLastItem_W1 && bFirstItem_W2)) { newRecordItems.Add(witnessItem_W2); WitnessTwo.LastVistedItem = ItemIndex; } else if ((bFirstItem_W1 && bNextItem_W2) || (bFirstItem_W1 && bLastItem_W2)) { for (int j = stPos; j <= ItemIndex; j++) { newRecordItems.Add(WitnessTwoItemsList[j].getWitness()); } WitnessTwo.LastVistedItem = ItemIndex; } else if ((bNextItem_W1 && bNextItem_W2) || (bNextItem_W1 && bLastItem_W2)) { WitnessTwo.LastVistedItem = ItemIndex; if (WitnessOne.GetPrevItemMatched(witnessGroup)) { for (int j = stPos; j <= ItemIndex; j++) { newRecordItems.Add(WitnessTwoItemsList[j].getWitness()); } } else { if (!bIgnoreIfSplit) { //split bSplit = true; subWitnessitems = new List<string>(); int stIndex = stPos > 0 ? (stPos - 1) : -1; if (stIndex >= 0) CopyTillLastMatch(ref newRecordItems, WitnessTwoItemsList[stIndex].getWitness(), ref subWitnessitems); for (int j = stPos; j <= ItemIndex; j++) { subWitnessitems.Add(WitnessTwoItemsList[j].getWitness()); } newRecordItems.Add(witnessItem_W2); } } } else if ((bLastItem_W1 && bNextItem_W2) || (bLastItem_W1 && bLastItem_W2)) { WitnessTwo.LastVistedItem = WitnessTwoItemsList.Count; if (WitnessOne.GetPrevItemMatched(witnessGroup)) { for (int j = stPos; j < WitnessTwoItemsList.Count; j++) { newRecordItems.Add(WitnessTwoItemsList[j].getWitness()); } } else { if (!bIgnoreIfSplit) { //split bSplit = true; subWitnessitems = new List<string>(); int stIndex = stPos > 0 ? (stPos - 1) : -1; if (stIndex >= 0) CopyTillLastMatch(ref newRecordItems, WitnessTwoItemsList[stIndex].getWitness(), ref subWitnessitems); int matchedItemPos = stPos; bool bVisit = false; for (int j = stPos; j < WitnessTwoItemsList.Count; j++) { if (witnessItem_W2.Equals(WitnessTwoItemsList[j].getWitness())) { if (!bVisit) { matchedItemPos = j; bVisit = true; } } subWitnessitems.Add(WitnessTwoItemsList[j].getWitness()); } for (int j = matchedItemPos; j < WitnessTwoItemsList.Count; j++) { newRecordItems.Add(WitnessTwoItemsList[j].getWitness()); } } } } iLastVistedPos = WitnessTwo.LastVistedItem; WitnessOne.SetPrevItemMatched(true, witnessGroup); } else { iLastVistedPos++; var groupName = WitnessTwoItemsList[0].WitnessGroup; if (!bIgnoreIfSplit) { if (iLastVistedPos + 1 == WitnessTwoItemsList.Count) // last item in second list { bSplit = true; subWitnessitems = new List<string>(); CopyTillLastMatch(ref newRecordItems, lastMatchdString, ref subWitnessitems); for (int j = WitnessTwo.LastVistedItem + 1; j < WitnessTwoItemsList.Count; j++) { subWitnessitems.Add(WitnessTwoItemsList[j].getWitness()); } } if (bLastItem_W1 && WitnessOne.GetPrevItemMatched(groupName)) { if ((iLastVistedPos + 1) > WitnessTwoItemsList.Count) // No more elements in W2 { if (subWitnessitems == null) subWitnessitems = new List<string>(); subWitnessitems.Add(witnessItem_W1); } } } newRecordItems.Add(witnessItem_W1); WitnessOne.SetPrevItemMatched(false, groupName); } } if (!bSplit) { newWitnessList.addToFullMerge(CreateWitnessRecord(newRecordItems)); } else { if (!bIgnoreIfSplit) { if (subWitnessitems != null) { newWitnessList.addToPartialMerge(CreateWitnessRecord(subWitnessitems)); } newWitnessList.addToPartialMerge(CreateWitnessRecord(newRecordItems)); } else newWitnessList.addToPartialMerge(WitnessTwo); } } catch (Exception e) { Console.WriteLine("Contraint matching error" + e.Message); } finally { WitnessTwo.LastVistedItem = -1; } return newWitnessList; }