Skip to content

Commit

Permalink
Update scraping related types
Browse files Browse the repository at this point in the history
  • Loading branch information
rolledback committed Feb 14, 2021
1 parent d8e1e2f commit f3f903e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 52 deletions.
32 changes: 32 additions & 0 deletions LegoSharp/Scraping/Facet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace LegoSharp
{
public class Facet
{
public string id { get; set; }
public string key { get; set; }
public IEnumerable<FacetLabel> labels { get; set; }
}

public struct FacetLabel
{
public string name { get; set; }
public string value { get; set; }
}

public class FacetLabelComparaer : IEqualityComparer<FacetLabel>
{
public bool Equals(FacetLabel a, FacetLabel b)
{
return a.value == b.value && a.name == b.name;
}
public int GetHashCode(FacetLabel t)
{
string code = t.value + "," + t.name;
return code.GetHashCode();
}
}
}
20 changes: 0 additions & 20 deletions LegoSharp/Scraping/FacetLabel.cs

This file was deleted.

14 changes: 7 additions & 7 deletions LegoSharp/Scraping/FacetScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public FacetScraper(IEnumerable<IGraphQuery<GraphQueryResultT>> queriesToScrapeW
}
}

public async Task<ISet<ScrapedFacetLabel>> scrapeFacet(string facetId, string facetKey)
public async Task<ISet<FacetLabel>> scrapeFacet(string facetId, string facetKey)
{
var scrapedFacets = new HashSet<ScrapedFacetLabel>(new ScrapedFacetLabelComparaer());
var scrapedFacets = new HashSet<FacetLabel>(new FacetLabelComparaer());

foreach (var facetQuery in this._facetQueries)
{
Expand All @@ -35,17 +35,17 @@ public async Task<ISet<ScrapedFacetLabel>> scrapeFacet(string facetId, string fa
{
foreach (var label in facet.labels)
{
scrapedFacets.Add(new ScrapedFacetLabel { name = label.name, value = label.value });
scrapedFacets.Add(new FacetLabel { name = label.name, value = label.value });
}
}
}

return scrapedFacets;
}

public async Task<IDictionary<string, ISet<ScrapedFacetLabel>>> scrapeFacets()
public async Task<IDictionary<string, ISet<FacetLabel>>> scrapeFacets()
{
var result = new Dictionary<string, ISet<ScrapedFacetLabel>>();
var result = new Dictionary<string, ISet<FacetLabel>>();

foreach (var facetQuery in this._facetQueries)
{
Expand All @@ -57,11 +57,11 @@ public async Task<ISet<ScrapedFacetLabel>> scrapeFacet(string facetId, string fa
var dictionaryIdx = facet.id + "," + facet.key;
if (!result.ContainsKey(dictionaryIdx))
{
result[dictionaryIdx] = new HashSet<ScrapedFacetLabel>(new ScrapedFacetLabelComparaer());
result[dictionaryIdx] = new HashSet<FacetLabel>(new FacetLabelComparaer());
}
foreach (var label in facet.labels)
{
result[dictionaryIdx].Add(new ScrapedFacetLabel { name = label.name, value = label.value });
result[dictionaryIdx].Add(new FacetLabel { name = label.name, value = label.value });
}
}
}
Expand Down
25 changes: 0 additions & 25 deletions LegoSharp/Scraping/ScrapedFacetLabel.cs

This file was deleted.

0 comments on commit f3f903e

Please sign in to comment.