Skip to content

Commit 5a0553c

Browse files
committed
Update modules
1 parent e072f67 commit 5a0553c

File tree

11 files changed

+43
-36
lines changed

11 files changed

+43
-36
lines changed

src/Sentiment/Wikiled.Sentiment.Analysis/Containers/SentimentMainModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public IServiceCollection ConfigureServices(IServiceCollection services)
6262
.AddFactory<ITextSplitter, ITextSplitter>();
6363

6464
services.AddTransient<IProcessingPipeline, ProcessingPipeline>();
65-
services.AddTransient<Func<string, ITestingClient>>(ctx => path => new TestingClient(ctx.GetService<IClientContext>(), path));
66-
services.AddTransient<Func<string, ITrainingClient>>(ctx => path => new TrainingClient(ctx.GetService<IClientContext>(), path));
65+
services.AddTransient<ITestingClient, TestingClient>();
66+
services.AddTransient<ITrainingClient, TrainingClient>();
6767

6868
services.AddScoped<SessionContext>().As<ISessionContext, SessionContext>();
6969
services.AddScoped<IContextWordsHandler, ContextWordsDataLoader>();

src/Sentiment/Wikiled.Sentiment.Analysis/Containers/SessionContainer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ public ITextSplitter GetTextSplitter()
2525

2626
public ITestingClient GetTesting(string path = null)
2727
{
28-
return scope.ServiceProvider.GetService<Func<string, ITestingClient>>()(path);
28+
Context.SvmPath = path;
29+
return scope.ServiceProvider.GetService<ITestingClient>();
2930
}
3031

3132
public ITrainingClient GetTraining(string path)
3233
{
33-
return scope.ServiceProvider.GetService<Func<string, ITrainingClient>>()(path);
34+
Context.SvmPath = path;
35+
return scope.ServiceProvider.GetService<ITrainingClient>();
3436
}
3537

3638
public T Resolve<T>()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Wikiled.Sentiment.Analysis.Processing
6+
{
7+
public class IClientFactory
8+
{
9+
}
10+
}

src/Sentiment/Wikiled.Sentiment.Analysis/Processing/ITestingClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public interface ITestingClient
3333

3434
SentimentVector SentimentVector { get; }
3535

36-
string SvmPath { get; }
37-
3836
bool TrackArff { get; set; }
3937

4038
bool UseBagOfWords { get; set; }

src/Sentiment/Wikiled.Sentiment.Analysis/Processing/TestingClient.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
using System.IO;
44
using System.Reactive.Linq;
55
using System.Threading;
6-
using System.Threading.Tasks;
76
using System.Xml.Linq;
87
using Wikiled.Arff.Extensions;
98
using Wikiled.Arff.Logic;
109
using Wikiled.Common.Extensions;
11-
using Wikiled.Common.Logging;
1210
using Wikiled.Common.Serialization;
1311
using Wikiled.MachineLearning.Mathematics;
1412
using Wikiled.MachineLearning.Mathematics.Vectors.Serialization;
@@ -30,7 +28,7 @@ namespace Wikiled.Sentiment.Analysis.Processing
3028
{
3129
public class TestingClient : ITestingClient
3230
{
33-
private static readonly ILogger log = ApplicationLogging.CreateLogger<TestingClient>();
31+
private readonly ILogger<TestingClient > log;
3432

3533
private readonly IDocumentFromReviewFactory documentFromReview = new DocumentFromReviewFactory();
3634

@@ -44,15 +42,20 @@ public class TestingClient : ITestingClient
4442

4543
private readonly IClientContext clientContext;
4644

47-
public TestingClient(IClientContext clientContext, string svmPath = null)
45+
public TestingClient(ILogger<TestingClient> log, IClientContext clientContext)
4846
{
49-
if (string.IsNullOrEmpty(svmPath))
47+
if (log == null)
48+
{
49+
throw new ArgumentNullException(nameof(log));
50+
}
51+
52+
if (string.IsNullOrEmpty(clientContext.Context.SvmPath))
5053
{
5154
DisableSvm = true;
5255
}
5356

5457
this.clientContext = clientContext ?? throw new ArgumentNullException(nameof(clientContext));
55-
SvmPath = svmPath;
58+
this.log = log;
5659
AspectSentiment = new AspectSentimentTracker(new ContextSentimentFactory());
5760
SentimentVector = new SentimentVector();
5861
}
@@ -89,8 +92,6 @@ public bool UseBuiltInSentiment
8992

9093
public SentimentVector SentimentVector { get; }
9194

92-
public string SvmPath { get; }
93-
9495
public bool UseBagOfWords { get; set; }
9596

9697
public bool TrackArff { get; set; }
@@ -102,7 +103,7 @@ public string GetPerformanceDescription()
102103

103104
public void Init()
104105
{
105-
MachineSentiment = DisableSvm ? new NullMachineSentiment() : Text.MachineLearning.MachineSentiment.Load(SvmPath);
106+
MachineSentiment = DisableSvm ? new NullMachineSentiment() : Text.MachineLearning.MachineSentiment.Load(clientContext.Context.SvmPath);
106107
if (TrackArff)
107108
{
108109
arff = ArffDataSet.Create<PositivityType>("MAIN");
@@ -114,9 +115,9 @@ public void Init()
114115

115116
log.LogInformation("Track ARFF: {0}", TrackArff);
116117
if (!DisableAspects &&
117-
(!string.IsNullOrEmpty(AspectPath) || !string.IsNullOrEmpty(SvmPath)))
118+
(!string.IsNullOrEmpty(AspectPath) || !string.IsNullOrEmpty(clientContext.Context.SvmPath)))
118119
{
119-
var path = string.IsNullOrEmpty(AspectPath) ? Path.Combine(SvmPath, "aspects.xml") : AspectPath;
120+
var path = string.IsNullOrEmpty(AspectPath) ? Path.Combine(clientContext.Context.SvmPath, "aspects.xml") : AspectPath;
120121
if (File.Exists(path))
121122
{
122123
log.LogInformation("Loading {0} aspects", path);

src/Sentiment/Wikiled.Sentiment.Analysis/Processing/TrainingClient.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Xml.Linq;
88
using Wikiled.Arff.Extensions;
99
using Wikiled.Arff.Logic;
10-
using Wikiled.Common.Logging;
1110
using Wikiled.MachineLearning.Mathematics.Vectors.Serialization;
1211
using Wikiled.MachineLearning.Normalization;
1312
using Wikiled.Sentiment.Analysis.Arff;
@@ -23,29 +22,27 @@ namespace Wikiled.Sentiment.Analysis.Processing
2322
{
2423
public class TrainingClient : ITrainingClient
2524
{
26-
private static readonly ILogger log = ApplicationLogging.CreateLogger<TrainingClient>();
25+
private readonly ILogger<TrainingClient> log;
2726

2827
private readonly AnalyseReviews analyze;
2928

3029
private readonly MainAspectHandler featureExtractor;
3130

3231
private readonly SentimentVector sentimentVector;
3332

34-
private readonly string svmPath;
35-
3633
private IProcessArff arffProcess;
3734

3835
private readonly IClientContext clientContext;
3936

40-
public TrainingClient(IClientContext clientContext, string svmPath)
37+
public TrainingClient(ILogger<TrainingClient> log, IClientContext clientContext)
4138
{
42-
if (string.IsNullOrEmpty(svmPath))
39+
this.clientContext = clientContext ?? throw new ArgumentNullException(nameof(clientContext));
40+
if (string.IsNullOrEmpty(clientContext.Context.SvmPath))
4341
{
44-
throw new ArgumentException("Value cannot be null or empty.", nameof(svmPath));
42+
throw new ArgumentException("Value cannot be null or empty.", nameof(clientContext.Context.SvmPath));
4543
}
46-
47-
this.svmPath = svmPath;
48-
this.clientContext = clientContext ?? throw new ArgumentNullException(nameof(clientContext));
44+
45+
this.log = log ?? throw new ArgumentNullException(nameof(log));
4946
SentimentVector = new SentimentVector();
5047
analyze = new AnalyseReviews();
5148
featureExtractor = new MainAspectHandler(new AspectContextFactory());
@@ -72,7 +69,7 @@ public ISentimentDataHolder Lexicon
7269

7370
public async Task Train(IObservable<IParsedDocumentHolder> reviews)
7471
{
75-
analyze.SvmPath = svmPath;
72+
analyze.SvmPath = clientContext.Context.SvmPath;
7673
analyze.InitEnvironment();
7774
log.LogInformation("Starting Training...");
7875
using (Observable.Interval(TimeSpan.FromSeconds(30)).Subscribe(item => log.LogInformation(clientContext.Pipeline.Monitor.ToString())))

src/Sentiment/Wikiled.Sentiment.TestLogic.Shared/Wikiled.Sentiment.TestLogic.Shared.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,5 @@
3535
<ProjectReference Include="..\Wikiled.Sentiment.Text\Wikiled.Sentiment.Text.csproj" />
3636
</ItemGroup>
3737

38-
<ItemGroup>
39-
<Reference Include="Microsoft.Extensions.Logging.Debug">
40-
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.logging.debug\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Debug.dll</HintPath>
41-
</Reference>
42-
</ItemGroup>
4338

4439
</Project>

src/Sentiment/Wikiled.Sentiment.Text.Tests/Parser/LexiconLoaderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void CheckArguments()
5858

5959
private LexiconLoader CreateInstance()
6060
{
61-
return new LexiconLoader(new NullLogger<ContextWordsDataLoader>());
61+
return new LexiconLoader(new NullLogger<LexiconLoader>());
6262
}
6363
}
6464
}

src/Sentiment/Wikiled.Sentiment.Text/Configuration/ISessionContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public interface ISessionContext
1414
bool DisableInvertors { get; }
1515

1616
ISentimentDataHolder Lexicon { get; }
17+
18+
string SvmPath { get; }
1719
}
1820
}

src/Sentiment/Wikiled.Sentiment.Text/Configuration/SessionContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public SessionContext()
2424

2525
public IAspectDectector Aspect => aspect ?? nullDetector;
2626

27+
public string SvmPath { get; set; }
28+
2729
public bool DisableFeatureSentiment
2830
{
2931
get => disableFeatureSentiment;

0 commit comments

Comments
 (0)