|
@@ -8,78 +8,17 @@ namespace Yuuna.Contracts.Plugins
|
|
|
using Yuuna.Contracts.Interaction;
|
|
|
using Yuuna.Contracts.Optimization;
|
|
|
using Yuuna.Contracts.Patterns;
|
|
|
- using Yuuna.Contracts.Patterns.Cascade;
|
|
|
+ using Yuuna.Contracts.Artisan.Cascade;
|
|
|
using Yuuna.Contracts.Semantics;
|
|
|
using Yuuna.Contracts.TextSegmention;
|
|
|
-
|
|
|
- public delegate Response Invoke(IScore score);
|
|
|
- public delegate Response Incomplete(IScore score);
|
|
|
-
|
|
|
- public interface IInvokeCreator
|
|
|
- {
|
|
|
- IIncompleteCreator OnInvoke(Invoke invoke);
|
|
|
- }
|
|
|
-
|
|
|
- public interface IIncompleteCreator
|
|
|
- {
|
|
|
- void OnIncomplete(Incomplete incomplete);
|
|
|
- }
|
|
|
|
|
|
- public sealed class IncompleteCreator : Output<Incomplete>, IIncompleteCreator
|
|
|
- {
|
|
|
- public void OnIncomplete(Incomplete incomplete)
|
|
|
- {
|
|
|
- //if (incomplete is null)
|
|
|
- // throw new ArgumentNullException(nameof(incomplete));
|
|
|
- this.StoreData( incomplete);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public sealed class InvokeCreator : Pipeline<Invoke, IncompleteCreator>, IInvokeCreator
|
|
|
- {
|
|
|
- public IIncompleteCreator OnInvoke(Invoke invoke)
|
|
|
- {
|
|
|
- //if (invoke is null)
|
|
|
- // throw new ArgumentNullException(nameof(invoke));
|
|
|
-
|
|
|
- return this.StoreData(invoke);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public interface IGrammarCreator
|
|
|
- {
|
|
|
- IInvokeCreator Build(IGroup group, params IGroup[] rest);
|
|
|
- }
|
|
|
-
|
|
|
- public sealed class GrammarCreator : Pipeline<IGrammar, InvokeCreator>, IGrammarCreator
|
|
|
- {
|
|
|
- public IInvokeCreator Build(IGroup group, params IGroup[] rest)
|
|
|
- {
|
|
|
- //if (group is null)
|
|
|
- // throw new ArgumentNullException(nameof(group));
|
|
|
- var g = new Grammar();
|
|
|
- //g.Add(group);
|
|
|
- //if (rest != null)
|
|
|
- // foreach (var item in rest)
|
|
|
- // {
|
|
|
- // g.Add(item);
|
|
|
- // }
|
|
|
- //g.Immute();
|
|
|
-
|
|
|
- return this.StoreData( g);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
public abstract class PluginBase
|
|
|
{
|
|
|
- private readonly PatternBuilder _grammarSet;
|
|
|
-
|
|
|
+ private readonly PatternFactory _patternfactory;
|
|
|
|
|
|
public PluginBase()
|
|
|
{
|
|
|
- this._grammarSet = new PatternBuilder();
|
|
|
+ this._patternfactory = new PatternFactory();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -94,17 +33,17 @@ namespace Yuuna.Contracts.Plugins
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
this.BeforeInitialize(textSegmenter);
|
|
|
+
|
|
|
var groupManager = new GroupManager();
|
|
|
- this.BuildPatterns(groupManager, this._grammarSet);
|
|
|
+ this.BuildPatterns(groupManager, this._patternfactory );
|
|
|
textSegmenter.Load(groupManager);
|
|
|
this.AfterInitialize();
|
|
|
return true;
|
|
|
}
|
|
|
- catch
|
|
|
+ catch(Exception e)
|
|
|
{
|
|
|
+ Console.WriteLine(e);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -124,13 +63,13 @@ namespace Yuuna.Contracts.Plugins
|
|
|
protected abstract void BuildPatterns(IGroupManager g, IPatternBuilder p);
|
|
|
|
|
|
internal IImmutableList<IScore> Evaluate(StrategyBase strategy, IImmutableList<string> cutted)
|
|
|
- {
|
|
|
- return strategy.Assess(this, cutted, this._grammarSet);
|
|
|
+ {
|
|
|
+ return strategy.Assess(this, cutted, this._patternfactory);
|
|
|
}
|
|
|
|
|
|
- internal Behaviour SelectBest(IScore score)
|
|
|
+ internal Invoke SelectBest(IScore score)
|
|
|
{
|
|
|
- return this._grammarSet.TryGet(score.Contrast, out var b) ? b : null;
|
|
|
+ return this._patternfactory.TryGet(score.Contrast, out var b) ? b : null;
|
|
|
}
|
|
|
}
|
|
|
|