private ITaxonRank GetClassificationItem(Result result, TaxonRankType rank) { try { var name = result.Classification .FirstOrDefault(c => string.Compare(c.Rank, rank.MapTaxonRankTypeToTaxonRankString(), true) == 0) .Name; return(new TaxonRankServiceModel { ScientificName = name, Rank = rank }); } catch { return(null); } }
private void ReplaceTreatmentMetaClassificationItem(IDocument document, IEnumerable <ITaxonClassification> classification, string genus, TaxonRankType rank) { if (classification == null) { throw new ArgumentNullException(nameof(classification)); } var matchingHigherTaxa = classification .Select(c => c.Classification.SingleOrDefault(x => x.Rank == rank).ScientificName) .Distinct() .ToList(); var higherTaxaCount = matchingHigherTaxa.Count(); switch (higherTaxaCount) { case 0: this.logger?.Log(LogType.Warning, "Zero matches for rank {0}.", rank); break; case 1: { string taxonName = matchingHigherTaxa.Single(); this.logger?.Log("{0}: {1}\t--\t{2}", genus, rank, taxonName); string xpath = string.Format(TreatmentMetaReplaceXPathTemplate, genus, rank.MapTaxonRankTypeToTaxonRankString()); document.SelectNodes(xpath) .AsParallel() .ForAll(node => { node.InnerText = taxonName; }); } break; default: { this.logger?.Log(LogType.Warning, "Multiple matches for rank {0}:", rank); foreach (string taxonName in matchingHigherTaxa) { this.logger?.Log("{0}: {1}\t--\t{2}", genus, rank, taxonName); } this.logger?.Log(); } break; } }