/// <summary> /// Method that returns a filtered version of this species fact list. The filtering is done on Taxa /// </summary> /// <param name="taxa"></param> /// <returns>A filtered SpeciesFactList</returns> public SpeciesFactList FilterSpeciesFacts(TaxonList taxa) { if (taxa == null) { throw new ArgumentException("TaxonList is null", "taxa"); } SpeciesFactList filteredList = new SpeciesFactList(); //if (originalList.Count > taxa.Count) { foreach (SpeciesFact fact in this) { foreach (Taxon taxon in taxa) { if (fact.Taxon.Id == taxon.Id) { filteredList.Add(fact); break; } } } } return(filteredList); }
/// <summary> /// Method that returns a filtered version of this species fact list. The filtering is done on hosts /// </summary> /// <param name="hosts"></param> /// <returns>A filtered SpeciesFactList</returns> public SpeciesFactList FilterSpeciesFactsHosts(TaxonList hosts) { if (hosts == null) { throw new ArgumentException("TaxonList is null", "hosts"); } SpeciesFactList filteredList = new SpeciesFactList(); //if (originalList.Count > hosts.Count) { foreach (SpeciesFact fact in this) { foreach (Taxon host in hosts) { if (fact.Host.Id == host.Id) { filteredList.Add(fact); break; } } } } return(filteredList); }
private ArtDatabanken.Data.ArtDatabankenService.TaxonList GetTaxa() { if (_taxa.IsNull()) { _taxa = ArtDatabanken.Data.ArtDatabankenService.TaxonManager.GetTaxa(TaxonManagerTest.GetTaxaIds(), TaxonInformationType.Basic); } return(_taxa); }
/// <summary> /// Create a user parameter selection instance. /// </summary> public UserParameterSelection() { _factors = new FactorList(true); _hosts = new TaxonList(true); _individualCategories = new IndividualCategoryList(true); _periods = new PeriodList(true); _references = new ReferenceList(true); _taxa = new TaxonList(true); }
/// <summary> /// Add taxa to the data identifier list. /// Data type is needed to distinguish between taxon and host. /// Default is taxon. /// </summary> /// <param name='taxa'>Taxa.</param> /// <param name='dataType'> /// Data type is needed to distinguish between taxon and host. /// Default is taxon. /// </param> public void AddRange(TaxonList taxa, DataTypeId dataType) { if (taxa.IsNotEmpty()) { foreach (Taxon taxon in taxa) { Add(taxon, dataType); } } }
/// <summary> /// Add taxa to the data identifier list. /// Data type is added to distinguish between taxon and host. /// Default is taxon. /// </summary> /// <param name='taxa'>Taxa.</param> public void AddRange(TaxonList taxa) { if (taxa.IsNotEmpty()) { foreach (Taxon taxon in taxa) { Add(taxon); } } }
public void GetTaxaBySearchString() { ArtDatabanken.Data.ArtDatabankenService.TaxonList taxa = GetTaxa(); ArtDatabanken.Data.ArtDatabankenService.TaxonList subset = taxa.GetTaxaBySearchString("A", StringComparison.CurrentCultureIgnoreCase); Assert.IsNotNull(subset); String firstString = subset[0].ScientificName; ArtDatabanken.Data.ArtDatabankenService.TaxonList subset1 = taxa.GetTaxaBySearchString(firstString, StringComparison.CurrentCultureIgnoreCase); Assert.IsNotNull(subset1); }
/// <summary> /// Get a subset of this taxon list by search string /// </summary> /// <param name="searchString">Search string</param> /// <param name="comparisonType">Type of string comparison</param> /// <returns>A taxon list</returns> public TaxonList GetTaxaBySearchString(String searchString, StringComparison comparisonType) { TaxonList taxa = new TaxonList(); var subset = from Taxon taxon in this where taxon.ScientificName.StartsWith(searchString, comparisonType) orderby taxon.ScientificName ascending select taxon; taxa.AddRange(subset.ToArray()); return(taxa); }
/// <summary> /// Convert a WebTaxon array to a TaxonList. /// </summary> /// <param name="webTaxa">The WebTaxon array.</param> /// <returns>A TaxonList.</returns> public static TaxonList GetTaxa(List <WebTaxon> webTaxa) { TaxonList taxa; // Convert taxon data. taxa = new TaxonList(true); if (webTaxa.IsNotEmpty()) { foreach (WebTaxon webTaxon in webTaxa) { taxa.Add(GetTaxon(webTaxon)); } } return(taxa); }
/// <summary> /// Private constructor. Makes a clone of a UserParameterSelection. /// </summary> /// <param name="userParameterSelection">UserParameterSelection to clone</param> private UserParameterSelection(UserParameterSelection userParameterSelection) { _factors = new FactorList(true); _factors.AddRange(userParameterSelection.Factors); _hosts = new TaxonList(true); _hosts.AddRange(userParameterSelection.Hosts); _individualCategories = new IndividualCategoryList(true); _individualCategories.AddRange(userParameterSelection.IndividualCategories); _periods = new PeriodList(true); _periods.AddRange(userParameterSelection.Periods); _references = new ReferenceList(true); _references.AddRange(userParameterSelection.References); _taxa = new TaxonList(true); _taxa.AddRange(userParameterSelection.Taxa); }
/// <summary> /// Get species facts with species document information. /// </summary> private void GetSpeciesFacts() { UserParameterSelection parameters = new UserParameterSelection(); TaxonList taxa = new TaxonList(); taxa.Add(_taxon); parameters.Taxa = taxa; FactorSearchCriteria criteria = new FactorSearchCriteria(); List <Int32> factorIds = new List <Int32>(); factorIds.Add((Int32)FactorId.SpeciesInformationDocumentGroup); criteria.RestrictSearchToFactorIds = factorIds; criteria.RestrictReturnToScope = ArtDatabanken.Data.WebService.FactorSearchScope.LeafFactors; parameters.Factors = FactorManager.GetFactorsBySearchCriteria(criteria); _speciesFacts = SpeciesFactManager.GetSpeciesFactsByUserParameterSelection(parameters); }
public void SquareBracketOperator() { Int32 taxonIndex; ArtDatabanken.Data.ArtDatabankenService.TaxonList newTaxonList, oldTaxonList; oldTaxonList = GetTaxa(); newTaxonList = new ArtDatabanken.Data.ArtDatabankenService.TaxonList(); for (taxonIndex = 0; taxonIndex < oldTaxonList.Count; taxonIndex++) { newTaxonList.Add(oldTaxonList[oldTaxonList.Count - taxonIndex - 1]); } for (taxonIndex = 0; taxonIndex < oldTaxonList.Count; taxonIndex++) { Assert.AreEqual(newTaxonList[taxonIndex], oldTaxonList[oldTaxonList.Count - taxonIndex - 1]); } }
/// <summary> /// Method that returns a filtered version of this species fact list. The filtering is done on several parameters. /// </summary> /// <param name="individualCategories"></param> /// <param name="periods"></param> /// <param name="hosts"></param> /// <param name="taxa"></param> /// <param name="factors"></param> /// <returns>A filtered SpeciesFactList</returns> public SpeciesFactList FilterSpeciesFacts( IndividualCategoryList individualCategories, PeriodList periods, TaxonList hosts, TaxonList taxa, FactorList factors) { SpeciesFactList filteredList = new SpeciesFactList(); foreach (SpeciesFact fact in this) { bool go = true; if (fact.IndividualCategory != null) { if ((individualCategories != null) && (individualCategories.Count > 0)) { if (!individualCategories.Exists(fact.IndividualCategory)) { go = false; } } } if (go) { if (fact.Period != null) { if ((periods != null) && (periods.Count > 0)) { if (!periods.Exists(fact.Period)) { go = false; } } } } if (go) { if (fact.Host != null) { // For the time being we only accept species facts that dont have a host. go = false; //if ((hosts != null) && (hosts.Count > 0)) //{ // if (!hosts.Exists(fact.Host)) // go = false; //} } } if (go) { if (fact.Taxon != null) { if ((taxa != null) && (taxa.Count > 0)) { if (!taxa.Exists(fact.Taxon)) { go = false; } } } } if (go) { if (fact.Factor != null) { if ((factors != null) && (factors.Count > 0)) { if (!factors.Exists(fact.Factor)) { go = false; } } } } if (go) { filteredList.Add(fact); } } return(filteredList); }
public TaxonListTest() { _taxa = null; }
/// <summary> /// Get string with taxonomic information. /// </summary> /// <returns>String with taxonomic information.</returns> private String GetAutomaticTaxonomicString() { StringBuilder text; if (_taxonomicParagraphSpeciesFact.IsNotNull() && (_taxonomicParagraphSpeciesFact.Quality.Id == (Int32)SpeciesFactQualityId.VerryGood) && _taxonomicParagraphSpeciesFact.Field5.HasValue) { return(_taxonomicParagraphSpeciesFact.Field5.StringValue); } text = new StringBuilder(); if (_taxon.IsNotNull()) { _italicStringsInAutomaticTaxonomicParagraph.Clear(); TaxonSearchCriteria criteria = new TaxonSearchCriteria(); List <Int32> taxonIds = new List <Int32>(); taxonIds.Add(_taxon.Id); criteria.RestrictSearchToTaxonIds = taxonIds; criteria.RestrictReturnToScope = WebService.TaxonSearchScope.AllParentTaxa; TaxonList parentTaxa = TaxonManager.GetTaxaBySearchCriteria(criteria); TaxonList suitableParents = new TaxonList(); foreach (Taxon parent in parentTaxa) { if ((parent.TaxonType.Id == (Int32)(TaxonTypeId.Kingdom)) || (parent.TaxonType.Id == (Int32)(TaxonTypeId.Phylum)) || (parent.TaxonType.Id == (Int32)(TaxonTypeId.Class)) || (parent.TaxonType.Id == (Int32)(TaxonTypeId.Order)) || (parent.TaxonType.Id == (Int32)(TaxonTypeId.Family))) { if (!(parent.Id == (Int32)TaxonId.Dummy)) { suitableParents.Add(parent); } } } Int32 startFromIndex = suitableParents.Count - 3; if (startFromIndex < 0) { startFromIndex = 0; } for (Int32 index = startFromIndex; index < suitableParents.Count; index++) { if (text.ToString() != String.Empty) { text.Append(", "); } text.Append(suitableParents[index].TaxonType.Label + " "); text.Append(suitableParents[index].ScientificName); //Eventuellt ska denna kodrad tas bort (förslag från Tomas Hallingbäck): Överordnade taxa bör ej vara kursiverade //Enligt artexperternas diskussion 2010-03-04 ska överordnade vetenskapliga taxonnamn ej kursiveras! //_italicStringsInAutomaticTaxonomicParagraph.Add(suitableParents[index].ScientificName); if (suitableParents[index].CommonName.IsNotEmpty()) { text.Append(" (" + suitableParents[index].CommonName + ")"); } } if (text.ToString() != String.Empty) { text.Append(", "); } text.Append(_taxon.ScientificNameAndAuthor); _italicStringsInAutomaticTaxonomicParagraph.Add(_taxon.ScientificName); TaxonNameList Synonyms = new TaxonNameList(); foreach (TaxonName name in _taxon.TaxonNames) { if ((name.TaxonNameType.Id == 0) && (name.TaxonNameUseType.Id == 0) && (!name.IsRecommended) && (name.Name != _taxon.ScientificName)) { _italicStringsInAutomaticTaxonomicParagraph.Add(name.Name); Synonyms.Add(name); } } if (Synonyms.Count > 0) { text.Append(". Syn. "); for (Int32 itemIndex = 0; itemIndex < Synonyms.Count; itemIndex++) { if (itemIndex > 0) { if (itemIndex == Synonyms.Count - 1) { text.Append(" och "); } else { text.Append(", "); } } text.Append(Synonyms[itemIndex].Name); if (Synonyms[itemIndex].Author.IsNotEmpty()) { text.Append(" " + Synonyms[itemIndex].Author); } } } if (text.ToString() != String.Empty) { text.Append(". "); } } String cleanText = text.ToString().Replace("..", "."); return(cleanText); }