public List <DyntaxaMatchItem> GetMatches(List <Int32> taxonIds, MatchSettingsViewModel options) { var list = new List <DyntaxaMatchItem>(); // todo - it would be nice if GetTaxaByIds don't throw Exception on non existing taxon ids. //var taxa = CoreData.TaxonManager.GetTaxaByIds(_user, taxonIds); int row = 1; foreach (Int32 id in taxonIds) { var matchItem = new DyntaxaMatchItem(id); matchItem.RowNumber = row++; ITaxon taxon = null; try { taxon = CoreData.TaxonManager.GetTaxon(_user, id); } catch { } if (taxon != null) { matchItem.SetTaxon(taxon, options); matchItem.Status = MatchStatus.Exact; } else { matchItem.Status = MatchStatus.NoMatch; } list.Add(matchItem); } return(list); }
/// <summary> /// The general matching algorithm. /// This method is called by all the other methods in order to get the match result. /// </summary> /// <param name="item">The match item.</param> /// <param name="options">Match options.</param> /// <returns></returns> private DyntaxaMatchItem GetMatch(DyntaxaMatchItem item, MatchSettingsViewModel options) { item.Status = MatchStatus.NoMatch; if (options.ColumnContentAlternative == MatchColumnContentAlternative.NameAndAuthorCombined) { //TODO: split name and author /* * StringBuilder name = new StringBuilder(); * StringBuilder author = new StringBuilder(); * bool nameIsCompleted = false; * string[] stringArray = item.NameString.Split(' '); * for (int i = 0; i < stringArray.Length; i++) * { * if (!nameIsCompleted) * { * if (name.Length > 0) * { * name.Append(" "); * * } * name.Append(stringArray[i]); * } * } */ } //ITaxonSearchCriteria taxonSearchCriteria = new TaxonSearchCriteria(); //taxonSearchCriteria.TaxonName = item.NameString; ////taxonSearchCriteria.TaxonIds = ////taxonSearchCriteria.TaxonCategoryIds = //CoreData.TaxonManager.GetTaxaBySearchCriteria(_user, taxonSearchCriteria); //var taxonNameSearchCriteria = new TaxonNameSearchCriteria(); //taxonNameSearchCriteria.NameSearchString = new StringSearchCriteria(); //taxonNameSearchCriteria.NameSearchString.SearchString = item.NameString; //taxonNameSearchCriteria.NameSearchString.CompareOperators = new List<StringCompareOperator>(); //taxonNameSearchCriteria.NameSearchString.CompareOperators.Add(StringCompareOperator.Iterative); //if (options.LimitToTaxon && options.LimitToParentTaxonId.HasValue) //{ // taxonNameSearchCriteria.TaxonIdList = new List<int> { options.LimitToParentTaxonId.Value }; //} options.SearchOptions.NameSearchString = item.NameString; TaxonNameSearchCriteria taxonNameSearchCriteria = options.SearchOptions.CreateTaxonNameSearchCriteriaObject(); if (options.MatchToType == MatchTaxonToType.TaxonNameAndAuthor) { taxonNameSearchCriteria.IsAuthorIncludedInNameSearchString = true; } TaxonNameList taxonNames = CoreData.TaxonManager.GetTaxonNames(_user, taxonNameSearchCriteria); if (taxonNames.IsNotEmpty()) { var dicTaxonNames = new Dictionary <int, ITaxonName>(); foreach (ITaxonName taxonName in taxonNames) { if (taxonName.Status.Id == (int)TaxonNameStatusId.Removed) { continue; } if (!dicTaxonNames.ContainsKey(taxonName.Taxon.Id)) { dicTaxonNames.Add(taxonName.Taxon.Id, taxonName); } } if (dicTaxonNames.Count == 1) { ITaxon taxon = CoreData.TaxonManager.GetTaxon(_user, dicTaxonNames.Keys.First()); item.SetTaxon(taxon, options); item.Status = MatchStatus.Exact; } else if (dicTaxonNames.Count > 1) { item.Status = MatchStatus.NeedsManualSelection; item.DropDownListIdentifier = "AlternativeTaxa" + item.RowNumber.ToString(); item.AlternativeTaxa = new TaxonSelectList(taxonNames).GetList(); // todo - den här ska vara med } } else { //TODO: Using som fuzzy algorithms to obtain taxon suggestions. } return(item); }
/// <summary> /// A method that perform matches of taxon identifiers provided in a list. /// </summary> /// <param name="items">Array of strings representing names or identifiers that should be matched with taxon concepts in Dyntaxa.</param> /// <param name="options">Options determining the matching process.</param> /// <returns>A list of matches</returns> public List <DyntaxaMatchItem> GetMatches(string[] items, MatchSettingsViewModel options) { var list = new List <DyntaxaMatchItem>(); if (options.MatchToType == MatchTaxonToType.TaxonId) { var ids = new List <Int32>(); foreach (var item in items) { Int32 id; if (Int32.TryParse(item, out id)) { ids.Add(id); } } return(this.GetMatches(ids, options)); } else { for (int i = 0; i < items.Count(); i++) { string item = items[i]; if (!((i == items.Count() - 1) && item == "")) { DyntaxaMatchItem matchItem; if (options.ColumnContentAlternative == MatchColumnContentAlternative.NameAndAuthorInSeparateColumns) { string[] stringArray = null; switch (options.ColumnDelimiter) { case MatchTaxonColumnDelimiter.Semicolon: stringArray = item.Split(';'); break; case MatchTaxonColumnDelimiter.Tab: stringArray = item.Split('\t'); break; case MatchTaxonColumnDelimiter.VerticalBar: stringArray = item.Split('|'); break; default: stringArray = item.Split('\t'); break; } if (stringArray.Length > 1) { matchItem = new DyntaxaMatchItem(stringArray[0], stringArray[1]); } else { matchItem = new DyntaxaMatchItem(item); } } else { matchItem = new DyntaxaMatchItem(item); } list.Add(matchItem); } } } return(GetMatches(list, options)); }
/// <summary> /// A method that perform matches of taxon identifiers provided in a list. /// </summary> /// <param name="filePath">Full file name including its path of an excel file including the provided list of taxon identifiers.</param> /// <param name="options">Options determining the matching process.</param> /// <returns>A list of matches.</returns> public List <DyntaxaMatchItem> GetMatches(string filePath, MatchSettingsViewModel options) { string strName; var list = new List <DyntaxaMatchItem>(); //var file = new ExcelFile(filePath, options.IsFirstRowColumnName); var file = new XlsxExcelFile(filePath, options.IsFirstRowColumnName); DataTable table = file.DataTable; if (table.Rows.Count > 0 && table.Columns.Count > 0) { if (options.MatchToType == MatchTaxonToType.TaxonId) { var ids = new List <Int32>(); foreach (DataRow row in table.Rows) { int id; if (Int32.TryParse(row[0].ToString(), out id)) { ids.Add(id); } } list = this.GetMatches(ids, options); } else if (options.MatchToType == MatchTaxonToType.TaxonNameAndAuthor) { if (table.Columns.Count >= 2) { foreach (DataRow row in table.Rows) { string strColumn1 = row[0].ToString(); string strColumn2 = row[1].ToString(); if (string.IsNullOrEmpty(strColumn1)) { strName = strColumn2; } else if (string.IsNullOrEmpty(strColumn2)) { strName = strColumn1; } else { strName = string.Format("{0} {1}", row[0], row[1]).Trim(); } if (!string.IsNullOrEmpty(strName)) { var matchItem = new DyntaxaMatchItem(strName); list.Add(matchItem); } } } else { foreach (DataRow row in table.Rows) { strName = row[0].ToString(); if (!string.IsNullOrEmpty(strName)) { var matchItem = new DyntaxaMatchItem(strName); list.Add(matchItem); } } } } else { foreach (DataRow row in table.Rows) { strName = row[0].ToString(); if (!string.IsNullOrEmpty(strName)) { var matchItem = new DyntaxaMatchItem(strName); list.Add(matchItem); } } } } return(GetMatches(list, options)); }