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,123 @@
using System.Reflection;
using Autofac;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Requests.Concordance;
using Gos.Services.Framework;
using Gos.Services.Framework.ConcordanceBuilder;
using Gos.Services.Framework.Decorators;
using Gos.Services.Framework.Fragments;
using Gos.Services.Search.Aggregations;
using Gos.Services.Search.AlternateSearches;
using Gos.Services.Search.QueryFactories;
using Gos.Services.Services.LemmatizationService;
using Gos.Services.Services.PartOfSpeechService;
using Gos.Services.Services.QueryParser;
using Gos.Services.Services.StatementService;
using MediatR;
using Module = Autofac.Module;
namespace Gos.Services.CompositionRoot
{
public class ServicesModule : Module
{
private Assembly ServicesAssembly => GetType().Assembly;
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
RegisterDatabase(builder);
RegisterRequestHandlers(builder);
RegisterServices(builder);
RegisterFramework(builder);
RegisterSearch(builder);
}
private static void RegisterDatabase(ContainerBuilder builder)
{
builder.RegisterType<GosDbContext>().InstancePerLifetimeScope();
}
private static void RegisterFramework(ContainerBuilder builder)
{
// Fragment parsers
builder.RegisterType<FragmentParserFactory>().As<IFragmentParserFactory>().SingleInstance();
builder.RegisterType<CharacterFragmentParser>().Keyed<IFragmentParser>(FragmentType.Character).SingleInstance();
builder.RegisterType<CorrectedWordFragmentParser>().Keyed<IFragmentParser>(FragmentType.CorrectedWord).SingleInstance();
builder.RegisterType<CorrectionFragmentParser>().Keyed<IFragmentParser>(FragmentType.Correction).SingleInstance();
builder.RegisterType<NameFragmentParser>().Keyed<IFragmentParser>(FragmentType.Name).SingleInstance();
builder.RegisterType<SegmentFragmentParser>().Keyed<IFragmentParser>(FragmentType.Segment).SingleInstance();
builder.RegisterType<UnclearWordFragmentParser>().Keyed<IFragmentParser>(FragmentType.Unclear).SingleInstance();
builder.RegisterType<VocalFragmentParser>().Keyed<IFragmentParser>(FragmentType.Vocal).SingleInstance();
builder.RegisterType<WordFragmentParser>().Keyed<IFragmentParser>(FragmentType.Word).SingleInstance();
builder.RegisterType<IncidentFragmentParser>().Keyed<IFragmentParser>(FragmentType.Incident).SingleInstance();
builder.RegisterType<KinesicFragmentParser>().Keyed<IFragmentParser>(FragmentType.Kinesic).SingleInstance();
builder.RegisterType<PauseFragmentParser>().Keyed<IFragmentParser>(FragmentType.Pause).SingleInstance();
builder.RegisterType<ForeignFragmentParser>().Keyed<IFragmentParser>(FragmentType.Foreign).SingleInstance();
builder.RegisterType<GapFragmentParser>().Keyed<IFragmentParser>(FragmentType.Gap).SingleInstance();
// Concordance builder
builder.RegisterType<ConcordanceBuilder>().As<IConcordanceBuilder>().SingleInstance();
}
private static void RegisterServices(ContainerBuilder builder)
{
builder.RegisterType<LemmatizationService>().As<ILemmatizationService>().InstancePerLifetimeScope();
builder.RegisterType<QueryParser>().As<IQueryParser>().SingleInstance();
builder.RegisterType<PartOfSpeechService>().As<IPartOfSpeechService>().InstancePerLifetimeScope();
builder.RegisterType<CacheWarmUp>().InstancePerLifetimeScope();
builder.RegisterType<StatementService>().As<IStatementService>().InstancePerLifetimeScope();
}
private void RegisterRequestHandlers(ContainerBuilder builder)
{
// Mediatr infrastructure
builder.RegisterType<Mediator>().As<IMediator>().InstancePerLifetimeScope();
builder.Register<ServiceFactory>(
context =>
{
var c = context.Resolve<IComponentContext>();
return t => c.Resolve(t);
});
// Request handlers
builder.RegisterAssemblyTypes(ServicesAssembly).AsClosedTypesOf(typeof(IRequestHandler<>)).AsImplementedInterfaces();
builder.RegisterAssemblyTypes(ServicesAssembly).AsClosedTypesOf(typeof(IRequestHandler<,>)).AsImplementedInterfaces();
// Decorators
builder.RegisterGenericDecorator(typeof(ConcordanceSearchDecorator<,>), typeof(IRequestHandler<,>));
builder.RegisterGenericDecorator(typeof(AuditLogDecorator<,>), typeof(IRequestHandler<,>));
}
private void RegisterSearch(ContainerBuilder builder)
{
// Query factories
builder.RegisterAssemblyTypes(ServicesAssembly).AsClosedTypesOf(typeof(IQueryFactory<,>)).AsImplementedInterfaces().InstancePerLifetimeScope();
// Aggregations
builder.RegisterType<AggregationProviderFactory>().As<IAggregationProviderFactory>().InstancePerLifetimeScope();
builder.RegisterType<DiscourseChannelAggregationProvider>()
.Keyed<IAggregationProvider>(AggregationType.DiscourseChannel)
.InstancePerLifetimeScope();
builder.RegisterType<DiscourseEventAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.DiscourseEvent).InstancePerLifetimeScope();
builder.RegisterType<DiscourseRegionAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.DiscourseRegion).InstancePerLifetimeScope();
builder.RegisterType<DiscourseTypeAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.DiscourseType).InstancePerLifetimeScope();
builder.RegisterType<DiscourseYearAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.DiscourseYear).InstancePerLifetimeScope();
builder.RegisterType<SpeakerAgeAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.SpeakerAge).InstancePerLifetimeScope();
builder.RegisterType<SpeakerEducationAggregationProvider>()
.Keyed<IAggregationProvider>(AggregationType.SpeakerEducation)
.InstancePerLifetimeScope();
builder.RegisterType<SpeakerLanguageAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.SpeakerLanguage).InstancePerLifetimeScope();
builder.RegisterType<SpeakerRegionAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.SpeakerRegion).InstancePerLifetimeScope();
builder.RegisterType<SpeakerSexAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.SpeakerSex).InstancePerLifetimeScope();
builder.RegisterType<PartOfSpeechAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.PartOfSpeech).InstancePerLifetimeScope();
builder.RegisterType<LemmaAggregationProvider>().Keyed<IAggregationProvider>(AggregationType.Lemma).InstancePerLifetimeScope();
// Alternate searches
builder.RegisterType<AlternateSearchProviderFactory>().As<IAlternateSearchProviderFactory>().InstancePerLifetimeScope();
builder.RegisterType<ConcordanceLemmasAlternateSearchProvider>()
.Keyed<IAlternateSearchProvider<ConcordanceSearch, ConcordanceSearchResponse>>(AlternateSearchType.Lemmas)
.InstancePerLifetimeScope();
}
}
}
@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Extensions;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Requests.Concordance;
namespace Gos.Services.Extensions
{
public static class HighligterExtensions
{
public static List<ConcordanceToken> Highlight(this List<ConcordanceToken> tokens, ConcordanceQuery query, int statementOrder, int tokenOrder)
{
var centerIndex = tokens.FindIndex(t => t.StatementOrder == statementOrder && t.TokenOrder == tokenOrder);
if (centerIndex != -1)
{
tokens.Highlight(query, centerIndex);
}
return tokens;
}
public static List<ConcordanceToken> Highlight(this List<ConcordanceToken> tokens, ConcordanceQuery query, int centerTokenIndex)
{
var wordsInContextIndexes = query.WordsInContext.IsNullOrEmpty()
? new HashSet<int>()
: GetWordsInContextIndexes(tokens, query, centerTokenIndex).ToHashSet();
for (var i = 0; i < tokens.Count; i++)
{
// Center word
if (i == centerTokenIndex)
{
tokens[i].IsCenterMatch = true;
}
// Words in context
if (wordsInContextIndexes.Contains(i))
{
tokens[i].IsWordInContextMatch = true;
}
}
return tokens;
}
private static bool CheckCandidateToken(List<ConcordanceToken> tokens, ConcordanceQuery query, int centerTokenIndex, int candidateTokenIndex)
{
foreach (var wordInContext in query.WordsInContext)
{
// Try to find candidates only on positive criteria
if (wordInContext.Condition != ConditionType.Is)
{
continue;
}
// Check positions
if (wordInContext.DistanceType == DistanceType.Position)
{
if (centerTokenIndex - wordInContext.LeftPosition != candidateTokenIndex &&
centerTokenIndex + wordInContext.RightPosition != candidateTokenIndex)
{
continue;
}
}
else if (wordInContext.DistanceType == DistanceType.Distance)
{
var leftIndex = Math.Max(0, centerTokenIndex - wordInContext.LeftPosition);
var rightIndex = Math.Min(tokens.Count, centerTokenIndex + wordInContext.RightPosition);
if (candidateTokenIndex < leftIndex && candidateTokenIndex > rightIndex)
{
continue;
}
}
// Check candidate
var candidate = tokens[candidateTokenIndex];
if (!wordInContext.ConversationalForm.IsNullOrEmpty())
{
if (!candidate.ConversationalForm.Equals(wordInContext.ConversationalForm, StringComparison.OrdinalIgnoreCase))
{
continue;
}
}
if (!wordInContext.StandardForm.IsNullOrEmpty())
{
if (!candidate.StandardForm.Equals(wordInContext.StandardForm, StringComparison.OrdinalIgnoreCase))
{
continue;
}
}
if (!wordInContext.Lemmas.IsNullOrEmpty())
{
if (!wordInContext.Lemmas.Any(l => l.Equals(candidate.Lemma, StringComparison.OrdinalIgnoreCase)))
{
continue;
}
}
return true;
}
return false;
}
private static IEnumerable<int> GetWordsInContextIndexes(List<ConcordanceToken> tokens, ConcordanceQuery query, int centerTokenIndex)
{
// Check up to 10 tokens (in both directions) for possible matches
var leftIndex = Math.Max(0, centerTokenIndex - 10);
var rightIndex = Math.Min(tokens.Count, centerTokenIndex + 10);
for (var i = leftIndex; i < rightIndex; i++)
{
if (i != centerTokenIndex && CheckCandidateToken(tokens, query, centerTokenIndex, i))
{
yield return i;
}
}
}
}
}
+52
View File
@@ -0,0 +1,52 @@
using System.Linq;
using Gos.Core;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
namespace Gos.Services.Framework
{
public class CacheWarmUp
{
private readonly GosDbContext dbContext;
private readonly IMemoryCache memoryCache;
public CacheWarmUp(GosDbContext dbContext, IMemoryCache memoryCache)
{
this.dbContext = dbContext;
this.memoryCache = memoryCache;
}
public void WarmUp()
{
InitializePartOfSpeeches();
InitializeMsds();
}
private void InitializePartOfSpeeches()
{
// Get part of speeches
var partOfSpeeches = dbContext.PartOfSpeeches.Include(p => p.Translations).ToList();
// Cache individual msd by code
foreach (var partOfSpeech in partOfSpeeches)
{
memoryCache.Set(Cache.CacheKeys.PartOfSpeech.ByCode(partOfSpeech.Code), partOfSpeech, Cache.Duration.Long);
}
}
private void InitializeMsds()
{
// Get msds
var msds = dbContext.Msds.Include(m => m.Translations).ToList();
// Cache all msds
memoryCache.Set(Cache.CacheKeys.Msd.All(), msds, Cache.Duration.Long);
// Cache individual msd by code
foreach (var msd in msds)
{
memoryCache.Set(Cache.CacheKeys.Msd.ByCode(msd.Code), msd, Cache.Duration.Long);
}
}
}
}
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.ConcordanceBuilder
{
public class ConcordanceBuilder : IConcordanceBuilder
{
public List<Concordance> GetConcordances(Statement statement, List<Token> tokens)
{
// Get window size (max 10)
var windowSize = Math.Min(tokens.Count - 1, 10);
// Create list of tokens with positions
var tokensIdx = tokens.Select((t, i) => new KeyValuePair<int, Token>(i, t)).ToList();
// Get tokens which will appear in current concordance
List<KeyValuePair<int, Token>> concordanceTokens;
var concordances = new List<Concordance>();
while ((concordanceTokens = tokensIdx.Where(x => x.Key >= -windowSize && x.Key <= windowSize).ToList().OrderBy(x => x.Key).ToList()).Any())
{
if (concordanceTokens.Last().Key < 0)
{
break;
}
var concordance = new Concordance()
{
Statement = statement,
};
// Loop through tokens and set it in the position
foreach (var concordanceToken in concordanceTokens)
{
concordance.SetToken(concordanceToken.Value, concordanceToken.Key);
}
concordances.Add(concordance);
// Decrease indexes of tokens (shift tokens to left, relative to window size)
tokensIdx = tokensIdx.Select(x => new KeyValuePair<int, Token>(x.Key - 1, x.Value)).ToList();
}
return concordances;
}
}
}
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Gos.Core.Entities;
using Gos.Core.Model;
namespace Gos.Services.Framework.ConcordanceBuilder
{
public interface IConcordanceBuilder
{
List<Concordance> GetConcordances(Statement statement, List<Token> tokens);
}
}
@@ -0,0 +1,65 @@
using System;
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Gos.Core.Entities;
using Gos.Core.Interfaces;
using MediatR;
namespace Gos.Services.Framework.Decorators
{
public class AuditLogDecorator<TRequest, TResponse> : IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly GosDbContext dbContext;
private readonly IRequestHandler<TRequest, TResponse> decorated;
private readonly ISessionIdResolver sessionIdResolver;
private readonly ITraceIdentifierResolver traceIdentifierResolver;
public AuditLogDecorator(
GosDbContext dbContext,
IRequestHandler<TRequest, TResponse> decorated,
ISessionIdResolver sessionIdResolver,
ITraceIdentifierResolver traceIdentifierResolver)
{
this.dbContext = dbContext;
this.decorated = decorated;
this.sessionIdResolver = sessionIdResolver;
this.traceIdentifierResolver = traceIdentifierResolver;
}
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken)
{
var startDate = DateTime.UtcNow;
var timer = Stopwatch.StartNew();
var response = await decorated.Handle(request, cancellationToken);
timer.Stop();
var endDate = DateTime.UtcNow;
var auditLog = new AuditLog()
{
StartDate = startDate,
EndDate = endDate,
DurationMs = timer.ElapsedMilliseconds,
Message = SerializeRequest(request),
ObjectType = request.GetType().ToString(),
SessionId = sessionIdResolver.Resolve(),
TraceIdentifier = traceIdentifierResolver.Resolve(),
};
await dbContext.AuditLogs.AddAsync(auditLog, cancellationToken);
await dbContext.SaveChangesAsync(cancellationToken);
return response;
}
private static string SerializeRequest(TRequest request)
{
var options = new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
};
return JsonSerializer.Serialize(request, options);
}
}
}
@@ -0,0 +1,36 @@
using System.Threading;
using System.Threading.Tasks;
using Gos.ServiceModel.Requests.Concordance;
using Gos.Services.Services.QueryParser;
using MediatR;
namespace Gos.Services.Framework.Decorators
{
public class ConcordanceSearchDecorator<TRequest, TResponse> : IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IRequestHandler<TRequest, TResponse> decorated;
private readonly IQueryParser queryParser;
public ConcordanceSearchDecorator(IRequestHandler<TRequest, TResponse> decorated, IQueryParser queryParser)
{
this.decorated = decorated;
this.queryParser = queryParser;
}
public Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken)
{
if (request is BaseConcordanceSearch<TResponse> search)
{
if (!string.IsNullOrEmpty(search.Query))
{
var parsed = queryParser.Parse(search.Query, search.TranscriptionType);
search.MainWord = parsed.mainWord;
search.WordsInContext = parsed.wordsInContext;
}
}
return decorated.Handle(request, cancellationToken);
}
}
}
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public abstract class BaseContainerParser : IFragmentParser
{
protected readonly IFragmentParserFactory ParserFactory;
protected BaseContainerParser(IFragmentParserFactory parserFactory)
{
ParserFactory = parserFactory;
}
public virtual IEnumerable<Token> GetTokens(XElement element)
{
var result = new List<Token>();
foreach (var el in element.Elements())
{
if (!IsChildAllowed(el.Name))
{
throw new Exception($"Child {el.Name} is not allowed under {element.Name}!");
}
var parser = GetParser(el.Name);
var tokens = parser.GetTokens(el);
result.AddRange(tokens);
}
return result;
}
protected virtual IFragmentParser GetParser(XName name)
{
return ParserFactory.GetParser(name);
}
protected virtual bool IsChildAllowed(XName name)
{
return true;
}
}
}
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class CharacterFragmentParser : IFragmentParser
{
public IEnumerable<Token> GetTokens(XElement element)
{
var character = element.Value;
yield return new Token(TokenType.Character).WithConversationForm(character)
.WithStandardForm(character)
.WithLemma(character)
.WithMsd(element.Attribute("ana").Value);
}
}
}
@@ -0,0 +1,25 @@
using System.Xml.Linq;
namespace Gos.Services.Framework.Fragments
{
public class CorrectedWordFragmentParser : WordFragmentParser
{
protected override string GetConversationalForm(XElement wordEl)
{
var conversational = base.GetConversationalForm(wordEl);
return $"{conversational}()";
}
protected override string GetStandardForm(XElement wordEl)
{
var standard = base.GetStandardForm(wordEl);
return $"{standard}()";
}
protected override string GetLemma(XElement wordEl)
{
var lemma = base.GetLemma(wordEl);
return $"{lemma}()";
}
}
}
@@ -0,0 +1,28 @@
using System.Xml.Linq;
using Gos.Core;
namespace Gos.Services.Framework.Fragments
{
public class CorrectionFragmentParser : BaseContainerParser
{
public CorrectionFragmentParser(IFragmentParserFactory parserFactory)
: base(parserFactory)
{
}
protected override bool IsChildAllowed(XName name)
{
return name == Constants.TeiNs + "w";
}
protected override IFragmentParser GetParser(XName name)
{
if (name == Constants.TeiNs + "w")
{
return ParserFactory.GetParser(FragmentType.CorrectedWord);
}
return base.GetParser(name);
}
}
}
@@ -0,0 +1,13 @@
using System;
using System.Linq;
namespace Gos.Services.Framework.Fragments
{
public class ForeignFragmentParser : BaseContainerParser
{
public ForeignFragmentParser(IFragmentParserFactory parserFactory)
: base(parserFactory)
{
}
}
}
@@ -0,0 +1,69 @@
using System;
using System.Xml.Linq;
using Autofac.Features.Indexed;
using Gos.Core;
namespace Gos.Services.Framework.Fragments
{
public class FragmentParserFactory : IFragmentParserFactory
{
private readonly IIndex<FragmentType, IFragmentParser> parsers;
public FragmentParserFactory(IIndex<FragmentType, IFragmentParser> parsers)
{
this.parsers = parsers;
}
public IFragmentParser GetParser(FragmentType fragmentType) => parsers[fragmentType];
public IFragmentParser GetParser(XName elementName)
{
if (elementName == Constants.TeiNs + "w")
{
return parsers[FragmentType.Word];
}
if (elementName == Constants.TeiNs + "pc")
{
return parsers[FragmentType.Character];
}
if (elementName == Constants.TeiNs + "name")
{
return parsers[FragmentType.Name];
}
if (elementName == Constants.TeiNs + "pause")
{
return parsers[FragmentType.Pause];
}
if (elementName == Constants.TeiNs + "vocal")
{
return parsers[FragmentType.Vocal];
}
if (elementName == Constants.TeiNs + "incident")
{
return parsers[FragmentType.Incident];
}
if (elementName == Constants.TeiNs + "gap")
{
return parsers[FragmentType.Gap];
}
if (elementName == Constants.TeiNs + "del")
{
return parsers[FragmentType.Correction];
}
if (elementName == Constants.TeiNs + "foreign")
{
return parsers[FragmentType.Foreign];
}
throw new Exception($"Parser for element {elementName} not found!");
}
}
}
@@ -0,0 +1,19 @@
namespace Gos.Services.Framework.Fragments
{
public enum FragmentType
{
Word,
Character,
Name,
Vocal,
Correction,
CorrectedWord,
Unclear,
Segment,
Incident,
Kinesic,
Pause,
Foreign,
Gap,
}
}
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Gos.Core;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class GapFragmentParser : IFragmentParser
{
public IEnumerable<Token> GetTokens(XElement element)
{
if (element.Attribute("reason").Value == "unclear")
{
return GetUnclear();
}
if (element.Attribute("reason").Value == "anon")
{
return GetAnon(element);
}
throw new Exception($"Unknown gap reason {element.Attribute("reason").Value}!");
}
private IEnumerable<Token> GetAnon(XElement element)
{
var tokens = new List<Token>();
var descEl = element.Element(Constants.TeiNs + "desc");
if (descEl != null)
{
var desc = descEl.Value;
tokens.Add(new Token(TokenType.Word).WithConversationForm(desc).WithStandardForm(desc).WithLemma(desc).WithMsd("mte:Xp"));
}
return tokens;
}
private IEnumerable<Token> GetUnclear()
{
yield return new Token(TokenType.Word).WithConversationForm("[nerazumljivo]")
.WithStandardForm("[nerazumljivo]")
.WithLemma("[nerazumljivo]")
.WithMsd("mte:Cc");
}
}
}
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
namespace Gos.Services.Framework.Fragments
{
public interface IFragmentParser
{
IEnumerable<Token> GetTokens(XElement element);
}
}
@@ -0,0 +1,11 @@
using System.Xml.Linq;
namespace Gos.Services.Framework.Fragments
{
public interface IFragmentParserFactory
{
IFragmentParser GetParser(FragmentType fragmentType);
IFragmentParser GetParser(XName elementName);
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class IncidentFragmentParser : IFragmentParser
{
public IEnumerable<Token> GetTokens(XElement element)
{
if (element.Attribute("type")?.Value == "sound")
{
yield return new Token(TokenType.Word).WithConversationForm("[zvok]").WithStandardForm("[zvok]").WithLemma("[zvok]").WithMsd("mte:Xt");
}
else
{
throw new Exception($"Unknown incident type {element.Attribute("type")?.Value}!");
}
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class KinesicFragmentParser : IFragmentParser
{
public IEnumerable<Token> GetTokens(XElement element)
{
if (element.Attribute("type")?.Value == "applause")
{
yield return new Token(TokenType.Word).WithConversationForm("[aplavz]").WithStandardForm("[aplavz]").WithLemma("[aplavz]").WithMsd("mte:Xt");
}
else
{
throw new Exception($"Unknown kinesic type {element.Attribute("type")?.Value}!");
}
}
}
}
@@ -0,0 +1,18 @@
using System.Xml.Linq;
using Gos.Core;
namespace Gos.Services.Framework.Fragments
{
public class NameFragmentParser : BaseContainerParser
{
public NameFragmentParser(IFragmentParserFactory parserFactory)
: base(parserFactory)
{
}
protected override bool IsChildAllowed(XName name)
{
return name == Constants.TeiNs + "gap" || name == Constants.TeiNs + "w";
}
}
}
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class PauseFragmentParser : IFragmentParser
{
public IEnumerable<Token> GetTokens(XElement element)
{
yield return new Token(TokenType.Word).WithConversationForm("[premor]").WithStandardForm("[premor]").WithLemma("[premor]").WithMsd("mte:Xt");
}
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class SegmentFragmentParser : BaseContainerParser
{
public SegmentFragmentParser(IFragmentParserFactory parserFactory)
: base(parserFactory)
{
}
public override IEnumerable<Token> GetTokens(XElement element)
{
try
{
return base.GetTokens(element);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
}
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class UnclearWordFragmentParser : IFragmentParser
{
public IEnumerable<Token> GetTokens(XElement element)
{
yield return new Token(TokenType.Word).WithConversationForm("[nerazumljivo]")
.WithStandardForm("[nerazumljivo]")
.WithLemma("[nerazumljivo]")
.WithMsd("mte:Cc");
}
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class VocalFragmentParser : IFragmentParser
{
public IEnumerable<Token> GetTokens(XElement element)
{
var type = element.Attribute("type")?.Value switch
{
"laughter" => "[smeh]",
"voice" => "[glas]",
_ => throw new Exception($"Unknown vocal type {element.Attribute("type")?.Value}!"),
};
yield return new Token(TokenType.Word).WithConversationForm(type).WithStandardForm(type).WithLemma(type).WithMsd("mte:Xt");
}
}
}
@@ -0,0 +1,77 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Xml.Linq;
using Gos.Core;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
namespace Gos.Services.Framework.Fragments
{
public class WordFragmentParser : IFragmentParser
{
public IEnumerable<Token> GetTokens(XElement element)
{
var result = new List<Token>();
var subWords = element.Elements(Constants.TeiNs + "w").ToList();
if (subWords.Count > 0)
{
for (int i = 0; i < subWords.Count; i++)
{
var token = new Token(TokenType.Word);
if (element.Attribute("norm") != null)
{
// Standard form has one word, conversational form has multiple words
token.WithConversationForm(GetConversationalForm(subWords[i]));
if (i == 0)
{
token.WithStandardForm(GetStandardForm(element)).WithLemma(GetLemma(element)).WithMsd(GetMsd(element));
}
}
else
{
// Standard form has multiple word, conversational form has one word
token.WithStandardForm(GetStandardForm(subWords[i])).WithLemma(GetLemma(subWords[i])).WithMsd(GetMsd(subWords[i]));
if (i == 0)
{
token.WithConversationForm(GetConversationalForm(element));
}
}
result.Add(token);
}
}
else
{
var token = new Token(TokenType.Word).WithConversationForm(GetConversationalForm(element))
.WithStandardForm(GetStandardForm(element))
.WithLemma(GetLemma(element))
.WithMsd(GetMsd(element));
result.Add(token);
}
return result;
}
protected virtual string GetConversationalForm(XElement wordEl)
{
return wordEl.Value;
}
protected virtual string GetStandardForm(XElement wordEl)
{
return wordEl.Attribute("norm")?.Value ?? wordEl.Value;
}
protected virtual string GetLemma(XElement wordEl)
{
return wordEl.Attribute("lemma")?.Value;
}
protected virtual string GetMsd(XElement wordEl)
{
return wordEl.Attribute("ana")?.Value;
}
}
}
+108
View File
@@ -0,0 +1,108 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Gos.Core;
using Gos.Core.Entities;
using Gos.Services.Framework.SeedData;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace Gos.Services.Framework
{
public class GosDbContext : DbContext
{
private readonly IConfiguration configuration;
public GosDbContext(IConfiguration configuration)
{
this.configuration = configuration;
}
public DbSet<AuditLog> AuditLogs { get; set; }
public DbSet<CorpusCounter> CorpusCounters { get; set; }
public DbSet<CorpusForm> CorpusForms { get; set; }
public DbSet<DiscourseChannel> DiscourseChannels { get; set; }
public DbSet<DiscourseEvent> DiscourseEvents { get; set; }
public DbSet<DiscourseRegion> DiscourseRegions { get; set; }
public DbSet<Discourse> Discourses { get; set; }
public DbSet<DiscourseType> DiscourseTypes { get; set; }
public DbSet<Msd> Msds { get; set; }
public DbSet<PartOfSpeech> PartOfSpeeches { get; set; }
public DbSet<Segment> Segments { get; set; }
public DbSet<SpeakerAge> SpeakerAges { get; set; }
public DbSet<SpeakerEducation> SpeakerEducations { get; set; }
public DbSet<SpeakerLanguage> SpeakerLanguages { get; set; }
public DbSet<SpeakerRegion> SpeakerRegions { get; set; }
public DbSet<Speaker> Speakers { get; set; }
public DbSet<SpeakerSex> SpeakerSexes { get; set; }
public DbSet<Statement> Statements { get; set; }
public DbSet<Token> Tokens { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
var connectionString = configuration[ConfigurationKey.Database.ConnectionString];
optionsBuilder.UseNpgsql(connectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Setup entities for localization
modelBuilder.Entity<DiscourseChannel>().Ignore(x => x.Title);
modelBuilder.Entity<DiscourseEvent>().Ignore(x => x.Title);
modelBuilder.Entity<DiscourseRegion>().Ignore(x => x.ShortTitle).Ignore(x => x.Title);
modelBuilder.Entity<DiscourseType>().Ignore(x => x.ShortTitle).Ignore(x => x.Title);
modelBuilder.Entity<Msd>().Ignore(x => x.Title);
modelBuilder.Entity<PartOfSpeech>().Ignore(x => x.Title);
modelBuilder.Entity<PartOfSpeechAttribute>().Ignore(x => x.Title);
modelBuilder.Entity<PartOfSpeechAttributeValue>().Ignore(x => x.Title);
modelBuilder.Entity<SpeakerAge>().Ignore(x => x.Title);
modelBuilder.Entity<SpeakerEducation>().Ignore(x => x.Title);
modelBuilder.Entity<SpeakerLanguage>().Ignore(x => x.Title);
modelBuilder.Entity<SpeakerRegion>().Ignore(x => x.ShortTitle).Ignore(x => x.Title);
modelBuilder.Entity<SpeakerSex>().Ignore(x => x.Title);
}
public async Task SeedDataAsync()
{
async Task SeedSingle<TEntity>(DbSet<TEntity> dbSet, IEnumerable<TEntity> entities)
where TEntity : class
{
dbSet.AddRange(entities);
await SaveChangesAsync();
}
await SeedSingle(DiscourseChannels, DiscourseChannelSeedData.Get());
await SeedSingle(DiscourseEvents, DiscourseEventSeedData.Get());
await SeedSingle(DiscourseRegions, DiscourseRegionSeedData.Get());
await SeedSingle(DiscourseTypes, DiscourseTypeSeedData.Get());
await SeedSingle(Msds, MsdSeedData.Get());
await SeedSingle(PartOfSpeeches, PartOfSpeechSeedData.Get());
await SeedSingle(SpeakerAges, SpeakerAgeSeedData.Get());
await SeedSingle(SpeakerEducations, SpeakerEducationSeedData.Get());
await SeedSingle(SpeakerLanguages, SpeakerLanguageSeedData.Get());
await SeedSingle(SpeakerRegions, SpeakerRegionSeedData.Get());
await SeedSingle(SpeakerSexes, SpeakerSexSeedData.Get());
}
}
}
@@ -0,0 +1,2 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;okrajšava;O;CATEGORY;Abbreviation;Y
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta okrajšava O CATEGORY Abbreviation Y
@@ -0,0 +1,22 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;pridevnik;P;CATEGORY;Adjective;A
1;vrsta;splošni;p;Type;general;g
;;svojilni;s;;possessive;s
;;deležniški;d;;participle;p
2;stopnja;nedoločeno;n;Degree;positive;p
;;primernik;p;;comparative;c
;;presežnik;s;;superlative;s
3;spol;moški;m;Gender;masculine;m
;;ženski;z;;feminine;f
;;srednji;s;;neuter;n
4;število;ednina;e;Number;singular;s
;;dvojina;d;;dual;d
;;množina;m;;plural;p
5;sklon;imenovalnik;i;Case;nominative;n
;;rodilnik;r;;genitive;g
;;dajalnik;d;;dative;d
;;tožilnik;t;;accusative;a
;;mestnik;m;;locative;l
;;orodnik;o;;instrumental;i
6;določnost;ne;n;Definiteness;no;n
;;da;d;;yes;y
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta pridevnik P CATEGORY Adjective A
3 1 vrsta splošni p Type general g
4 svojilni s possessive s
5 deležniški d participle p
6 2 stopnja nedoločeno n Degree positive p
7 primernik p comparative c
8 presežnik s superlative s
9 3 spol moški m Gender masculine m
10 ženski z feminine f
11 srednji s neuter n
12 4 število ednina e Number singular s
13 dvojina d dual d
14 množina m plural p
15 5 sklon imenovalnik i Case nominative n
16 rodilnik r genitive g
17 dajalnik d dative d
18 tožilnik t accusative a
19 mestnik m locative l
20 orodnik o instrumental i
21 6 določnost ne n Definiteness no n
22 da d yes y
@@ -0,0 +1,8 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;predlog;D;CATEGORY;Adposition;S
1;sklon;imenovalnik;i;Case;nominative;n
;;rodilnik;r;;genitive;g
;;dajalnik;d;;dative;d
;;tožilnik;t;;accusative;a
;;mestnik;m;;locative;l
;;orodnik;o;;instrumental;i
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta predlog D CATEGORY Adposition S
3 1 sklon imenovalnik i Case nominative n
4 rodilnik r genitive g
5 dajalnik d dative d
6 tožilnik t accusative a
7 mestnik m locative l
8 orodnik o instrumental i
@@ -0,0 +1,7 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;prislov;R;CATEGORY;Adverb;R
1;vrsta;splošni;s;Type;general;g
;;deležje;d;;participle;r
2;stopnja;nedoločeno;n;Degree;positive;p
;;primernik;r;;comparative;c
;;presežnik;s;;superlative;s
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta prislov R CATEGORY Adverb R
3 1 vrsta splošni s Type general g
4 deležje d participle r
5 2 stopnja nedoločeno n Degree positive p
6 primernik r comparative c
7 presežnik s superlative s
@@ -0,0 +1,4 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;veznik;V;CATEGORY;Conjunction;C
1;vrsta;priredni;p;Type;coordinating;c
;;podredni;d;;subordinating;s
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta veznik V CATEGORY Conjunction C
3 1 vrsta priredni p Type coordinating c
4 podredni d subordinating s
@@ -0,0 +1,2 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;medmet;M;CATEGORY;Interjection;I
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta medmet M CATEGORY Interjection I
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,18 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;samostalnik;S;CATEGORY;Noun;N
1;vrsta;občno_ime;o;Type;common;c
;;lastno_ime;l;;proper;p
2;spol;moški;m;Gender;masculine;m
;;ženski;z;;feminine;f
;;srednji;s;;neuter;n
3;število;ednina;e;Number;singular;s
;;dvojina;d;;dual;d
;;množina;m;;plural;p
4;sklon;imenovalnik;i;Case;nominative;n
;;rodilnik;r;;genitive;g
;;dajalnik;d;;dative;d
;;tožilnik;t;;accusative;a
;;mestnik;m;;locative;l
;;orodnik;o;;instrumental;i
5;živost;ne;n;Animate;no;n
;;da;d;;yes;y
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta samostalnik S CATEGORY Noun N
3 1 vrsta občno_ime o Type common c
4 lastno_ime l proper p
5 2 spol moški m Gender masculine m
6 ženski z feminine f
7 srednji s neuter n
8 3 število ednina e Number singular s
9 dvojina d dual d
10 množina m plural p
11 4 sklon imenovalnik i Case nominative n
12 rodilnik r genitive g
13 dajalnik d dative d
14 tožilnik t accusative a
15 mestnik m locative l
16 orodnik o instrumental i
17 5 živost ne n Animate no n
18 da d yes y
@@ -0,0 +1,23 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;števnik;K;CATEGORY;Numeral;M
1;zapis;arabski;a;Form;digit;d
;;rimski;r;;roman;r
;;besedni;b;;letter;l
2;vrsta;glavni;g;Type;cardinal;c
;;vrstilni;v;;ordinal;o
;;zaimkovni;z;;pronominal;p
;;drugi;d;;special;s
3;spol;moški;m;Gender;masculine;m
;;ženski;z;;feminine;f
;;srednji;s;;neuter;n
4;število;ednina;e;Number;singular;s
;;dvojina;d;;dual;d
;;množina;m;;plural;p
5;sklon;imenovalnik;i;Case;nominative;n
;;rodilnik;r;;genitive;g
;;dajalnik;d;;dative;d
;;tožilnik;t;;accusative;a
;;mestnik;m;;locative;l
;;orodnik;o;;instrumental;i
6;določnost;ne;n;Definiteness;no;n
;;da;d;;yes;y
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta števnik K CATEGORY Numeral M
3 1 zapis arabski a Form digit d
4 rimski r roman r
5 besedni b letter l
6 2 vrsta glavni g Type cardinal c
7 vrstilni v ordinal o
8 zaimkovni z pronominal p
9 drugi d special s
10 3 spol moški m Gender masculine m
11 ženski z feminine f
12 srednji s neuter n
13 4 število ednina e Number singular s
14 dvojina d dual d
15 množina m plural p
16 5 sklon imenovalnik i Case nominative n
17 rodilnik r genitive g
18 dajalnik d dative d
19 tožilnik t accusative a
20 mestnik m locative l
21 orodnik o instrumental i
22 6 določnost ne n Definiteness no n
23 da d yes y
@@ -0,0 +1,2 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;členek;L;CATEGORY;Particle;Q
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta členek L CATEGORY Particle Q
@@ -0,0 +1,34 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;zaimek;Z;CATEGORY;Pronoun;P
1;vrsta;osebni;o;Type;personal;p
;;svojilni;s;;possessive;s
;;kazalni;k;;demonstrative;d
;;oziralni;z;;relative;r
;;povratni;p;;reflexive;x
;;celostni;c;;general;g
;;vprašalni;v;;interrogative;q
;;nedoločni;n;;indefinite;i
;;nikalni;l;;negative;z
2;oseba;prva;p;Person;first;1
;;druga;d;;second;2
;;tretja;t;;third;3
3;spol;moški;m;Gender;masculine;m
;;ženski;z;;feminine;f
;;srednji;s;;neuter;n
4;število;ednina;e;Number;singular;s
;;dvojina;d;;dual;d
;;množina;m;;plural;p
5;sklon;imenovalnik;i;Case;nominative;n
;;rodilnik;r;;genitive;g
;;dajalnik;d;;dative;d
;;tožilnik;t;;accusative;a
;;mestnik;m;;locative;l
;;orodnik;o;;instrumental;i
6;število_svojine;ednina;e;Owner_Number;singular;s
;;dvojina;d;;dual;d
;;množina;m;;plural;p
7;spol_svojine;moški;m;Owner_Gender;masculine;m
;;ženski;z;;feminine;f
;;srednji;s;;neuter;n
8;naslonskost;klitična;k;Clitic;yes;y
;;navezna;z;;bound;b
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta zaimek Z CATEGORY Pronoun P
3 1 vrsta osebni o Type personal p
4 svojilni s possessive s
5 kazalni k demonstrative d
6 oziralni z relative r
7 povratni p reflexive x
8 celostni c general g
9 vprašalni v interrogative q
10 nedoločni n indefinite i
11 nikalni l negative z
12 2 oseba prva p Person first 1
13 druga d second 2
14 tretja t third 3
15 3 spol moški m Gender masculine m
16 ženski z feminine f
17 srednji s neuter n
18 4 število ednina e Number singular s
19 dvojina d dual d
20 množina m plural p
21 5 sklon imenovalnik i Case nominative n
22 rodilnik r genitive g
23 dajalnik d dative d
24 tožilnik t accusative a
25 mestnik m locative l
26 orodnik o instrumental i
27 6 število_svojine ednina e Owner_Number singular s
28 dvojina d dual d
29 množina m plural p
30 7 spol_svojine moški m Owner_Gender masculine m
31 ženski z feminine f
32 srednji s neuter n
33 8 naslonskost klitična k Clitic yes y
34 navezna z bound b
@@ -0,0 +1,2 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;ločilo;U;CATEGORY;Punctuation;Z
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta ločilo U CATEGORY Punctuation Z
@@ -0,0 +1,9 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;neuvrščeno;N;CATEGORY;Residual;X
1;vrsta;tujejezično;j;Type;foreign;f
;;tipkarska;t;;typo;t
;;splet;w;;web;w
;;emo;e;;emo;e
;;ključnik;h;;hashtag;h
;;afna;a;;at;a
;;program;p;;program;p
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta neuvrščeno N CATEGORY Residual X
3 1 vrsta tujejezično j Type foreign f
4 tipkarska t typo t
5 splet w web w
6 emo e emo e
7 ključnik h hashtag h
8 afna a at a
9 program p program p
@@ -0,0 +1,25 @@
P;Attribute (sl);Value (sl);Code (sl);Attribute (en);Value (en);Code (en)
0;besedna_vrsta;glagol;G;CATEGORY;Verb;V
1;vrsta;glavni;g;Type;main;m
;;pomožni;p;;auxiliary;a
2;vid;dovršni;d;Aspect;perfective;e
;;nedovršni;n;;progressive;p
;;dvovidski;v;;biaspectual;b
3;oblika;nedoločnik;n;VForm;infinitive;n
;;namenilnik;m;;supine;u
;;deležnik;d;;participle;p
;;sedanjik;s;;present;r
;;prihodnjik;p;;future;f
;;pogojnik;g;;conditional;c
;;velelnik;v;;imperative;m
4;oseba;prva;p;Person;first;1
;;druga;d;;second;2
;;tretja;t;;third;3
5;število;ednina;e;Number;singular;s
;;množina;m;;plural;p
;;dvojina;d;;dual;d
6;spol;moški;m;Gender;masculine;m
;;ženski;z;;feminine;f
;;srednji;s;;neuter;n
7;nikalnost;nezanikani;n;Negative;no;n
;;zanikani;d;;yes;y
1 P Attribute (sl) Value (sl) Code (sl) Attribute (en) Value (en) Code (en)
2 0 besedna_vrsta glagol G CATEGORY Verb V
3 1 vrsta glavni g Type main m
4 pomožni p auxiliary a
5 2 vid dovršni d Aspect perfective e
6 nedovršni n progressive p
7 dvovidski v biaspectual b
8 3 oblika nedoločnik n VForm infinitive n
9 namenilnik m supine u
10 deležnik d participle p
11 sedanjik s present r
12 prihodnjik p future f
13 pogojnik g conditional c
14 velelnik v imperative m
15 4 oseba prva p Person first 1
16 druga d second 2
17 tretja t third 3
18 5 število ednina e Number singular s
19 množina m plural p
20 dvojina d dual d
21 6 spol moški m Gender masculine m
22 ženski z feminine f
23 srednji s neuter n
24 7 nikalnost nezanikani n Negative no n
25 zanikani d yes y
@@ -0,0 +1,81 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class DiscourseChannelSeedData
{
public static IEnumerable<DiscourseChannel> Get()
{
yield return new DiscourseChannel
{
Id = (int)DiscourseChannelKeys.Radio,
Translations = new TranslationCollection<DiscourseChannelTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Radio",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Radio",
},
},
};
yield return new DiscourseChannel
{
Id = (int)DiscourseChannelKeys.Televizija,
Translations = new TranslationCollection<DiscourseChannelTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Televizija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Television",
},
},
};
yield return new DiscourseChannel
{
Id = (int)DiscourseChannelKeys.OsebniStik,
Translations = new TranslationCollection<DiscourseChannelTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Osebni stik",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Personal contact",
},
},
};
yield return new DiscourseChannel
{
Id = (int)DiscourseChannelKeys.Telefon,
Translations = new TranslationCollection<DiscourseChannelTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Telefon",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Telephone",
},
},
};
}
}
}
@@ -0,0 +1,404 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class DiscourseEventSeedData
{
public static IEnumerable<DiscourseEvent> Get()
{
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.NovinarskiPrispevek,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Novinarski prispevek",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "News report",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.ModeriraniPogovorTv,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Moderirani pogovor",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Moderated discussion",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.ModeriranaOddaja,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Moderirana oddaja",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Moderated show",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.ResnicnostniSov,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Resničnostni šov",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Reality show",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.SportniPrenos,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Športni prenos",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Sports broadcast",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.ModeriraniProgram,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Moderirani program",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Moderated broadcast",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.ModeriraniPogovorRadio,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Moderirani pogovor",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Moderated discussion",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.OsnovnosolskaUcnaUra,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Osnovnošolska učna ura",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Elementary school lesson",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.SrednjesolskaUcnaUra,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Srednješolska učna ura",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Secondary school lesson",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.Tecaj,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Tečaj",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Course",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.FakultetnoPredavanje,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Fakultetno predavanje",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "University lecture",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.JavnoPredavanje,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Javno predavanje",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Public lecture",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.FormalniDelovniSestanek,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Formalni delovni sestanek",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Formal work meeting",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.NeformalniDelovniSestanek,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Neformalni delovni sestanek",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Informal work meeting",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.Konzultacija,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Konzultacija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Consultation",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.Storitev,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Storitev",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Service",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.FormalniRazgovor,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Formalni razgovor",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Formal interview",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.ProdajaTrgovina,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Prodaja/trgovina",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Sales/Trade",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.Svetovanje,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Svetovanje",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Advising",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.Informacije,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Informacije",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Information desk",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.Tajnistvo,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Tajništvo",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Administration office",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.PogovorVDruzini,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Pogovor v družini",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Family conversation",
},
},
};
yield return new DiscourseEvent
{
Id = (int)DiscourseEventKeys.PogovorMedPrijateljiZnanci,
Translations = new TranslationCollection<DiscourseEventTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Pogovor med prijatelji/znanci",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Conversation between friends",
},
},
};
}
}
}
@@ -0,0 +1,355 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class DiscourseRegionSeedData
{
public static IEnumerable<DiscourseRegion> Get()
{
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Celjska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "CE",
Title = "Celjska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "CE",
Title = "Celje",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Novogoriska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "GO",
Title = "Novogoriška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "GO",
Title = "Nova Gorica",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Krska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "KK",
Title = "Krška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "KK",
Title = "Krško",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Koprska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "KP",
Title = "Koprska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "KP",
Title = "Koper",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Kranjska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "KR",
Title = "Kranjska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "KR",
Title = "Kranj",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Ljubljanska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "LJ",
Title = "Ljubljanska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "LJ",
Title = "Ljubljana",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Mariborska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "MB",
Title = "Mariborska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "MB",
Title = "Maribor",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Murskosoboska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "MS",
Title = "Murskosoboška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "MS",
Title = "Murska Sobota",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Novomeska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "NM",
Title = "Novomeška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "NM",
Title = "Novo mesto",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Postojnska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "PO",
Title = "Postojnska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "PO",
Title = "Postojna",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Slovenjgraska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "SG",
Title = "Slovenjgraška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "SG",
Title = "Slovenj Gradec",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.CelotnaSlovenija,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Slo",
Title = "Celotna Slovenija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Slo",
Title = "Slovenia",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.SeverovzhodnaSlovenija,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "SV Slo",
Title = "Severovzhodna Slovenija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "SV Slo",
Title = "Northeastern Slovenia",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.JugozahodnaSlovenija,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "JZ Slo",
Title = "Jugozahodna Slovenija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "JZ Slo",
Title = "Southwestern Slovenia",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Avstrija,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Avstrija",
Title = "Avstrija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Austria",
Title = "Austria",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Italija,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Italija",
Title = "Italija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Italy",
Title = "Italy",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Madzarska,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Madžarska",
Title = "Madžarska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Hungary",
Title = "Hungary",
},
},
};
yield return new DiscourseRegion
{
Id = (int)DiscourseRegionKeys.Neznano,
Translations = new TranslationCollection<DiscourseRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Neznano",
Title = "Neznano",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Unknown",
Title = "Unknown",
},
},
};
}
}
}
@@ -0,0 +1,90 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class DiscourseTypeSeedData
{
public static IEnumerable<DiscourseType> Get()
{
yield return new DiscourseType
{
Id = (int)DiscourseTypeKeys.JavniInformativnoIzobrazevalni,
Translations = new TranslationCollection<DiscourseTypeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "JI",
Title = "Javni informativno-izobraževalni",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "PI",
Title = "Public – informative and educational",
},
},
};
yield return new DiscourseType
{
Id = (int)DiscourseTypeKeys.JavniRazvedrilni,
Translations = new TranslationCollection<DiscourseTypeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "JR",
Title = "Javni razvedrilni",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "PE",
Title = "Public – entertainment",
},
},
};
yield return new DiscourseType
{
Id = (int)DiscourseTypeKeys.NejavniNezasebni,
Translations = new TranslationCollection<DiscourseTypeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "NN",
Title = "Nejavni nezasebni",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "NN",
Title = "Non-public – non-private",
},
},
};
yield return new DiscourseType
{
Id = (int)DiscourseTypeKeys.NejavniZasebni,
Translations = new TranslationCollection<DiscourseTypeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "NZ",
Title = "Nejavni zasebni",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "NP",
Title = "Non-public – private",
},
},
};
}
}
}
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.IO;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class MsdSeedData
{
public static IEnumerable<Msd> Get()
{
var assembly = typeof(PartOfSpeechSeedData).Assembly;
var resourceName = $"Gos.Services.Framework.SeedData.CsvFiles.msd.csv";
using var stream = assembly.GetManifestResourceStream(resourceName);
using var streamReader = new StreamReader(stream);
// Skip header line
streamReader.ReadLine();
// Loop through other lines
string line;
while ((line = streamReader.ReadLine()) != null)
{
yield return ReadFromLine(line);
}
}
public static Msd ReadFromLine(string line)
{
var values = line.Split(";");
return new Msd()
{
Code = values[0],
Translations = new TranslationCollection<MsdTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = values[3],
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = values[1],
},
},
};
}
}
}
@@ -0,0 +1,142 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class PartOfSpeechSeedData
{
public static IEnumerable<PartOfSpeech> Get()
{
var names = new string[]
{
"Noun",
"Verb",
"Adjective",
"Adverb",
"Pronoun",
"Numeral",
"Adposition",
"Conjunction",
"Particle",
"Interjection",
"Abbreviation",
"Residual",
"Punctuation",
};
for (int i = 0; i < names.Length; i++)
{
var assembly = typeof(PartOfSpeechSeedData).Assembly;
var resourceName = $"Gos.Services.Framework.SeedData.CsvFiles.{names[i].ToLower()}.csv";
using var stream = assembly.GetManifestResourceStream(resourceName);
yield return ReadFromStream(stream, (short)(i + 1));
}
}
private static PartOfSpeech ReadFromStream(Stream stream, short recordOrder)
{
using var streamReader = new StreamReader(stream);
// Skip header line
streamReader.ReadLine();
// Loop through other lines
string line;
short attributeOrder = 0;
short attributeValueOrder = 0;
PartOfSpeech partOfSpeech = null;
PartOfSpeechAttribute partOfSpeechAttribute = null;
while ((line = streamReader.ReadLine()) != null)
{
var values = line.Split(";");
if (values[0] == "0")
{
partOfSpeech = GetPartOfSpeech(values, recordOrder);
}
else
{
if (values[0] != "")
{
attributeOrder++;
partOfSpeechAttribute = GetPartOfSpeechAttribute(values, attributeOrder);
partOfSpeech.Attributes.Add(partOfSpeechAttribute);
attributeValueOrder = 0;
}
attributeValueOrder++;
var partOfSpeechAttributeValue = GetPartOfSpeechAttributeValue(values, attributeValueOrder);
partOfSpeechAttribute.Values.Add(partOfSpeechAttributeValue);
}
}
return partOfSpeech;
}
private static PartOfSpeech GetPartOfSpeech(string[] values, short recordOrder)
{
return new PartOfSpeech()
{
Code = values[6],
RecordOrder = recordOrder,
Translations = new TranslationCollection<PartOfSpeechTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = values[2],
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = values[5],
},
},
};
}
private static PartOfSpeechAttribute GetPartOfSpeechAttribute(string[] values, short recordOrder)
{
return new PartOfSpeechAttribute()
{
RecordOrder = recordOrder,
Translations = new TranslationCollection<PartOfSpeechAttributeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = values[1],
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = values[4],
},
},
};
}
private static PartOfSpeechAttributeValue GetPartOfSpeechAttributeValue(string[] values, short recordOrder)
{
return new PartOfSpeechAttributeValue()
{
Code = values[6],
RecordOrder = recordOrder,
Translations = new TranslationCollection<PartOfSpeechAttributeValueTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = values[2],
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = values[5],
},
},
};
}
}
}
@@ -0,0 +1,149 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class SpeakerAgeSeedData
{
public static IEnumerable<SpeakerAge> Get()
{
yield return new SpeakerAge
{
Id = (int)SpeakerAgeKeys.Do10Let,
Translations = new TranslationCollection<SpeakerAgeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "do 10",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "below 10",
},
},
};
yield return new SpeakerAge
{
Id = (int)SpeakerAgeKeys.Od10Do14Let,
Translations = new TranslationCollection<SpeakerAgeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "10 do 14",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "10 to 14",
},
},
};
yield return new SpeakerAge
{
Id = (int)SpeakerAgeKeys.Od15Do18Let,
Translations = new TranslationCollection<SpeakerAgeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "15 do 18",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "15 to 18",
},
},
};
yield return new SpeakerAge
{
Id = (int)SpeakerAgeKeys.Od19Do24Let,
Translations = new TranslationCollection<SpeakerAgeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "19 do 24",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "19 to 24",
},
},
};
yield return new SpeakerAge
{
Id = (int)SpeakerAgeKeys.Od25Do34Let,
Translations = new TranslationCollection<SpeakerAgeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "25 do 34",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "25 to 34",
},
},
};
yield return new SpeakerAge
{
Id = (int)SpeakerAgeKeys.Od35Do59Let,
Translations = new TranslationCollection<SpeakerAgeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "35 do 59",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "35 to 59",
},
},
};
yield return new SpeakerAge
{
Id = (int)SpeakerAgeKeys.Nad60Let,
Translations = new TranslationCollection<SpeakerAgeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "nad 60",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "over 60",
},
},
};
yield return new SpeakerAge
{
Id = (int)SpeakerAgeKeys.Neznano,
Translations = new TranslationCollection<SpeakerAgeTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Neznano",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Unknown",
},
},
};
}
}
}
@@ -0,0 +1,98 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class SpeakerEducationSeedData
{
public static IEnumerable<SpeakerEducation> Get()
{
yield return new SpeakerEducation
{
Id = (int)SpeakerEducationKeys.OsAliManj,
Translations = new TranslationCollection<SpeakerEducationTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "OŠ ali manj",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Elementary or lower",
},
},
};
yield return new SpeakerEducation
{
Id = (int)SpeakerEducationKeys.SrednjaSola,
Translations = new TranslationCollection<SpeakerEducationTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Srednja šola",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Secondary",
},
},
};
yield return new SpeakerEducation
{
Id = (int)SpeakerEducationKeys.VisjaAliVisokaSola,
Translations = new TranslationCollection<SpeakerEducationTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Višja ali visoka šola",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Professional higher",
},
},
};
yield return new SpeakerEducation
{
Id = (int)SpeakerEducationKeys.FakultetaAliVec,
Translations = new TranslationCollection<SpeakerEducationTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Fakulteta ali več",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "University or more",
},
},
};
yield return new SpeakerEducation
{
Id = (int)SpeakerEducationKeys.Neznano,
Translations = new TranslationCollection<SpeakerEducationTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Neznano",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Unknown",
},
},
};
}
}
}
@@ -0,0 +1,217 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class SpeakerLanguageSeedData
{
public static IEnumerable<SpeakerLanguage> Get()
{
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Slovenscina,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Slovenščina",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Slovene",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Anglescina,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Angleščina",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "English",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Nemscina,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Nemščina",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "German",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Italijanscina,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Italijanščina",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Italian",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Madzarscina,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Madžarščina",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Hungarian",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Juznoslovanski,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Južnoslovanski",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "South Slavic",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Albanscina,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Albanščina",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Albanian",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.DrugiSlovanski,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Drugi slovanski",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Other Slavic",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.DrugiGermanski,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Drugi germanski",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Other Germanic",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.DrugiRomanski,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Drugi romanski",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Other Romanic",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Neindoevropski,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Neindoevropski",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "non-Indo-European",
},
},
};
yield return new SpeakerLanguage
{
Id = (int)SpeakerLanguageKeys.Neznano,
Translations = new TranslationCollection<SpeakerLanguageTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Neznano",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Unknown",
},
},
};
}
}
}
@@ -0,0 +1,317 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class SpeakerRegionSeedData
{
public static IEnumerable<SpeakerRegion> Get()
{
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Celjska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "CE",
Title = "Celjska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "CE",
Title = "Celje",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Novogoriska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "GO",
Title = "Novogoriška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "GO",
Title = "Nova Gorica",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Krska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "KK",
Title = "Krška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "KK",
Title = "Krško",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Koprska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "KP",
Title = "Koprska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "KP",
Title = "Koper",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Kranjska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "KR",
Title = "Kranjska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "KR",
Title = "Kranj",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Ljubljanska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "LJ",
Title = "Ljubljanska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "LJ",
Title = "Ljubljana",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Mariborska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "MB",
Title = "Mariborska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "MB",
Title = "Maribor",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Murskosoboska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "MS",
Title = "Murskosoboška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "MS",
Title = "Murska Sobota",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Novomeska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "NM",
Title = "Novomeška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "NM",
Title = "Novo mesto",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Postojnska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "PO",
Title = "Postojnska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "PO",
Title = "Postojna",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Slovenjgraska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "SG",
Title = "Slovenjgraška",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "SG",
Title = "Slovenj Gradec",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Avstrija,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Avstrija",
Title = "Avstrija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Austria",
Title = "Austria",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Italija,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Italija",
Title = "Italija",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Italy",
Title = "Italy",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Madzarska,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Madžarska",
Title = "Madžarska",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Hungary",
Title = "Hungary",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Tujina,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Tujina",
Title = "Tujina",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Outside Slovenia",
Title = "Outside Slovenia",
},
},
};
yield return new SpeakerRegion
{
Id = (int)SpeakerRegionKeys.Neznano,
Translations = new TranslationCollection<SpeakerRegionTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
ShortTitle = "Neznano",
Title = "Neznano",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
ShortTitle = "Unknown",
Title = "Unknown",
},
},
};
}
}
}
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using Gos.Core;
using Gos.Core.Entities;
namespace Gos.Services.Framework.SeedData
{
public static class SpeakerSexSeedData
{
public static IEnumerable<SpeakerSex> Get()
{
yield return new SpeakerSex
{
Id = (int)SpeakerSexKeys.Moski,
Translations = new TranslationCollection<SpeakerSexTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Moški",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Male",
},
},
};
yield return new SpeakerSex
{
Id = (int)SpeakerSexKeys.Zenski,
Translations = new TranslationCollection<SpeakerSexTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Ženski",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Female",
},
},
};
yield return new SpeakerSex
{
Id = (int)SpeakerSexKeys.Neznano,
Translations = new TranslationCollection<SpeakerSexTranslation>()
{
new()
{
CultureName = Constants.InterfaceLanguages.Slovene,
Title = "Neznano",
},
new()
{
CultureName = Constants.InterfaceLanguages.English,
Title = "Unknown",
},
},
};
}
}
}
+73
View File
@@ -0,0 +1,73 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Gos.Core\Gos.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="6.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Framework\SeedData\CsvFiles" />
</ItemGroup>
<ItemGroup>
<None Remove="Framework\SeedData\CsvFiles\abbreviation.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\abbreviation.csv" />
<None Remove="Framework\SeedData\CsvFiles\adjective.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\adjective.csv" />
<None Remove="Framework\SeedData\CsvFiles\adposition.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\adposition.csv" />
<None Remove="Framework\SeedData\CsvFiles\adverb.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\adverb.csv" />
<None Remove="Framework\SeedData\CsvFiles\conjunction.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\conjunction.csv" />
<None Remove="Framework\SeedData\CsvFiles\interjection.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\interjection.csv" />
<None Remove="Framework\SeedData\CsvFiles\noun.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\noun.csv" />
<None Remove="Framework\SeedData\CsvFiles\numeral.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\numeral.csv" />
<None Remove="Framework\SeedData\CsvFiles\particle.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\particle.csv" />
<None Remove="Framework\SeedData\CsvFiles\pronoun.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\pronoun.csv" />
<None Remove="Framework\SeedData\CsvFiles\punctuation.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\punctuation.csv" />
<None Remove="Framework\SeedData\CsvFiles\residual.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\residual.csv" />
<None Remove="Framework\SeedData\CsvFiles\verb.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\verb.csv" />
<None Remove="Framework\SeedData\CsvFiles\msd.csv" />
<EmbeddedResource Include="Framework\SeedData\CsvFiles\msd.csv" />
<EmbeddedResource Update="Resources\ExportResource.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>ExportResource.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\ExportResource.en.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>ExportResource.en.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\ExportResource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ExportResource.resx</DependentUpon>
</Compile>
<Compile Update="Resources\ExportResource.en.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>ExportResource.en.resx</DependentUpon>
</Compile>
</ItemGroup>
</Project>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,929 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Gos.Services.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "CorpusCounters",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Discourses = table.Column<int>(type: "integer", nullable: false),
Statements = table.Column<int>(type: "integer", nullable: false),
Words = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CorpusCounters", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CorpusForms",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StandardForm = table.Column<string>(type: "text", nullable: true),
Lemma = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_CorpusForms", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DiscourseChannels",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscourseChannels", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DiscourseEvents",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscourseEvents", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DiscourseRegions",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscourseRegions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DiscourseTypes",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscourseTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Msds",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Code = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Msds", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PartOfSpeeches",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Code = table.Column<string>(type: "text", nullable: true),
RecordOrder = table.Column<short>(type: "smallint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PartOfSpeeches", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SpeakerAges",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerAges", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SpeakerEducations",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerEducations", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SpeakerLanguages",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerLanguages", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SpeakerRegions",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerRegions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SpeakerSexes",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerSexes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DiscourseChannelTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
DiscourseChannelId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscourseChannelTranslation", x => x.Id);
table.ForeignKey(
name: "FK_DiscourseChannelTranslation_DiscourseChannels_DiscourseChan~",
column: x => x.DiscourseChannelId,
principalTable: "DiscourseChannels",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "DiscourseEventTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
DiscourseEventId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscourseEventTranslation", x => x.Id);
table.ForeignKey(
name: "FK_DiscourseEventTranslation_DiscourseEvents_DiscourseEventId",
column: x => x.DiscourseEventId,
principalTable: "DiscourseEvents",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "DiscourseRegionTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ShortTitle = table.Column<string>(type: "text", nullable: true),
Title = table.Column<string>(type: "text", nullable: true),
DiscourseRegionId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscourseRegionTranslation", x => x.Id);
table.ForeignKey(
name: "FK_DiscourseRegionTranslation_DiscourseRegions_DiscourseRegion~",
column: x => x.DiscourseRegionId,
principalTable: "DiscourseRegions",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Discourses",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ChannelId = table.Column<int>(type: "integer", nullable: true),
Code = table.Column<string>(type: "text", nullable: true),
Date = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
Description = table.Column<string>(type: "text", nullable: true),
EventId = table.Column<int>(type: "integer", nullable: true),
Length = table.Column<int>(type: "integer", nullable: false),
Location = table.Column<string>(type: "text", nullable: true),
NumberOfSpeakers = table.Column<int>(type: "integer", nullable: false),
RegionId = table.Column<int>(type: "integer", nullable: true),
Source = table.Column<string>(type: "text", nullable: true),
TypeId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Discourses", x => x.Id);
table.ForeignKey(
name: "FK_Discourses_DiscourseChannels_ChannelId",
column: x => x.ChannelId,
principalTable: "DiscourseChannels",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Discourses_DiscourseEvents_EventId",
column: x => x.EventId,
principalTable: "DiscourseEvents",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Discourses_DiscourseRegions_RegionId",
column: x => x.RegionId,
principalTable: "DiscourseRegions",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Discourses_DiscourseTypes_TypeId",
column: x => x.TypeId,
principalTable: "DiscourseTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "DiscourseTypeTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ShortTitle = table.Column<string>(type: "text", nullable: true),
Title = table.Column<string>(type: "text", nullable: true),
DiscourseTypeId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DiscourseTypeTranslation", x => x.Id);
table.ForeignKey(
name: "FK_DiscourseTypeTranslation_DiscourseTypes_DiscourseTypeId",
column: x => x.DiscourseTypeId,
principalTable: "DiscourseTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "MsdTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
MsdId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_MsdTranslation", x => x.Id);
table.ForeignKey(
name: "FK_MsdTranslation_Msds_MsdId",
column: x => x.MsdId,
principalTable: "Msds",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "PartOfSpeechAttribute",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RecordOrder = table.Column<short>(type: "smallint", nullable: false),
PartOfSpeechId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PartOfSpeechAttribute", x => x.Id);
table.ForeignKey(
name: "FK_PartOfSpeechAttribute_PartOfSpeeches_PartOfSpeechId",
column: x => x.PartOfSpeechId,
principalTable: "PartOfSpeeches",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "PartOfSpeechTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
PartOfSpeechId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PartOfSpeechTranslation", x => x.Id);
table.ForeignKey(
name: "FK_PartOfSpeechTranslation_PartOfSpeeches_PartOfSpeechId",
column: x => x.PartOfSpeechId,
principalTable: "PartOfSpeeches",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "SpeakerAgeTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
SpeakerAgeId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerAgeTranslation", x => x.Id);
table.ForeignKey(
name: "FK_SpeakerAgeTranslation_SpeakerAges_SpeakerAgeId",
column: x => x.SpeakerAgeId,
principalTable: "SpeakerAges",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "SpeakerEducationTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
SpeakerEducationId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerEducationTranslation", x => x.Id);
table.ForeignKey(
name: "FK_SpeakerEducationTranslation_SpeakerEducations_SpeakerEducat~",
column: x => x.SpeakerEducationId,
principalTable: "SpeakerEducations",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "SpeakerLanguageTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
SpeakerLanguageId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerLanguageTranslation", x => x.Id);
table.ForeignKey(
name: "FK_SpeakerLanguageTranslation_SpeakerLanguages_SpeakerLanguage~",
column: x => x.SpeakerLanguageId,
principalTable: "SpeakerLanguages",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "SpeakerRegionTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ShortTitle = table.Column<string>(type: "text", nullable: true),
Title = table.Column<string>(type: "text", nullable: true),
SpeakerRegionId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerRegionTranslation", x => x.Id);
table.ForeignKey(
name: "FK_SpeakerRegionTranslation_SpeakerRegions_SpeakerRegionId",
column: x => x.SpeakerRegionId,
principalTable: "SpeakerRegions",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Speakers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
AgeId = table.Column<int>(type: "integer", nullable: true),
Code = table.Column<string>(type: "text", nullable: true),
EducationId = table.Column<int>(type: "integer", nullable: true),
LanguageId = table.Column<int>(type: "integer", nullable: true),
Region1Id = table.Column<int>(type: "integer", nullable: true),
Region2Id = table.Column<int>(type: "integer", nullable: true),
Region3Id = table.Column<int>(type: "integer", nullable: true),
SexId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Speakers", x => x.Id);
table.ForeignKey(
name: "FK_Speakers_SpeakerAges_AgeId",
column: x => x.AgeId,
principalTable: "SpeakerAges",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Speakers_SpeakerEducations_EducationId",
column: x => x.EducationId,
principalTable: "SpeakerEducations",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Speakers_SpeakerLanguages_LanguageId",
column: x => x.LanguageId,
principalTable: "SpeakerLanguages",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Speakers_SpeakerRegions_Region1Id",
column: x => x.Region1Id,
principalTable: "SpeakerRegions",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Speakers_SpeakerRegions_Region2Id",
column: x => x.Region2Id,
principalTable: "SpeakerRegions",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Speakers_SpeakerRegions_Region3Id",
column: x => x.Region3Id,
principalTable: "SpeakerRegions",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Speakers_SpeakerSexes_SexId",
column: x => x.SexId,
principalTable: "SpeakerSexes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "SpeakerSexTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
SpeakerSexId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SpeakerSexTranslation", x => x.Id);
table.ForeignKey(
name: "FK_SpeakerSexTranslation_SpeakerSexes_SpeakerSexId",
column: x => x.SpeakerSexId,
principalTable: "SpeakerSexes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "PartOfSpeechAttributeTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
PartOfSpeechAttributeId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PartOfSpeechAttributeTranslation", x => x.Id);
table.ForeignKey(
name: "FK_PartOfSpeechAttributeTranslation_PartOfSpeechAttribute_Part~",
column: x => x.PartOfSpeechAttributeId,
principalTable: "PartOfSpeechAttribute",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "PartOfSpeechAttributeValue",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Code = table.Column<string>(type: "text", nullable: true),
RecordOrder = table.Column<short>(type: "smallint", nullable: false),
PartOfSpeechAttributeId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PartOfSpeechAttributeValue", x => x.Id);
table.ForeignKey(
name: "FK_PartOfSpeechAttributeValue_PartOfSpeechAttribute_PartOfSpee~",
column: x => x.PartOfSpeechAttributeId,
principalTable: "PartOfSpeechAttribute",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Statements",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Code = table.Column<string>(type: "text", nullable: true),
DiscourseId = table.Column<int>(type: "integer", nullable: true),
Order = table.Column<int>(type: "integer", nullable: false),
SpeakerId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Statements", x => x.Id);
table.ForeignKey(
name: "FK_Statements_Discourses_DiscourseId",
column: x => x.DiscourseId,
principalTable: "Discourses",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Statements_Speakers_SpeakerId",
column: x => x.SpeakerId,
principalTable: "Speakers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "PartOfSpeechAttributeValueTranslation",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: true),
PartOfSpeechAttributeValueId = table.Column<int>(type: "integer", nullable: true),
CultureName = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PartOfSpeechAttributeValueTranslation", x => x.Id);
table.ForeignKey(
name: "FK_PartOfSpeechAttributeValueTranslation_PartOfSpeechAttribute~",
column: x => x.PartOfSpeechAttributeValueId,
principalTable: "PartOfSpeechAttributeValue",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Segments",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Order = table.Column<int>(type: "integer", nullable: false),
SoundFile = table.Column<string>(type: "text", nullable: true),
StatementId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Segments", x => x.Id);
table.ForeignKey(
name: "FK_Segments_Statements_StatementId",
column: x => x.StatementId,
principalTable: "Statements",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Tokens",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ConversationalForm = table.Column<string>(type: "text", nullable: true),
DiscourseOrder = table.Column<int>(type: "integer", nullable: false),
Lemma = table.Column<string>(type: "text", nullable: true),
Msd = table.Column<string>(type: "text", nullable: true),
Order = table.Column<int>(type: "integer", nullable: false),
SegmentId = table.Column<int>(type: "integer", nullable: true),
StandardForm = table.Column<string>(type: "text", nullable: true),
Type = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tokens", x => x.Id);
table.ForeignKey(
name: "FK_Tokens_Segments_SegmentId",
column: x => x.SegmentId,
principalTable: "Segments",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_DiscourseChannelTranslation_DiscourseChannelId",
table: "DiscourseChannelTranslation",
column: "DiscourseChannelId");
migrationBuilder.CreateIndex(
name: "IX_DiscourseEventTranslation_DiscourseEventId",
table: "DiscourseEventTranslation",
column: "DiscourseEventId");
migrationBuilder.CreateIndex(
name: "IX_DiscourseRegionTranslation_DiscourseRegionId",
table: "DiscourseRegionTranslation",
column: "DiscourseRegionId");
migrationBuilder.CreateIndex(
name: "IX_Discourses_ChannelId",
table: "Discourses",
column: "ChannelId");
migrationBuilder.CreateIndex(
name: "IX_Discourses_EventId",
table: "Discourses",
column: "EventId");
migrationBuilder.CreateIndex(
name: "IX_Discourses_RegionId",
table: "Discourses",
column: "RegionId");
migrationBuilder.CreateIndex(
name: "IX_Discourses_TypeId",
table: "Discourses",
column: "TypeId");
migrationBuilder.CreateIndex(
name: "IX_DiscourseTypeTranslation_DiscourseTypeId",
table: "DiscourseTypeTranslation",
column: "DiscourseTypeId");
migrationBuilder.CreateIndex(
name: "IX_MsdTranslation_MsdId",
table: "MsdTranslation",
column: "MsdId");
migrationBuilder.CreateIndex(
name: "IX_PartOfSpeechAttribute_PartOfSpeechId",
table: "PartOfSpeechAttribute",
column: "PartOfSpeechId");
migrationBuilder.CreateIndex(
name: "IX_PartOfSpeechAttributeTranslation_PartOfSpeechAttributeId",
table: "PartOfSpeechAttributeTranslation",
column: "PartOfSpeechAttributeId");
migrationBuilder.CreateIndex(
name: "IX_PartOfSpeechAttributeValue_PartOfSpeechAttributeId",
table: "PartOfSpeechAttributeValue",
column: "PartOfSpeechAttributeId");
migrationBuilder.CreateIndex(
name: "IX_PartOfSpeechAttributeValueTranslation_PartOfSpeechAttribute~",
table: "PartOfSpeechAttributeValueTranslation",
column: "PartOfSpeechAttributeValueId");
migrationBuilder.CreateIndex(
name: "IX_PartOfSpeechTranslation_PartOfSpeechId",
table: "PartOfSpeechTranslation",
column: "PartOfSpeechId");
migrationBuilder.CreateIndex(
name: "IX_Segments_StatementId",
table: "Segments",
column: "StatementId");
migrationBuilder.CreateIndex(
name: "IX_SpeakerAgeTranslation_SpeakerAgeId",
table: "SpeakerAgeTranslation",
column: "SpeakerAgeId");
migrationBuilder.CreateIndex(
name: "IX_SpeakerEducationTranslation_SpeakerEducationId",
table: "SpeakerEducationTranslation",
column: "SpeakerEducationId");
migrationBuilder.CreateIndex(
name: "IX_SpeakerLanguageTranslation_SpeakerLanguageId",
table: "SpeakerLanguageTranslation",
column: "SpeakerLanguageId");
migrationBuilder.CreateIndex(
name: "IX_SpeakerRegionTranslation_SpeakerRegionId",
table: "SpeakerRegionTranslation",
column: "SpeakerRegionId");
migrationBuilder.CreateIndex(
name: "IX_Speakers_AgeId",
table: "Speakers",
column: "AgeId");
migrationBuilder.CreateIndex(
name: "IX_Speakers_EducationId",
table: "Speakers",
column: "EducationId");
migrationBuilder.CreateIndex(
name: "IX_Speakers_LanguageId",
table: "Speakers",
column: "LanguageId");
migrationBuilder.CreateIndex(
name: "IX_Speakers_Region1Id",
table: "Speakers",
column: "Region1Id");
migrationBuilder.CreateIndex(
name: "IX_Speakers_Region2Id",
table: "Speakers",
column: "Region2Id");
migrationBuilder.CreateIndex(
name: "IX_Speakers_Region3Id",
table: "Speakers",
column: "Region3Id");
migrationBuilder.CreateIndex(
name: "IX_Speakers_SexId",
table: "Speakers",
column: "SexId");
migrationBuilder.CreateIndex(
name: "IX_SpeakerSexTranslation_SpeakerSexId",
table: "SpeakerSexTranslation",
column: "SpeakerSexId");
migrationBuilder.CreateIndex(
name: "IX_Statements_DiscourseId",
table: "Statements",
column: "DiscourseId");
migrationBuilder.CreateIndex(
name: "IX_Statements_SpeakerId",
table: "Statements",
column: "SpeakerId");
migrationBuilder.CreateIndex(
name: "IX_Tokens_SegmentId",
table: "Tokens",
column: "SegmentId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CorpusCounters");
migrationBuilder.DropTable(
name: "CorpusForms");
migrationBuilder.DropTable(
name: "DiscourseChannelTranslation");
migrationBuilder.DropTable(
name: "DiscourseEventTranslation");
migrationBuilder.DropTable(
name: "DiscourseRegionTranslation");
migrationBuilder.DropTable(
name: "DiscourseTypeTranslation");
migrationBuilder.DropTable(
name: "MsdTranslation");
migrationBuilder.DropTable(
name: "PartOfSpeechAttributeTranslation");
migrationBuilder.DropTable(
name: "PartOfSpeechAttributeValueTranslation");
migrationBuilder.DropTable(
name: "PartOfSpeechTranslation");
migrationBuilder.DropTable(
name: "SpeakerAgeTranslation");
migrationBuilder.DropTable(
name: "SpeakerEducationTranslation");
migrationBuilder.DropTable(
name: "SpeakerLanguageTranslation");
migrationBuilder.DropTable(
name: "SpeakerRegionTranslation");
migrationBuilder.DropTable(
name: "SpeakerSexTranslation");
migrationBuilder.DropTable(
name: "Tokens");
migrationBuilder.DropTable(
name: "Msds");
migrationBuilder.DropTable(
name: "PartOfSpeechAttributeValue");
migrationBuilder.DropTable(
name: "Segments");
migrationBuilder.DropTable(
name: "PartOfSpeechAttribute");
migrationBuilder.DropTable(
name: "Statements");
migrationBuilder.DropTable(
name: "PartOfSpeeches");
migrationBuilder.DropTable(
name: "Discourses");
migrationBuilder.DropTable(
name: "Speakers");
migrationBuilder.DropTable(
name: "DiscourseChannels");
migrationBuilder.DropTable(
name: "DiscourseEvents");
migrationBuilder.DropTable(
name: "DiscourseRegions");
migrationBuilder.DropTable(
name: "DiscourseTypes");
migrationBuilder.DropTable(
name: "SpeakerAges");
migrationBuilder.DropTable(
name: "SpeakerEducations");
migrationBuilder.DropTable(
name: "SpeakerLanguages");
migrationBuilder.DropTable(
name: "SpeakerRegions");
migrationBuilder.DropTable(
name: "SpeakerSexes");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,37 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Gos.Services.Migrations
{
public partial class AddAuditLog : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AuditLogs",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DurationMs = table.Column<long>(type: "bigint", nullable: false),
EndDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
Message = table.Column<string>(type: "text", nullable: true),
ObjectType = table.Column<string>(type: "text", nullable: true),
SessionId = table.Column<string>(type: "text", nullable: true),
StartDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
TraceIdentifier = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AuditLogs", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AuditLogs");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Gos.Core.Entities;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Requests.Concordance;
using Gos.Services.Extensions;
using Gos.Services.Services.StatementService;
namespace Gos.Services.RequestHandlers.Concordance
{
public abstract class BaseConcordanceHandler
{
protected readonly IStatementService StatementService;
protected BaseConcordanceHandler(IStatementService statementService)
{
this.StatementService = statementService;
}
protected async Task<List<ConcordanceSearchResponseItem>> GetResponseItems(
ConcordanceQuery query,
List<ConcordanceQueryResultItem> items,
bool loadSoundFiles = false)
{
var result = new List<ConcordanceSearchResponseItem>();
foreach (var item in items)
{
result.Add(await GetResponseItem(query, item, loadSoundFiles));
}
return result;
}
private async Task<ConcordanceSearchResponseItem> GetResponseItem(ConcordanceQuery query, ConcordanceQueryResultItem item, bool loadSoundFiles)
{
// Get discourse tokens
var orderStart = item.TokenOrder - 10;
var orderEnd = item.TokenOrder + 10;
// Get predicate for token context limitation
Expression<Func<Token, bool>> predicate = t =>
t.Segment.Statement.Discourse.Id == item.DiscourseId && t.DiscourseOrder >= orderStart && t.DiscourseOrder <= orderEnd;
// Get tokens
var tokens = await StatementService.GetTokens(predicate);
// Get center token
var centerTokenIndex = tokens.FindIndex(t => t.TokenOrder == item.TokenOrder);
// Highlight tokens
tokens = tokens.Highlight(query, centerTokenIndex);
// Get sound files
var soundFiles = loadSoundFiles ? await StatementService.GetSoundFiles(predicate) : null;
// Get contexts
return new ConcordanceSearchResponseItem
{
LeftContext = tokens.GetRange(0, centerTokenIndex),
CenterContext = tokens[centerTokenIndex],
RightContext = tokens.GetRange(centerTokenIndex + 1, tokens.Count - centerTokenIndex - 1),
SoundFiles = soundFiles,
};
}
}
}
@@ -0,0 +1,76 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Gos.Core.Entities;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Requests.Concordance;
using Gos.Services.Extensions;
using Gos.Services.Search.QueryFactories;
using Gos.Services.Services.StatementService;
using MediatR;
namespace Gos.Services.RequestHandlers.Concordance
{
public class ConcordanceDetailsHandler : IRequestHandler<ConcordanceDetails, ConcordanceDetailsResponse>
{
private readonly IQueryFactory<ConcordanceDetails, ConcordanceQuery> queryFactory;
private readonly IStatementService statementService;
public ConcordanceDetailsHandler(IQueryFactory<ConcordanceDetails, ConcordanceQuery> queryFactory, IStatementService statementService)
{
this.queryFactory = queryFactory;
this.statementService = statementService;
}
public async Task<ConcordanceDetailsResponse> Handle(ConcordanceDetails request, CancellationToken cancellationToken)
{
var statement = await statementService.GetStatement(s => s.Id == request.StatementId);
var previous = statement.Order > 0
? await statementService.GetStatement(s => s.Order == statement.Order - 1 && s.Discourse.Id == statement.Discourse.Id)
: null;
var next = await statementService.GetStatement(s => s.Order == statement.Order + 1 && s.Discourse.Id == statement.Discourse.Id);
var response = new ConcordanceDetailsResponse
{
Statement = await GetResponseStatement(statement),
PreviousStatement = await GetResponseStatement(previous),
NextStatement = await GetResponseStatement(next),
};
// Highlight main statement
var query = await queryFactory.GetQuery(request);
response.Statement.Tokens.Highlight(query, statement.Order, request.TokenOrder);
// Return response
return response;
}
private async Task<ConcordanceDetailsResponseStatement> GetResponseStatement(Statement statement)
{
if (statement == null)
{
return null;
}
return new ConcordanceDetailsResponseStatement
{
DiscourseChannel = statement.Discourse.Channel?.Title,
DiscourseDescription = statement.Discourse.Description,
DiscourseEvent = statement.Discourse.Event?.Title,
DiscourseRegion = statement.Discourse.Region?.Title,
DiscourseSource = statement.Discourse.Source,
DiscourseType = statement.Discourse.Type?.Title,
Id = statement.Id,
NumberOfSpeakers = statement.Discourse.NumberOfSpeakers,
SpeakerAge = statement.Speaker?.Age?.Title,
SpeakerCode = statement.Speaker?.Code,
SpeakerEducation = statement.Speaker?.Education?.Title,
SpeakerLanguage = statement.Speaker?.Language?.Title,
SpeakerRegion = statement.Speaker?.Region1?.Title,
SpeakerSex = statement.Speaker?.Sex?.Title,
Tokens = await statementService.GetTokens(t => t.Segment.Statement.Id == statement.Id),
SoundFiles = await statementService.GetSoundFiles(t => t.Segment.Statement.Id == statement.Id),
};
}
}
}
@@ -0,0 +1,118 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Gos.Core.Extensions;
using Gos.Core.Search;
using Gos.Core.Search.Queries.Concordance;
using Gos.ServiceModel.Requests.Concordance;
using Gos.ServiceModel.Requests.Shared;
using Gos.Services.Resources;
using Gos.Services.Search.QueryFactories;
using Gos.Services.Services.StatementService;
using MediatR;
namespace Gos.Services.RequestHandlers.Concordance
{
public class ConcordanceExportHandler : BaseConcordanceHandler, IRequestHandler<ConcordanceExport, ExportResponse>
{
private readonly IQueryFactory<ConcordanceExport, ConcordanceQuery> queryFactory;
private readonly ISearchEngine searchEngine;
public ConcordanceExportHandler(
IQueryFactory<ConcordanceExport, ConcordanceQuery> queryFactory,
ISearchEngine searchEngine,
IStatementService statementService)
: base(statementService)
{
this.queryFactory = queryFactory;
this.searchEngine = searchEngine;
}
public async Task<ExportResponse> Handle(ConcordanceExport request, CancellationToken cancellationToken)
{
// Get query
var query = await queryFactory.GetQuery(request);
// Get results
var results = searchEngine.Search<ConcordanceQuery, ConcordanceQueryResult>(query);
var items = await GetResponseItems(query, results.Items);
// Get center context statements (for details about discourse and speakers)
var statementIds = items.Select(s => s.CenterContext.StatementId).ToList();
var statements = (await StatementService.GetStatements(s => statementIds.Contains(s.Id))).ToDictionary(s => s.Id, s => s);
var stream = new MemoryStream();
using (var writer = new StreamWriter(stream, Encoding.Default, 1024, true))
{
// Write header
await writer.WriteAsync(ExportResource.LeftContext + "\t");
await writer.WriteAsync(request.Query + "\t");
await writer.WriteAsync(ExportResource.RightContext + "\t");
await writer.WriteAsync(ExportResource.StandardizedForm + "\t");
await writer.WriteAsync(ExportResource.DiscourseType + "\t");
await writer.WriteAsync(ExportResource.DiscourseChannel + "\t");
await writer.WriteAsync(ExportResource.DiscourseRegion + "\t");
await writer.WriteAsync(ExportResource.DiscourseSource + "\t");
await writer.WriteAsync(ExportResource.DiscourseYear + "\t");
await writer.WriteAsync(ExportResource.DiscourseEvent + "\t");
await writer.WriteAsync(ExportResource.SpeakerSex + "\t");
await writer.WriteAsync(ExportResource.SpeakerAge + "\t");
await writer.WriteAsync(ExportResource.SpeakerRegion + "\t");
await writer.WriteAsync(ExportResource.SpeakerEducation + "\t");
await writer.WriteAsync(ExportResource.SpeakerLanguage);
await writer.WriteLineAsync();
// Write items
foreach (var item in items)
{
var centerStatement = statements[item.CenterContext.StatementId];
await writer.WriteAsync(item.LeftContext.ToConversationalFormText() + "\t");
await writer.WriteAsync(item.CenterContext.ConversationalForm + "\t");
await writer.WriteAsync(item.RightContext.ToConversationalFormText() + "\t");
await writer.WriteAsync(GetStandardizedForm(item) + "\t");
await writer.WriteAsync(centerStatement.Discourse.Type.Title + "\t");
await writer.WriteAsync(centerStatement.Discourse.Channel.Title + "\t");
await writer.WriteAsync(centerStatement.Discourse.Region.Title + "\t");
await writer.WriteAsync(centerStatement.Discourse.Source + "\t");
await writer.WriteAsync(centerStatement.Discourse.Date.Year + "\t");
await writer.WriteAsync(centerStatement.Discourse.Event.Title + "\t");
await writer.WriteAsync(centerStatement.Speaker?.Sex?.Title + "\t");
await writer.WriteAsync(centerStatement.Speaker?.Age?.Title + "\t");
await writer.WriteAsync(centerStatement.Speaker?.Region1?.Title + "\t");
await writer.WriteAsync(centerStatement.Speaker?.Education?.Title + "\t");
await writer.WriteAsync(centerStatement.Speaker?.Language?.Title);
await writer.WriteLineAsync();
}
}
stream.Position = 0;
return new ExportResponse()
{
ContentType = "text/plain",
FileName = "export.txt",
Stream = stream,
};
}
private static string GetStandardizedForm(ConcordanceSearchResponseItem item)
{
var sb = new StringBuilder();
Append(item.LeftContext.ToStandardFormText());
Append(item.CenterContext.StandardForm);
Append(item.RightContext.ToStandardFormText());
return sb.ToString();
void Append(string text)
{
if (sb.Length > 0)
{
sb.Append(' ');
}
sb.Append(text);
}
}
}
}
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
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.Aggregations;
using Gos.Services.Search.AlternateSearches;
using Gos.Services.Search.QueryFactories;
using Gos.Services.Services.StatementService;
using MediatR;
namespace Gos.Services.RequestHandlers.Concordance
{
public class ConcordanceSearchHandler : BaseConcordanceHandler, IRequestHandler<ConcordanceSearch, ConcordanceSearchResponse>
{
private readonly IAggregationProviderFactory aggregationProviderFactory;
private readonly IAlternateSearchProviderFactory alternateSearchProviderFactory;
private readonly IQueryFactory<ConcordanceSearch, ConcordanceQuery> queryFactory;
private readonly ISearchEngine searchEngine;
public ConcordanceSearchHandler(
IAggregationProviderFactory aggregationProviderFactory,
IAlternateSearchProviderFactory alternateSearchProviderFactory,
IQueryFactory<ConcordanceSearch, ConcordanceQuery> queryFactory,
ISearchEngine searchEngine,
IStatementService statementService)
: base(statementService)
{
this.aggregationProviderFactory = aggregationProviderFactory;
this.alternateSearchProviderFactory = alternateSearchProviderFactory;
this.queryFactory = queryFactory;
this.searchEngine = searchEngine;
}
public async Task<ConcordanceSearchResponse> Handle(ConcordanceSearch request, CancellationToken cancellationToken)
{
// If there is no main word, just return empty result
if (request.MainWord == null)
{
return new ConcordanceSearchResponse()
{
Offset = request.From,
Total = 0,
};
}
// Get query
var query = await queryFactory.GetQuery(request);
// Get results
var results = searchEngine.Search<ConcordanceQuery, ConcordanceQueryResult>(query);
// Return response
return new ConcordanceSearchResponse
{
Items = await GetResponseItems(query, results.Items, true),
Aggregations = new List<Aggregation>()
{
GetAggregation(AggregationType.DiscourseType, c => c.DiscourseTypeIds?.Clear()),
GetAggregation(AggregationType.DiscourseChannel, c => c.DiscourseChannelIds?.Clear()),
GetAggregation(AggregationType.DiscourseRegion, c => c.DiscourseRegionIds?.Clear()),
GetAggregation(AggregationType.DiscourseYear, c => c.DiscourseYears?.Clear()),
GetAggregation(AggregationType.DiscourseEvent, c => c.DiscourseEventIds?.Clear()),
GetAggregation(AggregationType.SpeakerSex, c => c.SpeakerSexIds?.Clear()),
GetAggregation(AggregationType.SpeakerAge, c => c.SpeakerAgeIds?.Clear()),
GetAggregation(AggregationType.SpeakerRegion, c => c.SpeakerRegionIds?.Clear()),
GetAggregation(AggregationType.SpeakerEducation, c => c.SpeakerEducationIds?.Clear()),
GetAggregation(AggregationType.SpeakerLanguage, c => c.SpeakerLanguageIds?.Clear()),
},
LemmasAlternateSearch = await GetLemmaSearches(request),
Offset = request.From,
Total = results.Total,
};
Aggregation GetAggregation(AggregationType type, Action<ConcordanceQuery> modificationAction)
{
var clonedQuery = (ConcordanceQuery)query.Clone();
modificationAction(clonedQuery);
return aggregationProviderFactory.GetProvider(type).Get(clonedQuery);
}
}
private async Task<AlternateSearch<ConcordanceSearch>> GetLemmaSearches(ConcordanceSearch request)
{
if (request.MainWord.TranscriptionType != TranscriptionType.Standard)
{
return null;
}
var provider = alternateSearchProviderFactory.GetProvider<ConcordanceSearch, ConcordanceSearchResponse>(AlternateSearchType.Lemmas);
return await provider.Get(request);
}
}
}
@@ -0,0 +1,25 @@
using System.Threading;
using System.Threading.Tasks;
using Gos.Core.Search;
using Gos.ServiceModel.Requests.Corpus;
using MediatR;
namespace Gos.Services.RequestHandlers.Corpus
{
public class DeleteCorpusIndexHandler : IRequestHandler<DeleteCorpusIndex>
{
private readonly ISearchEngine searchEngine;
public DeleteCorpusIndexHandler(ISearchEngine searchEngine)
{
this.searchEngine = searchEngine;
}
public async Task<Unit> Handle(DeleteCorpusIndex request, CancellationToken cancellationToken)
{
await searchEngine.DeleteSchema();
return new Unit();
}
}
}
@@ -0,0 +1,313 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Gos.Core;
using Gos.Core.Entities;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.RequestHandlers.Corpus
{
public partial class ImportCorpusHandler
{
private async Task<DiscourseChannel> GetDiscourseChannel(XElement channelEl)
{
var channel = channelEl.Attribute("target").Value;
switch (channel)
{
case "#gos.K.R":
return await dbContext.DiscourseChannels.SingleAsync(x => x.Id == (int)DiscourseChannelKeys.Radio);
case "#gos.K.T":
return await dbContext.DiscourseChannels.SingleAsync(x => x.Id == (int)DiscourseChannelKeys.Televizija);
case "#gos.K.O":
return await dbContext.DiscourseChannels.SingleAsync(x => x.Id == (int)DiscourseChannelKeys.OsebniStik);
case "#gos.K.P":
return await dbContext.DiscourseChannels.SingleAsync(x => x.Id == (int)DiscourseChannelKeys.Telefon);
default:
throw new Exception($"Invalid discourse channel {channel}!");
}
}
private DateTime GetDiscourseDate(XElement settingEl)
{
// Date
var date = settingEl.Element(Constants.TeiNs + "date").Value;
var dateParts = date.Split('-');
var year = int.Parse(dateParts[0]);
var month = int.Parse(dateParts[1]);
var day = int.Parse(dateParts[2]);
// Time
var time = settingEl.Element(Constants.TeiNs + "time")?.Value;
if (string.IsNullOrEmpty(time))
{
return new DateTime(year, month, day, 0, 0, 0, DateTimeKind.Utc);
}
var timeParts = time.Split(':');
var hour = int.Parse(timeParts[0]);
var minutes = int.Parse(timeParts[1]);
return new DateTime(year, month, day, hour, minutes, 0, DateTimeKind.Utc);
}
private async Task<DiscourseEvent> GetDiscourseEvent(XElement eventEl)
{
var @event = eventEl.Value;
switch (@event)
{
case "PopTV, 24ur":
case "PopTV, Preverjeno":
case "TVSlo, Dnevnik":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.NovinarskiPrispevek);
case "PopTV, Trenja":
case "PopTV, predvolilna":
case "TVSlo, Odmevi":
case "TVSlo, Polemika":
case "TVSlo, StudioCity":
case "TVSlo, Tarca": // Not in use
case "TVSlo, NLP":
case "TVSlo, Piramida":
case "PopTV, As ti tud":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.ModeriraniPogovorTv);
case "PopTV, Vzemi ali pusti":
case "PopTV, Desetka":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.ModeriranaOddaja);
case "PopTV, Kmetija":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.ResnicnostniSov);
case "TVSlo, šport":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.SportniPrenos);
case "Maribor1, jutranji":
case "Maribor1, Tribuna":
case "City, jutranji":
case "Fantasy, jutranji":
case "Koroški, Salter":
case "Aktual, Aktualno":
case "Belvi, jutranji":
case "Capris, jutranji":
case "Krka, potovanja":
case "Center, jutranji":
case "Maxi, Pod brajdami":
case "Maxi, Pižama bar":
case "Val202, Aktualna":
case "Val202, Vroči mikrofon":
case "Ognjišče, Pogovor o":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.ModeriraniProgram);
case "Koroški, intervju":
case "Kranj, intervju":
case "Krka, intervju":
case "Ognjišče, Naš gost":
case "Štajerski, intervju":
case "Slovenija1, Intervju":
case "Aktual, Na sredi":
case "Val202, Na sceni":
case "moderirani pogovor":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.ModeriraniPogovorRadio);
case "2. triletje, družboslovje":
case "2. triletje, naravoslovje":
case "3. triletje, družboslovje":
case "3. triletje, naravoslovje":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.OsnovnosolskaUcnaUra);
case "gimnazija, družboslovje":
case "gimnazija, družb":
case "gimnazija, naravoslovje":
case "gimnazija, narav":
case "poklicna strokovna, družboslovje":
case "poklicna-strokovna, družb":
case "poklicna strokovna, naravoslovje":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.SrednjesolskaUcnaUra);
case "jezikovni tečaj za tujce":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.Tecaj);
case "akademski, naravoslovje":
case "akademski, družboslovje":
case "akademski, humanistika":
case "akademski, tehnika":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.FakultetnoPredavanje);
case "javno predavanje":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.JavnoPredavanje);
case "formalni delovni sestanek":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.FormalniDelovniSestanek);
case "neformalni delovni sestanek":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.NeformalniDelovniSestanek);
case "konzultacija":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.Konzultacija);
case "storitev":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.Storitev);
case "formalni razgovor":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.FormalniRazgovor);
case "prodaja/trgovina":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.ProdajaTrgovina);
case "svetovanje":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.Svetovanje);
case "informacije":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.Informacije);
case "tajništvo":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.Tajnistvo);
case "doma, družina":
case "zunaj doma, družina":
case "klic sorodniku":
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.PogovorVDruzini);
case "doma, prijatelji":
case "zunaj doma, prijatelji":
case "klic prijatelju":
case "delovno mesto, sodelavci":
case "klic sodelavcu": // Not in use
return await dbContext.DiscourseEvents.SingleAsync(x => x.Id == (int)DiscourseEventKeys.PogovorMedPrijateljiZnanci);
default:
throw new Exception($"Invalid discourse event {@event}!");
}
}
private int GetDiscourseLength(XElement recordingEl)
{
var duration = recordingEl.Attribute("dur").Value;
duration = duration.Replace("PT", "");
var minutes = int.Parse(duration.Substring(0, duration.IndexOf('M')));
var seconds = int.Parse(duration.Substring(duration.IndexOf('M') + 1, duration.IndexOf('S') - duration.IndexOf('M') - 1));
return minutes * 60 + seconds;
}
private async Task<DiscourseRegion> GetDiscourseRegion(XElement regionEl)
{
return await GetDiscourseRegionInternal(regionEl.Value);
}
private async Task<DiscourseRegion> GetDiscourseRegionInternal(string region)
{
switch (region)
{
case "CE":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Celjska);
case "GO":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Novogoriska);
case "KK":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Krska);
case "KP":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Koprska);
case "KR":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Kranjska);
case "LJ":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Ljubljanska);
case "MB":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Mariborska);
case "MS":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Murskosoboska);
case "NM":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Novomeska);
case "PO":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Postojnska);
case "SG":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Slovenjgraska);
case "celotna Slo":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.CelotnaSlovenija);
case "SV Slo":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.SeverovzhodnaSlovenija);
case "JZ Slo":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.JugozahodnaSlovenija);
case "Avstrija":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Avstrija);
case "Italija":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Italija);
case "Madžarska":
return await dbContext.DiscourseRegions.SingleAsync(x => x.Id == (int)DiscourseRegionKeys.Madzarska);
default:
// If there are multiple regions (separated by space) then take only first region
var spaceIdx = region.IndexOf(' ');
if (spaceIdx >= 0)
{
var firstRegion = region.Substring(0, spaceIdx);
return await GetDiscourseRegionInternal(firstRegion);
}
throw new Exception($"Invalid discourse region {region}!");
}
}
private async Task<DiscourseType> GetDiscourseType(XElement typeEl)
{
var type = typeEl.Attribute("target").Value;
switch (type)
{
case "#gos.T.J.I":
return await dbContext.DiscourseTypes.SingleAsync(x => x.Id == (int)DiscourseTypeKeys.JavniInformativnoIzobrazevalni);
case "#gos.T.J.R":
return await dbContext.DiscourseTypes.SingleAsync(x => x.Id == (int)DiscourseTypeKeys.JavniRazvedrilni);
case "#gos.T.N.N":
return await dbContext.DiscourseTypes.SingleAsync(x => x.Id == (int)DiscourseTypeKeys.NejavniNezasebni);
case "#gos.T.N.Z":
return await dbContext.DiscourseTypes.SingleAsync(x => x.Id == (int)DiscourseTypeKeys.NejavniZasebni);
default:
throw new Exception($"Invalid discourse type {type}!");
}
}
private void ImportFileDesc(XElement fileDescEl, Discourse discourse)
{
// Code
var titleEl = fileDescEl.Element(Constants.TeiNs + "titleStmt").Element(Constants.TeiNs + "title");
// Description
discourse.Description = titleEl.Value;
// Location
discourse.Location = fileDescEl.Element(Constants.TeiNs + "publicationStmt").Element(Constants.TeiNs + "pubPlace").Value;
// Length
var recordingEl = fileDescEl.Element(Constants.TeiNs + "sourceDesc")
.Element(Constants.TeiNs + "recordingStmt")
.Element(Constants.TeiNs + "recording");
discourse.Length = GetDiscourseLength(recordingEl);
// Source
discourse.Source = recordingEl.Element(Constants.TeiNs + "broadcast").Element(Constants.TeiNs + "bibl").Element(Constants.TeiNs + "title").Value;
}
private async Task ImportHeader(XElement headerEl, Discourse discourse)
{
// fileDesc
var fileDescEl = headerEl.Element(Constants.TeiNs + "fileDesc");
if (fileDescEl != null)
{
ImportFileDesc(fileDescEl, discourse);
}
// profileDesc
var profileDescEl = headerEl.Element(Constants.TeiNs + "profileDesc");
if (profileDescEl != null)
{
await ImportProfileDesc(profileDescEl, discourse);
}
}
private async Task ImportProfileDesc(XElement profileDescEl, Discourse discourse)
{
// Discourse type
var catRefEles = profileDescEl.Element(Constants.TeiNs + "textClass").Elements(Constants.TeiNs + "catRef");
var typeEl = catRefEles.First(x => x.Attribute("target").Value.StartsWith("#gos.T"));
discourse.Type = await GetDiscourseType(typeEl);
// Discourse channel
var channelEl = catRefEles.First(x => x.Attribute("target").Value.StartsWith("#gos.K"));
discourse.Channel = await GetDiscourseChannel(channelEl);
// Discourse event
var domainEl = profileDescEl.Element(Constants.TeiNs + "textDesc")?.Element(Constants.TeiNs + "domain");
discourse.Event = await GetDiscourseEvent(domainEl);
// Number of speakers
var listPersonEl = profileDescEl.Element(Constants.TeiNs + "particDesc").Element(Constants.TeiNs + "listPerson");
discourse.NumberOfSpeakers = listPersonEl.Elements(Constants.TeiNs + "person").Count();
// Discourse region
var settingDescEl = profileDescEl.Element(Constants.TeiNs + "settingDesc");
var regionEl = settingDescEl.Element(Constants.TeiNs + "place")?.Element(Constants.TeiNs + "region");
discourse.Region = await GetDiscourseRegion(regionEl);
// Date
var settingEl = settingDescEl.Element(Constants.TeiNs + "setting");
discourse.Date = GetDiscourseDate(settingEl);
}
}
}
@@ -0,0 +1,233 @@
using System;
using System.Threading.Tasks;
using System.Xml.Linq;
using Gos.Core;
using Gos.Core.Entities;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.RequestHandlers.Corpus
{
public partial class ImportCorpusHandler
{
private async Task<SpeakerAge> GetSpeakerAge(XElement ageEl)
{
var age = ageEl?.Value;
var atLeast = ageEl?.Attribute("atLeast")?.Value;
var atMost = ageEl?.Attribute("atMost")?.Value;
var isRange = !string.IsNullOrEmpty(atLeast) || !string.IsNullOrEmpty(atMost);
if (string.IsNullOrEmpty(age) && !isRange || !string.IsNullOrEmpty(age) && age == "nedoločeno")
{
return await dbContext.SpeakerAges.SingleAsync(x => x.Id == (int)SpeakerAgeKeys.Neznano);
}
if (atMost == "10")
{
return await dbContext.SpeakerAges.SingleAsync(x => x.Id == (int)SpeakerAgeKeys.Do10Let);
}
if (atLeast == "10" && atMost == "14")
{
return await dbContext.SpeakerAges.SingleAsync(x => x.Id == (int)SpeakerAgeKeys.Od10Do14Let);
}
if (atLeast == "15" && atMost == "18")
{
return await dbContext.SpeakerAges.SingleAsync(x => x.Id == (int)SpeakerAgeKeys.Od15Do18Let);
}
if (atLeast == "19" && atMost == "24")
{
return await dbContext.SpeakerAges.SingleAsync(x => x.Id == (int)SpeakerAgeKeys.Od19Do24Let);
}
if (atLeast == "25" && atMost == "34")
{
return await dbContext.SpeakerAges.SingleAsync(x => x.Id == (int)SpeakerAgeKeys.Od25Do34Let);
}
if (atLeast == "35" && atMost == "59")
{
return await dbContext.SpeakerAges.SingleAsync(x => x.Id == (int)SpeakerAgeKeys.Od35Do59Let);
}
if (atLeast == "60")
{
return await dbContext.SpeakerAges.SingleAsync(x => x.Id == (int)SpeakerAgeKeys.Nad60Let);
}
throw new Exception($"Invalid speaker age {age}; atLeast {atLeast}, atMost {atMost}!");
}
private async Task<SpeakerEducation> GetSpeakerEducation(XElement educationEl)
{
var education = educationEl?.Value;
if (string.IsNullOrEmpty(education) || education == "nedoločno")
{
return await dbContext.SpeakerEducations.SingleAsync(x => x.Id == (int)SpeakerEducationKeys.Neznano);
}
switch (education)
{
case "OŠ ali manj":
return await dbContext.SpeakerEducations.SingleAsync(x => x.Id == (int)SpeakerEducationKeys.OsAliManj);
case "srednja šola":
return await dbContext.SpeakerEducations.SingleAsync(x => x.Id == (int)SpeakerEducationKeys.SrednjaSola);
case "višja ali visoka šola":
return await dbContext.SpeakerEducations.SingleAsync(x => x.Id == (int)SpeakerEducationKeys.VisjaAliVisokaSola);
case "fakulteta ali več":
return await dbContext.SpeakerEducations.SingleAsync(x => x.Id == (int)SpeakerEducationKeys.FakultetaAliVec);
default:
throw new Exception($"Invalid speaker education {education}!");
}
}
private async Task<SpeakerLanguage> GetSpeakerLanguage(XElement languageEl)
{
var language = languageEl?.Attribute("tag")?.Value;
if (string.IsNullOrEmpty(language))
{
return await dbContext.SpeakerLanguages.SingleAsync(x => x.Id == (int)SpeakerLanguageKeys.Neznano);
}
switch (language)
{
case "sl":
return await dbContext.SpeakerLanguages.SingleAsync(x => x.Id == (int)SpeakerLanguageKeys.Slovenscina);
case "en":
return await dbContext.SpeakerLanguages.SingleAsync(x => x.Id == (int)SpeakerLanguageKeys.Anglescina);
case "de":
return await dbContext.SpeakerLanguages.SingleAsync(x => x.Id == (int)SpeakerLanguageKeys.Nemscina);
case "it":
return await dbContext.SpeakerLanguages.SingleAsync(x => x.Id == (int)SpeakerLanguageKeys.Italijanscina);
case "zls":
case "sla":
return await dbContext.SpeakerLanguages.SingleAsync(x => x.Id == (int)SpeakerLanguageKeys.DrugiSlovanski);
case "roa":
return await dbContext.SpeakerLanguages.SingleAsync(x => x.Id == (int)SpeakerLanguageKeys.DrugiRomanski);
default:
throw new Exception($"Invalid speaker language {language}!");
}
}
private async Task<SpeakerRegion> GetSpeakerRegion(XElement residenceEl, int i)
{
var region = residenceEl?.Value;
if (string.IsNullOrEmpty(region))
{
return null;
}
var regions = region.Split(',');
if (i >= regions.Length)
{
return null;
}
region = regions[i].Trim();
switch (region)
{
case "CE":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Celjska);
case "GO":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Novogoriska);
case "KK":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Krska);
case "KP":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Koprska);
case "KR":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Kranjska);
case "LJ":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Ljubljanska);
case "MB":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Mariborska);
case "MS":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Murskosoboska);
case "NM":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Novomeska);
case "PO":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Postojnska);
case "SG":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Slovenjgraska);
case "Avstrija":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Avstrija);
case "Italija":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Italija);
case "Madzarska":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Madzarska);
case "tujina":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Tujina);
case "nedoločno":
return await dbContext.SpeakerRegions.SingleAsync(x => x.Id == (int)SpeakerRegionKeys.Neznano);
default:
throw new Exception($"Invalid speaker region {region}!");
}
}
private async Task<SpeakerSex> GetSpeakerSex(XElement personEl)
{
var sex = personEl.Attribute("sex")?.Value;
if (string.IsNullOrEmpty(sex) || sex == "-")
{
return await dbContext.SpeakerSexes.SingleAsync(x => x.Id == (int)SpeakerSexKeys.Neznano);
}
switch (sex)
{
case "M":
return await dbContext.SpeakerSexes.SingleAsync(x => x.Id == (int)SpeakerSexKeys.Moski);
case "F":
return await dbContext.SpeakerSexes.SingleAsync(x => x.Id == (int)SpeakerSexKeys.Zenski);
default:
throw new Exception($"Invalid speaker sex {sex}!");
}
}
private async Task ImportSpeaker(XElement personEl)
{
var code = personEl.Attribute(Constants.XmlNs + "id").Value;
var speaker = new Speaker
{
Code = code
};
// Sex
speaker.Sex = await GetSpeakerSex(personEl);
// Age
var ageEl = personEl.Element(Constants.TeiNs + "age");
speaker.Age = await GetSpeakerAge(ageEl);
// Region
var residenceEl = personEl.Element(Constants.TeiNs + "residence");
speaker.Region1 = await GetSpeakerRegion(residenceEl, 0);
speaker.Region2 = await GetSpeakerRegion(residenceEl, 1);
speaker.Region3 = await GetSpeakerRegion(residenceEl, 2);
// Education
var educationEl = personEl.Element(Constants.TeiNs + "education");
speaker.Education = await GetSpeakerEducation(educationEl);
// Language
var languageEl = personEl.Element(Constants.TeiNs + "langKnowledge")?.Element(Constants.TeiNs + "langKnown");
speaker.Language = await GetSpeakerLanguage(languageEl);
// Save
await dbContext.Speakers.AddAsync(speaker);
await dbContext.SaveChangesAsync();
}
private async Task ImportSpeakers(XElement listPersonEl)
{
foreach (var personEl in listPersonEl.Elements(Constants.TeiNs + "person"))
{
await ImportSpeaker(personEl);
}
}
}
}
@@ -0,0 +1,141 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Gos.Core;
using Gos.Core.Entities;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.RequestHandlers.Corpus
{
public partial class ImportCorpusHandler
{
private async Task ImportDiscourse(XElement discourseEl)
{
var discourse = new Discourse();
discourse.Code = discourseEl.Attribute(Constants.XmlNs + "id").Value;
await dbContext.Discourses.AddAsync(discourse);
// Header
var headerEl = discourseEl.Element(Constants.TeiNs + "teiHeader");
await ImportHeader(headerEl, discourse);
// Text
var textEl = discourseEl.Element(Constants.TeiNs + "text");
await ImportText(textEl, discourse);
// Save all data for single discourse
await dbContext.SaveChangesAsync();
}
private async Task ImportTextFile(string sourcePath)
{
using (var stream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
{
using (var xmlReader = XmlReader.Create(stream))
{
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "TEI" && xmlReader.NamespaceURI == Constants.TeiNamespace)
{
using (var discourseReader = xmlReader.ReadSubtree())
{
var discourseEl = XElement.Load(discourseReader);
await ImportDiscourse(discourseEl);
}
}
}
}
}
}
private async Task ImportText(XElement textEl, Discourse discourse)
{
var bodyEl = textEl.Element(Constants.TeiNs + "body");
// Loop through statements
var order = 0;
var discourseTokenOrder = new DiscourseTokenOrder();
foreach (var statementEl in bodyEl.Elements(Constants.TeiNs + "u"))
{
order++;
await ImportStatement(discourse, statementEl, order, discourseTokenOrder);
}
}
private async Task ImportStatement(Discourse discourse, XElement statementEl, int statementOrder, DiscourseTokenOrder discourseTokenOrder)
{
// Add statement
var statement = new Statement
{
Code = statementEl.Attribute(Constants.XmlNs + "id").Value,
Discourse = discourse,
Order = statementOrder,
Speaker = await GetSpeaker(statementEl),
};
await dbContext.Statements.AddAsync(statement);
// Loop through segments
var segmentOrder = 0;
foreach (var segEl in statementEl.Elements(Constants.TeiNs + "seg"))
{
segmentOrder++;
await ImportSegment(statement, segEl, segmentOrder, discourseTokenOrder);
}
}
private async Task ImportSegment(Statement statement, XElement segEl, int segmentOrder, DiscourseTokenOrder discourseTokenOrder)
{
// Add segment
var segment = new Segment()
{
Order = segmentOrder,
Statement = statement,
SoundFile = GetSoundFile(segEl),
};
await dbContext.Segments.AddAsync(segment);
// Get tokens
var tokens = segmentParser.GetTokens(segEl).ToList();
for (var i = 0; i < tokens.Count; i++)
{
discourseTokenOrder.Value += 1;
tokens[i].DiscourseOrder = discourseTokenOrder.Value;
tokens[i].Order = i + 1;
tokens[i].Segment = segment;
}
await dbContext.Tokens.AddRangeAsync(tokens);
}
private async Task<Speaker> GetSpeaker(XElement statementEl)
{
var who = statementEl.Attribute("who")?.Value;
if (string.IsNullOrEmpty(who))
{
return null;
}
var speakerCode = who.Substring(1);
return await dbContext.Speakers.SingleAsync(s => s.Code == speakerCode);
}
private string GetSoundFile(XElement segEl)
{
var synchAttr = segEl.Attribute("synch");
if (synchAttr == null || string.IsNullOrEmpty(synchAttr.Value))
{
return null;
}
return synchAttr.Value.Replace("#", "") + ".mp3";
}
private class DiscourseTokenOrder
{
public int Value { get; set; }
}
}
}
@@ -0,0 +1,77 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Gos.Core;
using Gos.ServiceModel.Requests.Corpus;
using Gos.Services.Framework;
using Gos.Services.Framework.Fragments;
using MediatR;
namespace Gos.Services.RequestHandlers.Corpus
{
public partial class ImportCorpusHandler : IRequestHandler<ImportCorpus>
{
private readonly GosDbContext dbContext;
private readonly IFragmentParser segmentParser;
public ImportCorpusHandler(GosDbContext dbContext, IFragmentParserFactory fragmentParserFactory)
{
this.dbContext = dbContext;
segmentParser = fragmentParserFactory.GetParser(FragmentType.Segment);
}
public async Task<Unit> Handle(ImportCorpus request, CancellationToken cancellationToken)
{
// Initialize database
await InitializeDatabase();
// Import data
await Import(request.SourcePath, cancellationToken);
return new Unit();
}
private async Task Import(string sourcePath, CancellationToken cancellationToken)
{
using (var stream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
{
var xmlDocument = await XDocument.LoadAsync(stream, LoadOptions.None, cancellationToken);
var corpusEl = xmlDocument.Element(Constants.TeiNs + "teiCorpus");
// teiHeader
var headerEl = corpusEl.Element(Constants.TeiNs + "teiHeader");
// profileDesc
var profileDescEl = headerEl.Element(Constants.TeiNs + "profileDesc");
// particDesc
var particDescEl = profileDescEl.Element(Constants.TeiNs + "particDesc");
// listPerson
var listPersonEl = particDescEl.Element(Constants.TeiNs + "listPerson");
// Import speakers
await ImportSpeakers(listPersonEl);
// Import texts
var sourceFolder = Path.GetDirectoryName(sourcePath);
foreach (var includeEl in corpusEl.Elements(Constants.IncludeNs + "include"))
{
var textFilePath = Path.Combine(sourceFolder, includeEl.Attribute("href")?.Value);
await ImportTextFile(textFilePath);
}
}
}
private async Task InitializeDatabase()
{
// Recreate database
await dbContext.Database.EnsureDeletedAsync();
await dbContext.Database.EnsureCreatedAsync();
// Seed data
await dbContext.SeedDataAsync();
}
}
}
@@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Gos.Core;
using Gos.Core.Entities;
using Gos.ServiceModel.Requests.Corpus;
using Gos.Services.Framework;
using Gos.Services.Framework.Fragments;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.RequestHandlers.Corpus
{
public class ImportCounterHandler : IRequestHandler<ImportCounters, Unit>
{
private readonly GosDbContext dbContext;
private readonly IFragmentParser segmentParser;
public ImportCounterHandler(GosDbContext dbContext, IFragmentParserFactory fragmentParserFactory)
{
this.dbContext = dbContext;
this.segmentParser = fragmentParserFactory.GetParser(FragmentType.Segment);
}
public async Task<Unit> Handle(ImportCounters request, CancellationToken cancellationToken)
{
// Create object for statistics
var stats = new Stats();
// Import data
await Import(request.SourcePath, stats, cancellationToken);
// Save statistics into database
await SaveStatistics(stats);
return new Unit();
}
private async Task Import(string sourcePath, Stats stats, CancellationToken cancellationToken)
{
using (var stream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
{
var xmlDocument = await XDocument.LoadAsync(stream, LoadOptions.None, cancellationToken);
var corpusEl = xmlDocument.Element(Constants.TeiNs + "teiCorpus");
// Import texts
var sourceFolder = Path.GetDirectoryName(sourcePath);
foreach (var includeEl in corpusEl.Elements(Constants.IncludeNs + "include"))
{
var textFilePath = Path.Combine(sourceFolder, includeEl.Attribute("href")?.Value);
await ImportTextFile(textFilePath, stats);
}
}
}
private async Task ImportTextFile(string sourcePath, Stats stats)
{
using (var stream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
{
using (var xmlReader = XmlReader.Create(stream))
{
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "TEI" && xmlReader.NamespaceURI == Constants.TeiNamespace)
{
using (var discourseReader = xmlReader.ReadSubtree())
{
var discourseEl = XElement.Load(discourseReader);
await ImportDiscourse(discourseEl, stats);
}
}
}
}
}
}
private async Task ImportDiscourse(XElement discourseEl, Stats stats)
{
stats.Discourses++;
// Text
var textEl = discourseEl.Element(Constants.TeiNs + "text");
await ImportText(textEl, stats);
}
private async Task ImportText(XElement textEl, Stats stats)
{
var bodyEl = textEl.Element(Constants.TeiNs + "body");
// Loop through statements
foreach (var statementEl in bodyEl.Elements(Constants.TeiNs + "u"))
{
await ImportStatement(statementEl, stats);
}
}
private async Task ImportStatement(XElement statementEl, Stats stats)
{
stats.Statements++;
foreach (var segEl in statementEl.Elements(Constants.TeiNs + "seg"))
{
// Get tokens for segment
var tokens = segmentParser.GetTokens(segEl);
foreach (var token in tokens)
{
stats.Words++;
if (!string.IsNullOrEmpty(token.StandardForm) && !string.IsNullOrEmpty(token.Lemma))
{
var standardForm = token.StandardForm.ToLower();
if (!stats.CorpusForms.ContainsKey(standardForm))
{
stats.CorpusForms.Add(standardForm, new HashSet<string>());
}
if (!stats.CorpusForms[standardForm].Contains(token.Lemma))
{
stats.CorpusForms[standardForm].Add(token.Lemma);
}
}
}
}
}
private async Task SaveStatistics(Stats stats)
{
// Save corpus forms
var forms = stats.CorpusForms.SelectMany(
x => x.Value.Select(
l => new CorpusForm
{
StandardForm = x.Key,
Lemma = l,
}))
.ToList();
await dbContext.Database.ExecuteSqlRawAsync($"TRUNCATE TABLE \"{nameof(dbContext.CorpusForms)}\"");
await dbContext.CorpusForms.AddRangeAsync(forms);
// Save global statistics
var counters = new CorpusCounter
{
Discourses = stats.Discourses,
Statements = stats.Statements,
Words = stats.Words,
};
await dbContext.Database.ExecuteSqlRawAsync($"TRUNCATE TABLE \"{nameof(dbContext.CorpusCounters)}\"");
await dbContext.CorpusCounters.AddAsync(counters);
// Save changes
await dbContext.SaveChangesAsync();
}
private class Stats
{
public IDictionary<string, HashSet<string>> CorpusForms = new Dictionary<string, HashSet<string>>();
public int Discourses { get; set; }
public int Statements { get; set; }
public int Words { get; set; }
}
}
}
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Gos.Core.Entities;
using Gos.ServiceModel.Requests.Corpus;
using Gos.Services.Framework;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.RequestHandlers.Corpus
{
public class ImportLexiconHandler : IRequestHandler<ImportLexicon, Unit>
{
private readonly GosDbContext dbContext;
public ImportLexiconHandler(GosDbContext dbContext)
{
this.dbContext = dbContext;
}
public async Task<Unit> Handle(ImportLexicon request, CancellationToken cancellationToken)
{
var sourcePath = request.SourcePath;
if (!File.Exists(sourcePath))
{
throw new FileNotFoundException($"File {sourcePath} not found!", sourcePath);
}
var data = ImportLexicon(sourcePath);
await SaveData(data);
return new Unit();
}
private string GetFeature(XElement element, string featName)
{
return element?.Elements("feat").SingleOrDefault(e => e.Attribute("att")?.Value == featName)?.Attribute("val")?.Value;
}
private void ImportEntry(XmlReader entryReader, Dictionary<string, HashSet<string>> data)
{
var entry = XDocument.Load(entryReader);
var entryEl = entry.Root;
// Skip if multiword
var partOfSpeech = GetFeature(entryEl, "besedna_vrsta");
if (!string.IsNullOrEmpty(partOfSpeech) && partOfSpeech == "večbesedna_enota")
{
return;
}
// Get lemma
var lemmaEl = entryEl.Element("Lemma");
var lemma = GetFeature(lemmaEl, "zapis_oblike");
// Add lemma
if (!data.ContainsKey(lemma))
{
data.Add(lemma, new HashSet<string>(StringComparer.Ordinal));
}
// Get forms
foreach (var wordFormEl in entryEl.Elements("WordForm"))
{
foreach (var representationEl in wordFormEl.Elements("FormRepresentation"))
{
var form = GetFeature(representationEl, "zapis_oblike");
if (!data[lemma].Contains(form))
{
data[lemma].Add(form);
}
}
}
}
private Dictionary<string, HashSet<string>> ImportLexicon(string sourcePath)
{
var items = new Dictionary<string, HashSet<string>>(StringComparer.Ordinal);
using var stream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read);
using var xmlReader = XmlReader.Create(stream);
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "LexicalEntry")
{
using var entryReader = xmlReader.ReadSubtree();
ImportEntry(entryReader, items);
}
}
return items;
}
private async Task SaveData(Dictionary<string, HashSet<string>> data)
{
// Get existing lemmas and forms
var existing = (await dbContext.CorpusForms.ToListAsync()).GroupBy(x => x.Lemma)
.ToDictionary(g => g.Key, g => g.Select(x => x.StandardForm).ToHashSet(StringComparer.Ordinal), StringComparer.Ordinal);
// Get lemmas and forms to add
var missing = new List<CorpusForm>();
foreach (var item in data)
{
var lemma = item.Key;
foreach (var form in item.Value)
{
if (!existing.ContainsKey(lemma) || !existing[lemma].Contains(form))
{
missing.Add(
new CorpusForm()
{
Lemma = lemma,
StandardForm = form
});
}
}
}
// Save to database in batches
await dbContext.CorpusForms.AddRangeAsync(missing);
await dbContext.SaveChangesAsync();
}
}
}
@@ -0,0 +1,101 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Gos.Core;
using Gos.Core.Entities;
using Gos.Core.Extensions;
using Gos.Core.Model;
using Gos.Core.Search;
using Gos.ServiceModel.Requests.Corpus;
using Gos.Services.Framework;
using Gos.Services.Framework.ConcordanceBuilder;
using Gos.Services.Framework.Fragments;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.RequestHandlers.Corpus
{
public class IndexCorpusHandler : IRequestHandler<IndexCorpus>
{
private readonly GosDbContext dbContext;
private readonly ISearchEngine searchEngine;
private readonly IConcordanceBuilder concordanceBuilder;
public IndexCorpusHandler(GosDbContext dbContext, ISearchEngine searchEngine, IConcordanceBuilder concordanceBuilder)
{
this.dbContext = dbContext;
this.searchEngine = searchEngine;
this.concordanceBuilder = concordanceBuilder;
}
public async Task<Unit> Handle(IndexCorpus request, CancellationToken cancellationToken)
{
// Recreate schema
await searchEngine.DeleteSchema();
await searchEngine.CreateSchema();
// Index
await Index();
// Commit changes
await searchEngine.Commit();
return new Unit();
}
private async Task Index()
{
// Loop through statements
var lastId = 0;
List<Statement> statements = null;
while ((statements = dbContext.Statements.AsNoTracking()
.Include(s => s.Discourse)
.Include(s => s.Discourse.Type)
.Include(s => s.Discourse.Channel)
.Include(s => s.Discourse.Event)
.Include(s => s.Discourse.Region)
.Include(s => s.Speaker)
.Include(s => s.Speaker.Age)
.Include(s => s.Speaker.Education)
.Include(s => s.Speaker.Language)
.Include(s => s.Speaker.Region1)
.Include(s => s.Speaker.Sex)
.Where(s => s.Id > lastId)
.OrderBy(s => s.Id)
.Take(5000)
.ToList()).Any())
{
await IndexStatements(statements);
lastId = statements[statements.Count - 1].Id;
}
}
private async Task IndexStatements(List<Statement> statements)
{
var batch = new List<Core.Model.Concordance>();
foreach (var statement in statements)
{
var tokens = await dbContext.Tokens.Include(t => t.Segment)
.Where(t => t.Segment.Statement.Id == statement.Id)
.OrderBy(t => t.Segment.Order)
.ThenBy(t => t.Order)
.ToListAsync();
var concordances = concordanceBuilder.GetConcordances(statement, tokens);
batch.AddRange(concordances);
if (batch.Count > 5000)
{
await searchEngine.Index(batch);
batch.Clear();
}
}
if (batch.Count > 0)
{
await searchEngine.Index(batch);
}
}
}
}
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Gos.Core.Search.Queries.List;
using Gos.ServiceModel.Requests.List;
using Gos.Services.Services.PartOfSpeechService;
namespace Gos.Services.RequestHandlers.List
{
public abstract class BaseListHandler
{
private readonly IPartOfSpeechService partOfSpeechService;
protected BaseListHandler(IPartOfSpeechService partOfSpeechService)
{
this.partOfSpeechService = partOfSpeechService;
}
protected async Task<List<ListSearchResponseItem>> GetResponseItems(List<ListQueryResultItem> items)
{
var convertedItems = new List<ListSearchResponseItem>();
foreach (var item in items)
{
var convertedItem = await GetResponseItem(item);
convertedItems.Add(convertedItem);
}
return convertedItems;
}
private async Task<ListSearchResponseItem> GetResponseItem(ListQueryResultItem item)
{
return new ListSearchResponseItem()
{
Frequency = item.Frequency,
ConversationalForm = item.ConversationalForm,
StandardForm = item.StandardForm,
Msd = item.Msd,
MsdDescription = await partOfSpeechService.GetMsdDescriptionByCode(item.Msd),
};
}
}
}
@@ -0,0 +1,83 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Gos.Core.Extensions;
using Gos.Core.Search;
using Gos.Core.Search.Queries.List;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Requests.List;
using Gos.ServiceModel.Requests.Shared;
using Gos.Services.Resources;
using Gos.Services.Search.QueryFactories;
using Gos.Services.Services.PartOfSpeechService;
using MediatR;
namespace Gos.Services.RequestHandlers.List
{
public class ListExportHandler : BaseListHandler, IRequestHandler<ListExport, ExportResponse>
{
private readonly IQueryFactory<ListExport, ListQuery> queryFactory;
private readonly ISearchEngine searchEngine;
public ListExportHandler(IPartOfSpeechService partOfSpeechService, IQueryFactory<ListExport, ListQuery> queryFactory, ISearchEngine searchEngine)
: base(partOfSpeechService)
{
this.queryFactory = queryFactory;
this.searchEngine = searchEngine;
}
public async Task<ExportResponse> Handle(ListExport request, CancellationToken cancellationToken)
{
// Get query
var query = await queryFactory.GetQuery(request);
// Get results
var results = searchEngine.Search<ListQuery, ListQueryResult>(query);
// Sort and page results
var items = (await GetResponseItems(results.Items)).AsQueryable()
.OrderBy(request.SortField, request.SortDirection == SortDirection.Descending)
.Take(request.Rows)
.ToList();
var stream = new MemoryStream();
using (var writer = new StreamWriter(stream, Encoding.Default, 1024, true))
{
// Write header
await writer.WriteAsync(ExportResource.ConversationalForm + "\t");
await writer.WriteAsync(ExportResource.Frequency + "\t");
await writer.WriteAsync(ExportResource.StandardizedForm);
if (request.GroupByMsd)
{
await writer.WriteAsync("\t" + ExportResource.Msd);
}
await writer.WriteLineAsync();
// Write items
foreach (var item in items)
{
await writer.WriteAsync(item.ConversationalForm + "\t");
await writer.WriteAsync(item.Frequency + "\t");
await writer.WriteAsync(item.StandardForm);
if (request.GroupByMsd)
{
await writer.WriteAsync("\t" + item.MsdDescription);
}
await writer.WriteLineAsync();
}
}
stream.Position = 0;
return new ExportResponse()
{
ContentType = "text/plain",
FileName = "export.txt",
Stream = stream,
};
}
}
}
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Gos.Core.Extensions;
using Gos.Core.Search;
using Gos.Core.Search.Queries.List;
using Gos.ServiceModel.Enums;
using Gos.ServiceModel.Requests.List;
using Gos.ServiceModel.Types;
using Gos.Services.Search.Aggregations;
using Gos.Services.Search.QueryFactories;
using Gos.Services.Services.PartOfSpeechService;
using MediatR;
namespace Gos.Services.RequestHandlers.List
{
public class ListSearchHandler : BaseListHandler, IRequestHandler<ListSearch, ListSearchResponse>
{
private readonly IAggregationProviderFactory aggregationProviderFactory;
private readonly IQueryFactory<ListSearch, ListQuery> queryFactory;
private readonly ISearchEngine searchEngine;
public ListSearchHandler(
IAggregationProviderFactory aggregationProviderFactory,
IPartOfSpeechService partOfSpeechService,
IQueryFactory<ListSearch, ListQuery> queryFactory,
ISearchEngine searchEngine)
: base(partOfSpeechService)
{
this.aggregationProviderFactory = aggregationProviderFactory;
this.queryFactory = queryFactory;
this.searchEngine = searchEngine;
}
public async Task<ListSearchResponse> Handle(ListSearch request, CancellationToken cancellationToken)
{
// Get query
var query = await queryFactory.GetQuery(request);
// Get results
var results = searchEngine.Search<ListQuery, ListQueryResult>(query);
// Sort and page results
var items = (await GetResponseItems(results.Items)).AsQueryable()
.OrderBy(request.SortField, request.SortDirection == SortDirection.Descending)
.Skip(request.From)
.Take(request.Size)
.ToList();
// Map results
return new ListSearchResponse()
{
Items = items,
Aggregations = new List<Aggregation>()
{
GetAggregation(AggregationType.Lemma, c => c.Lemmas?.Clear()),
GetAggregation(AggregationType.PartOfSpeech, c => c.PartOfSpeechIds?.Clear()),
GetAggregation(AggregationType.DiscourseType, c => c.DiscourseTypeIds?.Clear()),
GetAggregation(AggregationType.DiscourseChannel, c => c.DiscourseChannelIds?.Clear()),
GetAggregation(AggregationType.DiscourseRegion, c => c.DiscourseRegionIds?.Clear()),
GetAggregation(AggregationType.DiscourseYear, c => c.DiscourseYears?.Clear()),
GetAggregation(AggregationType.DiscourseEvent, c => c.DiscourseEventIds?.Clear()),
GetAggregation(AggregationType.SpeakerSex, c => c.SpeakerSexIds?.Clear()),
GetAggregation(AggregationType.SpeakerAge, c => c.SpeakerAgeIds?.Clear()),
GetAggregation(AggregationType.SpeakerRegion, c => c.SpeakerRegionIds?.Clear()),
GetAggregation(AggregationType.SpeakerEducation, c => c.SpeakerEducationIds?.Clear()),
GetAggregation(AggregationType.SpeakerLanguage, c => c.SpeakerLanguageIds?.Clear()),
},
Offset = request.From,
Total = results.Total,
};
Aggregation GetAggregation(AggregationType type, Action<ListQuery> modificationAction)
{
var clonedQuery = (ListQuery)query.Clone();
modificationAction(clonedQuery);
return aggregationProviderFactory.GetProvider(type).Get(clonedQuery);
}
}
}
}
@@ -0,0 +1,59 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Gos.ServiceModel.Requests.PartOfSpeech;
using Gos.Services.Framework;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Gos.Services.RequestHandlers.PartOfSpeech
{
public class GetPartOfSpeechHandler : IRequestHandler<GetPartOfSpeech, GetPartOfSpeechResponse>
{
private readonly GosDbContext dbContext;
public GetPartOfSpeechHandler(GosDbContext dbContext)
{
this.dbContext = dbContext;
}
public async Task<GetPartOfSpeechResponse> Handle(GetPartOfSpeech request, CancellationToken cancellationToken)
{
var partOfSpeech = await dbContext.PartOfSpeeches.Include(p => p.Translations)
.Include(p => p.Attributes)
.ThenInclude(a => a.Values)
.ThenInclude(v => v.Translations)
.Include(p => p.Attributes)
.ThenInclude(a => a.Translations)
.SingleOrDefaultAsync(p => p.Id == request.Id, cancellationToken);
if (partOfSpeech == null)
{
return null;
}
return new GetPartOfSpeechResponse()
{
Code = partOfSpeech.Code,
Title = partOfSpeech.Title,
Attributes = partOfSpeech.Attributes.Select(
a => new GetPartOfSpeechResponseAttribute()
{
RecordOrder = a.RecordOrder,
Title = a.Title,
Values = a.Values.Select(
v => new GetPartOfSpeechResponseAttributeValue()
{
Code = v.Code,
RecordOrder = v.RecordOrder,
Title = v.Title,
})
.OrderBy(v => v.RecordOrder)
.ToList(),
})
.OrderBy(a => a.RecordOrder)
.ToList(),
};
}
}
}
+216
View File
@@ -0,0 +1,216 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Gos.Services.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class ExportResource {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal ExportResource() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Gos.Services.Resources.ExportResource", typeof(ExportResource).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Pogovorni zapis.
/// </summary>
public static string ConversationalForm {
get {
return ResourceManager.GetString("ConversationalForm", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Kanal.
/// </summary>
public static string DiscourseChannel {
get {
return ResourceManager.GetString("DiscourseChannel", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Tip govornega dogodka.
/// </summary>
public static string DiscourseEvent {
get {
return ResourceManager.GetString("DiscourseEvent", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Regija snemanja.
/// </summary>
public static string DiscourseRegion {
get {
return ResourceManager.GetString("DiscourseRegion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Vir.
/// </summary>
public static string DiscourseSource {
get {
return ResourceManager.GetString("DiscourseSource", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Tip govora.
/// </summary>
public static string DiscourseType {
get {
return ResourceManager.GetString("DiscourseType", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Leto snemanja.
/// </summary>
public static string DiscourseYear {
get {
return ResourceManager.GetString("DiscourseYear", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Število pojavitev.
/// </summary>
public static string Frequency {
get {
return ResourceManager.GetString("Frequency", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Levo besedilo.
/// </summary>
public static string LeftContext {
get {
return ResourceManager.GetString("LeftContext", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Oblikoslovne lastnosti standardizirane oblike.
/// </summary>
public static string Msd {
get {
return ResourceManager.GetString("Msd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Desno besedilo.
/// </summary>
public static string RightContext {
get {
return ResourceManager.GetString("RightContext", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Starost govorca.
/// </summary>
public static string SpeakerAge {
get {
return ResourceManager.GetString("SpeakerAge", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Izobrazba govorca.
/// </summary>
public static string SpeakerEducation {
get {
return ResourceManager.GetString("SpeakerEducation", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Prvi jezik govorca.
/// </summary>
public static string SpeakerLanguage {
get {
return ResourceManager.GetString("SpeakerLanguage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Regija govorca.
/// </summary>
public static string SpeakerRegion {
get {
return ResourceManager.GetString("SpeakerRegion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Spol govorca.
/// </summary>
public static string SpeakerSex {
get {
return ResourceManager.GetString("SpeakerSex", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Standardizirana oblika.
/// </summary>
public static string StandardizedForm {
get {
return ResourceManager.GetString("StandardizedForm", resourceCulture);
}
}
}
}
+216
View File
@@ -0,0 +1,216 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Gos.Services.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class ExportResource_en {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal ExportResource_en() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Gos.Services.Resources.ExportResource.en", typeof(ExportResource_en).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Pronunciation-based spelling.
/// </summary>
public static string ConversationalForm {
get {
return ResourceManager.GetString("ConversationalForm", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Medium.
/// </summary>
public static string DiscourseChannel {
get {
return ResourceManager.GetString("DiscourseChannel", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Event type.
/// </summary>
public static string DiscourseEvent {
get {
return ResourceManager.GetString("DiscourseEvent", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Region.
/// </summary>
public static string DiscourseRegion {
get {
return ResourceManager.GetString("DiscourseRegion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Source.
/// </summary>
public static string DiscourseSource {
get {
return ResourceManager.GetString("DiscourseSource", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Discourse type.
/// </summary>
public static string DiscourseType {
get {
return ResourceManager.GetString("DiscourseType", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Year.
/// </summary>
public static string DiscourseYear {
get {
return ResourceManager.GetString("DiscourseYear", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Frequency.
/// </summary>
public static string Frequency {
get {
return ResourceManager.GetString("Frequency", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Left context.
/// </summary>
public static string LeftContext {
get {
return ResourceManager.GetString("LeftContext", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to POS-related characteristics of the word in the standardized form.
/// </summary>
public static string Msd {
get {
return ResourceManager.GetString("Msd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Right context.
/// </summary>
public static string RightContext {
get {
return ResourceManager.GetString("RightContext", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Age of the speaker.
/// </summary>
public static string SpeakerAge {
get {
return ResourceManager.GetString("SpeakerAge", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Education of the speaker.
/// </summary>
public static string SpeakerEducation {
get {
return ResourceManager.GetString("SpeakerEducation", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Speaker&apos;s first language.
/// </summary>
public static string SpeakerLanguage {
get {
return ResourceManager.GetString("SpeakerLanguage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Region of the speaker.
/// </summary>
public static string SpeakerRegion {
get {
return ResourceManager.GetString("SpeakerRegion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Gender of the speaker.
/// </summary>
public static string SpeakerSex {
get {
return ResourceManager.GetString("SpeakerSex", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Standardized form.
/// </summary>
public static string StandardizedForm {
get {
return ResourceManager.GetString("StandardizedForm", resourceCulture);
}
}
}
}
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DiscourseType" xml:space="preserve">
<value>Discourse type</value>
</data>
<data name="DiscourseChannel" xml:space="preserve">
<value>Medium</value>
</data>
<data name="DiscourseRegion" xml:space="preserve">
<value>Region</value>
</data>
<data name="DiscourseYear" xml:space="preserve">
<value>Year</value>
</data>
<data name="DiscourseEvent" xml:space="preserve">
<value>Event type</value>
</data>
<data name="SpeakerSex" xml:space="preserve">
<value>Gender of the speaker</value>
</data>
<data name="SpeakerAge" xml:space="preserve">
<value>Age of the speaker</value>
</data>
<data name="SpeakerRegion" xml:space="preserve">
<value>Region of the speaker</value>
</data>
<data name="SpeakerEducation" xml:space="preserve">
<value>Education of the speaker</value>
</data>
<data name="SpeakerLanguage" xml:space="preserve">
<value>Speaker's first language</value>
</data>
<data name="LeftContext" xml:space="preserve">
<value>Left context</value>
</data>
<data name="RightContext" xml:space="preserve">
<value>Right context</value>
</data>
<data name="StandardizedForm" xml:space="preserve">
<value>Standardized form</value>
</data>
<data name="DiscourseSource" xml:space="preserve">
<value>Source</value>
</data>
<data name="ConversationalForm" xml:space="preserve">
<value>Pronunciation-based spelling</value>
</data>
<data name="Frequency" xml:space="preserve">
<value>Frequency</value>
</data>
<data name="Msd" xml:space="preserve">
<value>POS-related characteristics of the word in the standardized form</value>
</data>
</root>
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DiscourseType" xml:space="preserve">
<value>Tip govora</value>
</data>
<data name="DiscourseChannel" xml:space="preserve">
<value>Kanal</value>
</data>
<data name="DiscourseEvent" xml:space="preserve">
<value>Tip govornega dogodka</value>
</data>
<data name="DiscourseRegion" xml:space="preserve">
<value>Regija snemanja</value>
</data>
<data name="DiscourseYear" xml:space="preserve">
<value>Leto snemanja</value>
</data>
<data name="SpeakerAge" xml:space="preserve">
<value>Starost govorca</value>
</data>
<data name="SpeakerEducation" xml:space="preserve">
<value>Izobrazba govorca</value>
</data>
<data name="SpeakerLanguage" xml:space="preserve">
<value>Prvi jezik govorca</value>
</data>
<data name="SpeakerRegion" xml:space="preserve">
<value>Regija govorca</value>
</data>
<data name="SpeakerSex" xml:space="preserve">
<value>Spol govorca</value>
</data>
<data name="LeftContext" xml:space="preserve">
<value>Levo besedilo</value>
</data>
<data name="RightContext" xml:space="preserve">
<value>Desno besedilo</value>
</data>
<data name="StandardizedForm" xml:space="preserve">
<value>Standardizirana oblika</value>
</data>
<data name="DiscourseSource" xml:space="preserve">
<value>Vir</value>
</data>
<data name="ConversationalForm" xml:space="preserve">
<value>Pogovorni zapis</value>
</data>
<data name="Frequency" xml:space="preserve">
<value>Število pojavitev</value>
</data>
<data name="Msd" xml:space="preserve">
<value>Oblikoslovne lastnosti standardizirane oblike</value>
</data>
</root>
@@ -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;
}
}
}

Some files were not shown because too many files have changed in this diff Show More