Initial commit

This commit is contained in:
2022-07-06 21:35:05 +02:00
commit b2494052ff
97220 changed files with 2449256 additions and 0 deletions
@@ -0,0 +1,17 @@
using Autofac.Features.Indexed;
using Gos.ServiceModel.Enums;
namespace Gos.Services.Search.Aggregations
{
public class AggregationProviderFactory : IAggregationProviderFactory
{
private readonly IIndex<AggregationType, IAggregationProvider> providers;
public AggregationProviderFactory(IIndex<AggregationType, IAggregationProvider> providers)
{
this.providers = providers;
}
public IAggregationProvider GetProvider(AggregationType aggregationType) => providers[aggregationType];
}
}
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using Gos.Core.Search.Aggregations;
using Gos.Core.Search.Queries;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
namespace Gos.Services.Search.Aggregations
{
public abstract class BaseAggregationProvider : IAggregationProvider
{
private readonly IAggregatorFactory aggregatorFactory;
protected BaseAggregationProvider(IAggregatorFactory aggregatorFactory)
{
this.aggregatorFactory = aggregatorFactory;
}
public abstract AggregationType Type { get; }
public Aggregation Get<TQuery>(TQuery query)
where TQuery : Query
{
// Run aggregator
var aggregator = aggregatorFactory.GetAggregator(Type);
var items = aggregator.Get(query);
return new Aggregation()
{
Items = GetItems(items),
Type = Type,
};
}
protected abstract List<AggregationItem> GetItems(IDictionary<string, int> items);
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class DiscourseChannelAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public DiscourseChannelAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.DiscourseChannel;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.DiscourseChannels.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join channel in types on id equals channel.Id
orderby item.Value descending, channel.Title
select new AggregationItem
{
Count = item.Value,
Key = channel.Id,
Title = channel.Title,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class DiscourseEventAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public DiscourseEventAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.DiscourseEvent;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.DiscourseEvents.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join @event in types on id equals @event.Id
orderby item.Value descending, @event.Title
select new AggregationItem
{
Count = item.Value,
Key = @event.Id,
Title = @event.Title,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class DiscourseRegionAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public DiscourseRegionAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.DiscourseRegion;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.DiscourseRegions.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join region in types on id equals region.Id
orderby item.Value descending, region.Title
select new AggregationItem
{
Count = item.Value,
Key = region.Id,
Title = region.Title,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class DiscourseTypeAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public DiscourseTypeAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.DiscourseType;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.DiscourseTypes.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join type in types on id equals type.Id
orderby item.Value descending, type.Title
select new AggregationItem
{
Count = item.Value,
Key = type.Id,
Title = type.Title,
}).ToList();
}
}
}
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
namespace Gos.Services.Search.Aggregations
{
public class DiscourseYearAggregationProvider : BaseAggregationProvider
{
public DiscourseYearAggregationProvider(IAggregatorFactory aggregatorFactory)
: base(aggregatorFactory)
{
}
public override AggregationType Type => AggregationType.DiscourseYear;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
return (from item in items
let year = int.Parse(item.Key)
orderby item.Value descending, year
select new AggregationItem()
{
Count = item.Value,
Key = year,
Title = year.ToString(),
}).ToList();
}
}
}
@@ -0,0 +1,11 @@
using Gos.Core.Search.Queries;
using Gos.ServiceModel.Types;
namespace Gos.Services.Search.Aggregations
{
public interface IAggregationProvider
{
Aggregation Get<TQuery>(TQuery query)
where TQuery : Query;
}
}
@@ -0,0 +1,9 @@
using Gos.ServiceModel.Enums;
namespace Gos.Services.Search.Aggregations
{
public interface IAggregationProviderFactory
{
IAggregationProvider GetProvider(AggregationType aggregationType);
}
}
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
namespace Gos.Services.Search.Aggregations
{
public class LemmaAggregationProvider : BaseAggregationProvider
{
public LemmaAggregationProvider(IAggregatorFactory aggregatorFactory)
: base(aggregatorFactory)
{
}
public override AggregationType Type => AggregationType.Lemma;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
return (from item in items
let lemma = item.Key
orderby item.Value descending, lemma
select new AggregationItem()
{
Count = item.Value,
Key = lemma,
Title = lemma,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class PartOfSpeechAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public PartOfSpeechAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.PartOfSpeech;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var partOfSpeeches = dbContext.PartOfSpeeches.Include(p => p.Translations).Where(pp => ids.Contains(pp.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join partOfSpeech in partOfSpeeches on id equals partOfSpeech.Id
orderby item.Value descending, partOfSpeech.Title
select new AggregationItem
{
Count = item.Value,
Key = partOfSpeech.Id,
Title = partOfSpeech.Title,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class SpeakerAgeAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public SpeakerAgeAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.SpeakerAge;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.SpeakerAges.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join age in types on id equals age.Id
orderby item.Value descending, age.Title
select new AggregationItem
{
Count = item.Value,
Key = age.Id,
Title = age.Title,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class SpeakerEducationAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public SpeakerEducationAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.SpeakerEducation;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.SpeakerEducations.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join education in types on id equals education.Id
orderby item.Value descending, education.Title
select new AggregationItem
{
Count = item.Value,
Key = education.Id,
Title = education.Title,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class SpeakerLanguageAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public SpeakerLanguageAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.SpeakerLanguage;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.SpeakerLanguages.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join language in types on id equals language.Id
orderby item.Value descending, language.Title
select new AggregationItem
{
Count = item.Value,
Key = language.Id,
Title = language.Title,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class SpeakerRegionAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public SpeakerRegionAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.SpeakerRegion;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.SpeakerRegions.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join region in types on id equals region.Id
orderby item.Value descending, region.Title
select new AggregationItem
{
Count = item.Value,
Key = region.Id,
Title = region.Title,
}).ToList();
}
}
}
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Search.Aggregations;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using Gos.Services.Framework;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.Search.Aggregations
{
public class SpeakerSexAggregationProvider : BaseAggregationProvider
{
private readonly GosDbContext dbContext;
public SpeakerSexAggregationProvider(IAggregatorFactory aggregatorFactory, GosDbContext dbContext)
: base(aggregatorFactory)
{
this.dbContext = dbContext;
}
public override AggregationType Type => AggregationType.SpeakerSex;
protected override List<AggregationItem> GetItems(IDictionary<string, int> items)
{
var ids = items.Select(b => int.Parse(b.Key)).ToList();
var types = dbContext.SpeakerSexes.Include(e => e.Translations).Where(tt => ids.Contains(tt.Id)).ToList();
return (from item in items
let id = int.Parse(item.Key)
join sex in types on id equals sex.Id
orderby item.Value descending, sex.Title
select new AggregationItem
{
Count = item.Value,
Key = sex.Id,
Title = sex.Title,
}).ToList();
}
}
}
@@ -0,0 +1,22 @@
using Autofac;
using Gos.ServiceModel.Enums;
using MediatR;
namespace Gos.Services.Search.AlternateSearches
{
public class AlternateSearchProviderFactory : IAlternateSearchProviderFactory
{
private readonly ILifetimeScope lifetimeScope;
public AlternateSearchProviderFactory(ILifetimeScope lifetimeScope)
{
this.lifetimeScope = lifetimeScope;
}
public IAlternateSearchProvider<TRequest, TResponse> GetProvider<TRequest, TResponse>(AlternateSearchType type)
where TRequest : IRequest<TResponse>
{
return lifetimeScope.ResolveKeyed<IAlternateSearchProvider<TRequest, TResponse>>(type);
}
}
}
@@ -0,0 +1,157 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gos.Core.Extensions;
using Gos.Core.Search;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Requests.Concordance;
using Gos.ServiceModel.Types;
using Gos.Services.Search.QueryFactories;
using Gos.Services.Services.LemmatizationService;
namespace Gos.Services.Search.AlternateSearches
{
public class ConcordanceLemmasAlternateSearchProvider : IAlternateSearchProvider<ConcordanceSearch, ConcordanceSearchResponse>
{
private readonly ILemmatizationService lemmatizationService;
private readonly IQueryFactory<ConcordanceSearch, ConcordanceQuery> queryFactory;
private readonly ISearchEngine searchEngine;
public AlternateSearchType Type => AlternateSearchType.Lemmas;
public ConcordanceLemmasAlternateSearchProvider(
ILemmatizationService lemmatizationService,
IQueryFactory<ConcordanceSearch, ConcordanceQuery> queryFactory,
ISearchEngine searchEngine)
{
this.lemmatizationService = lemmatizationService;
this.queryFactory = queryFactory;
this.searchEngine = searchEngine;
}
public async Task<AlternateSearch<ConcordanceSearch>> Get(ConcordanceSearch request)
{
// Main word
var lemmas = new List<List<string>>
{
await GetLemmasForWord(request.MainWord),
};
// Words in context
if (!request.WordsInContext.IsNullOrEmpty())
{
foreach (var wordInContext in request.WordsInContext)
{
if (SkipWord(wordInContext))
{
continue;
}
lemmas.Add(await GetLemmasForWord(wordInContext));
}
}
var products = lemmas.CartesianProduct();
var alternateSearch = new AlternateSearch<ConcordanceSearch>()
{
Items = new List<AlternateSearchItem<ConcordanceSearch>>(),
OriginalSearch = GetOriginalSearch(request),
Type = AlternateSearchType.Lemmas,
};
foreach (var product in products)
{
var clone = request.Copy();
// Main word
clone.MainWord.Lemma = product.ElementAt(0);
// Words
if (!clone.WordsInContext.IsNullOrEmpty())
{
for (var i = 0; i < clone.WordsInContext.Count; i++)
{
var wordInContext = clone.WordsInContext[i];
if (SkipWord(wordInContext))
{
continue;
}
clone.WordsInContext[i].Lemma = product.ElementAt(i + 1);
}
}
// Count
var count = await GetCount(clone);
if (count > 0)
{
alternateSearch.Items.Add(
new AlternateSearchItem<ConcordanceSearch>()
{
Count = count,
Search = clone,
Title = GetTitle(clone),
});
}
}
return alternateSearch;
}
private async Task<int> GetCount(ConcordanceSearch search)
{
var query = await queryFactory.GetQuery(search);
var results = searchEngine.Search<ConcordanceQuery, ConcordanceQueryResult>(query);
return (int)results.Total;
}
public async Task<List<string>> GetLemmasForWord(ConcordanceSearchWord word)
{
if (!string.IsNullOrEmpty(word.Form))
{
return await lemmatizationService.GetLemmas(word.Form, false);
}
return new List<string>();
}
private ConcordanceSearch GetOriginalSearch(ConcordanceSearch request)
{
var original = request.Copy();
original.MainWord.Lemma = null;
if (!original.WordsInContext.IsNullOrEmpty())
{
foreach (var wordInContext in original.WordsInContext)
{
wordInContext.Lemma = null;
}
}
return original;
}
private static string GetTitle(ConcordanceSearch search)
{
var sb = new StringBuilder();
sb.Append(search.MainWord.Lemma);
if (!search.WordsInContext.IsNullOrEmpty())
{
foreach (var wordInContext in search.WordsInContext)
{
sb.Append(" ");
sb.Append(wordInContext.Lemma);
}
}
return sb.ToString();
}
private static bool SkipWord(ConcordanceSearchWordInContext wordInContext)
{
return wordInContext.Condition == ConditionType.IsNot || string.IsNullOrEmpty(wordInContext.Form) && string.IsNullOrEmpty(wordInContext.Lemma);
}
}
}
@@ -0,0 +1,15 @@
using System.Threading.Tasks;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Types;
using MediatR;
namespace Gos.Services.Search.AlternateSearches
{
public interface IAlternateSearchProvider<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
AlternateSearchType Type { get; }
Task<AlternateSearch<TRequest>> Get(TRequest request);
}
}
@@ -0,0 +1,11 @@
using Gos.ServiceModel.Enums;
using MediatR;
namespace Gos.Services.Search.AlternateSearches
{
public interface IAlternateSearchProviderFactory
{
IAlternateSearchProvider<TRequest, TResponse> GetProvider<TRequest, TResponse>(AlternateSearchType type)
where TRequest : IRequest<TResponse>;
}
}
@@ -0,0 +1,124 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Gos.Core.Extensions;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Requests.Concordance;
using Gos.Services.Services.LemmatizationService;
using Gos.Services.Services.PartOfSpeechService;
namespace Gos.Services.Search.QueryFactories
{
public abstract class BaseConcordanceQueryFactory
{
private readonly ILemmatizationService lemmatizationService;
private readonly IPartOfSpeechService partOfSpeechService;
protected BaseConcordanceQueryFactory(ILemmatizationService lemmatizationService, IPartOfSpeechService partOfSpeechService)
{
this.lemmatizationService = lemmatizationService;
this.partOfSpeechService = partOfSpeechService;
}
protected async Task<ConcordanceQuery> GetQuery<TRequest, TResponse>(TRequest request)
where TRequest : BaseConcordanceSearch<TResponse>
{
return new ConcordanceQuery
{
MainWord = await GetMainWordQuery(request.MainWord),
WordsInContext = await GetWordsInContextQuery(request.WordsInContext),
}.WithFilters(request);
}
private async Task<ConcordanceQueryMainWord> GetMainWordQuery(ConcordanceSearchMainWord word)
{
return await GetWordQuery<ConcordanceQueryMainWord>(word);
}
private async Task<ConcordanceQueryWordInContext> GetWordInContextQuery(ConcordanceSearchWordInContext wordInContext)
{
var wordQuery = await GetWordQuery<ConcordanceQueryWordInContext>(wordInContext);
wordQuery.Condition = wordInContext.Condition;
wordQuery.DistanceType = wordInContext.DistanceType;
wordQuery.LeftPosition = wordInContext.LeftPosition;
wordQuery.RightPosition = wordInContext.RightPosition;
return wordQuery;
}
private async Task<T> GetWordQuery<T>(ConcordanceSearchWord word)
where T : ConcordanceQueryWord, new()
{
var wordQuery = new T();
if (!string.IsNullOrEmpty(word.ConversationalFormOverride) || !string.IsNullOrEmpty(word.StandardFormOverride))
{
wordQuery.ConversationalForm = word.ConversationalFormOverride;
wordQuery.StandardForm = word.StandardFormOverride;
}
else
{
if (word.TranscriptionType == TranscriptionType.Conversational)
{
wordQuery.ConversationalForm = word.Form;
}
else
{
if (word.FormSearchType == FormSearchType.ExactForm)
{
wordQuery.StandardForm = word.Form;
}
else
{
if (!string.IsNullOrEmpty(word.Lemma))
{
wordQuery.Lemmas = new List<string>()
{
word.Lemma,
};
}
else
{
wordQuery.Lemmas = await lemmatizationService.GetLemmas(word.Form, false);
}
}
}
}
wordQuery.PartOfSpeechCondition = word.PartOfSpeechCondition;
wordQuery.PartOfSpeechId = word.PartOfSpeechId;
if (word.PartOfSpeechId.HasValue && !string.IsNullOrEmpty(word.Msds))
{
// Search by msds from attributes (advanced search)
wordQuery.Msds = await partOfSpeechService.BuildMsds(word.PartOfSpeechId.Value, word.Msds);
}
else if (!string.IsNullOrEmpty(word.Msds))
{
// Search by exact msd (link from list results)
wordQuery.Msds = new List<string>()
{
word.Msds,
};
}
return wordQuery;
}
private async Task<List<ConcordanceQueryWordInContext>> GetWordsInContextQuery(List<ConcordanceSearchWordInContext> wordsInContext)
{
if (wordsInContext.IsNullOrEmpty())
{
return null;
}
var wordQueries = new List<ConcordanceQueryWordInContext>();
foreach (var wordInContext in wordsInContext)
{
var wordQuery = await GetWordInContextQuery(wordInContext);
wordQueries.Add(wordQuery);
}
return wordQueries;
}
}
}
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Gos.Core.Extensions;
using Gos.Core.Search.Queries.List;
using Gos.ServiceModel.Requests.List;
using Gos.Services.Services.PartOfSpeechService;
namespace Gos.Services.Search.QueryFactories
{
public abstract class BaseListQueryFactory
{
private readonly IPartOfSpeechService partOfSpeechService;
protected BaseListQueryFactory(IPartOfSpeechService partOfSpeechService)
{
this.partOfSpeechService = partOfSpeechService;
}
protected async Task<ListQuery> GetQuery<TRequest, TResponse>(TRequest request)
where TRequest : BaseListSearch<TResponse>
{
List<string> msds = null;
if (!request.PartOfSpeechIds.IsNullOrEmpty() && !string.IsNullOrEmpty(request.Msds))
{
msds = await partOfSpeechService.BuildMsds(request.PartOfSpeechIds[0], request.Msds);
}
return new ListQuery()
{
Condition = request.Condition,
ConversationalForm = request.ConversationalForm,
GroupByMsd = request.GroupByMsd,
Lemmas = request.Lemmas,
Msds = msds,
PartOfSpeechIds = request.PartOfSpeechIds,
Query = request.Query,
StandardForm = request.StandardForm,
TranscriptionType = request.TranscriptionType,
}.WithFilters(request);
}
}
}
@@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Requests.Concordance;
using Gos.Services.Services.LemmatizationService;
using Gos.Services.Services.PartOfSpeechService;
namespace Gos.Services.Search.QueryFactories
{
public class ConcordanceDetailsQueryFactory : BaseConcordanceQueryFactory, IQueryFactory<ConcordanceDetails, ConcordanceQuery>
{
public ConcordanceDetailsQueryFactory(ILemmatizationService lemmatizationService, IPartOfSpeechService partOfSpeechService)
: base(lemmatizationService, partOfSpeechService)
{
}
public async Task<ConcordanceQuery> GetQuery(ConcordanceDetails request)
{
var query = await base.GetQuery<ConcordanceDetails, ConcordanceDetailsResponse>(request);
query.From = 0;
query.Size = 0;
return query;
}
}
}
@@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Requests.Concordance;
using Gos.ServiceModel.Requests.Shared;
using Gos.Services.Services.LemmatizationService;
using Gos.Services.Services.PartOfSpeechService;
namespace Gos.Services.Search.QueryFactories
{
public class ConcordanceExportQueryFactory : BaseConcordanceQueryFactory, IQueryFactory<ConcordanceExport, ConcordanceQuery>
{
public ConcordanceExportQueryFactory(ILemmatizationService lemmatizationService, IPartOfSpeechService partOfSpeechService)
: base(lemmatizationService, partOfSpeechService)
{
}
public async Task<ConcordanceQuery> GetQuery(ConcordanceExport request)
{
var query = await base.GetQuery<ConcordanceExport, ExportResponse>(request);
query.From = 0;
query.Size = request.Rows;
query.ReturnRandomRows = request.Type == ConcordanceExportType.RandomRows;
return query;
}
}
}
@@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Requests.Concordance;
using Gos.Services.Services.LemmatizationService;
using Gos.Services.Services.PartOfSpeechService;
namespace Gos.Services.Search.QueryFactories
{
public class ConcordanceSearchQueryFactory : BaseConcordanceQueryFactory, IQueryFactory<ConcordanceSearch, ConcordanceQuery>
{
public ConcordanceSearchQueryFactory(ILemmatizationService lemmatizationService, IPartOfSpeechService partOfSpeechService)
: base(lemmatizationService, partOfSpeechService)
{
}
public async Task<ConcordanceQuery> GetQuery(ConcordanceSearch request)
{
var query = await base.GetQuery<ConcordanceSearch, ConcordanceSearchResponse>(request);
query.From = request.From;
query.Size = request.Size;
return query;
}
}
}
@@ -0,0 +1,11 @@
using System.Threading.Tasks;
using Gos.Core.Search.Queries;
namespace Gos.Services.Search.QueryFactories
{
public interface IQueryFactory<TRequest, TQuery>
where TQuery : Query
{
Task<TQuery> GetQuery(TRequest request);
}
}
@@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Gos.Core.Search.Queries.List;
using Gos.ServiceModel.Requests.List;
using Gos.ServiceModel.Requests.Shared;
using Gos.Services.Services.PartOfSpeechService;
namespace Gos.Services.Search.QueryFactories
{
public class ListExportQueryFactory : BaseListQueryFactory, IQueryFactory<ListExport, ListQuery>
{
public ListExportQueryFactory(IPartOfSpeechService partOfSpeechService)
: base(partOfSpeechService)
{
}
public async Task<ListQuery> GetQuery(ListExport request)
{
var query = await base.GetQuery<ListExport, ExportResponse>(request);
query.From = 0;
query.Size = request.Rows;
return query;
}
}
}
@@ -0,0 +1,23 @@
using System.Threading.Tasks;
using Gos.Core.Search.Queries.List;
using Gos.ServiceModel.Requests.List;
using Gos.Services.Services.PartOfSpeechService;
namespace Gos.Services.Search.QueryFactories
{
public class ListSearchQueryFactory : BaseListQueryFactory, IQueryFactory<ListSearch, ListQuery>
{
public ListSearchQueryFactory(IPartOfSpeechService partOfSpeechService)
: base(partOfSpeechService)
{
}
public async Task<ListQuery> GetQuery(ListSearch request)
{
var query = await base.GetQuery<ListSearch, ListSearchResponse>(request);
query.From = request.From;
query.Size = request.Size;
return query;
}
}
}