/// <summary> /// Gets the ordered tags by probability. /// </summary> /// <param name="words">The words.</param> /// <param name="tags">The tags.</param> /// <param name="index">The index.</param> /// <param name="tagProbs">The tag probs.</param> /// <returns>String[].</returns> /// <exception cref="System.NotSupportedException">This method can only be called if the classification model is an event model!</exception> public string[] GetOrderedTags(string[] words, string[] tags, int index, double[] tagProbs) { var posModel = modelPackage.MaxentModel; if (posModel != null) { var probs = posModel.Eval(ContextGenerator.GetContext(index, words, tags, null)); var orderedTags = new string[probs.Length]; for (int i = 0; i < probs.Length; i++) { int max = 0; for (int ti = 0; ti < probs.Length; ti++) { if (probs[ti] > probs[max]) { max = ti; } } orderedTags[i] = posModel.GetOutcome(max); if (tagProbs != null) { tagProbs[i] = probs[max]; } probs[max] = 0; } return(orderedTags); } throw new NotSupportedException("This method can only be called if the classification model is an event model!"); }
public void SaveChangesDoesntFail() { var sut = ContextGenerator.Generate <ITestContext>(); var res = sut.SaveChanges(); Assert.AreEqual(0, res); }
public void TestPropertiesCreated() { var sut = ContextGenerator.Generate <ITestContext>(); Assert.IsInstanceOf <InMemoryDbSet <Entity> >(sut.Entity1s); Assert.IsInstanceOf <InMemoryDbSet <Entity> >(sut.Entity2s); Assert.IsFalse(sut.Entity1s == sut.Entity2s); Assert.IsTrue(sut.Entity1s == sut.Entity1s); }
public BasicEventStream(DataStream ds, string sep) { separator = sep; cg = new BasicContextGenerator(separator); this.ds = ds; if (this.ds.hasNext()) { next_Renamed = createEvent((string)this.ds.nextToken()); } }
public async Task Authenticate_With_Valid_Should_Ok() { // Arrange var authenticationService = new AuthenticationService(await ContextGenerator.GetDummyContext()); // Act var user = authenticationService.Authenticate("admin", "admin"); // Assert Assert.Equal("admin", user.UserName); }
public async Task CreateTestRepoEmpty() { // setup var contextGenerator = new ContextGenerator(); // act var context = await contextGenerator.Create(string.Empty); // assert Assert.True(context.Thresholds.Count() == 5); }
public async Task Authenticate_InvalidUser_Should_Null() { // Arrange var authenticationService = new AuthenticationService(await ContextGenerator.GetDummyContext()); // Act var user = authenticationService.Authenticate("JohnDoe", "admin"); // Assert Assert.Null(user); }
public async Task CreateContextTest() { // setup var contextGenerator = new ContextGenerator(); // act var context = await contextGenerator.Create(gitRepoHelpers.RepoPath); // assert Assert.True(context.Thresholds.Count() == 5); Assert.True(context.AdditionPercentile.Count == 2); Assert.True(context.DeletionPercentile.Count == 1); }
public async Task GetContent_ShouldNull_NotExistingData_WhenNoResizing() { // Arrange var storageProviderMock = new Mock <IStorageProvider>(); storageProviderMock.Setup(x => x.Get(It.IsAny <string>())).Returns((byte[])null); var pictureService = new PictureService(await ContextGenerator.GetDummyContext(), storageProviderMock.Object); // Act var data = pictureService.GetContent(Guid.NewGuid()); // Assert Assert.Null(data); }
public async Task SavePicture_ShouldSave() { // Arrange var database = await ContextGenerator.GetDummyContext(); var user = database.Users.First(); var picture = Files.GetSimpleImage(); var pictureFileName = "test.jpg"; var pictureService = await GetPictureService(database); // Act var pictureId = pictureService.SavePicture(user.Id, pictureFileName, picture); // Assert Assert.NotEqual(default, pictureId);
public EditEventGenerator(IRSEnv env, IMessageBus messageBus, IDateUtils dateUtils, ContextGenerator contextGenerator, IThreading threading) : base(env, messageBus, dateUtils, threading) { _dateUtils = dateUtils; _contextGenerator = contextGenerator; _textEditorEvents = DTE.Events.TextEditorEvents; _textEditorEvents.LineChanged += TextEditorEvents_LineChanged; // TODO event happens before change is reflected... think about how to capture the // state *after* the change, e.g., by scheduling an artificial event or by attaching // this generator also to file save/close events }
public async Task GetContent_Unauthorized_ShouldNull() { // Arrange var database = await ContextGenerator.GetDummyContext(); var pictureService = await GetPictureService(database); var pictureId = database.Pictures.First().Id; var userId = database.Users.First(x => x.UserName == "user").Id; // Act var picture = pictureService.Get(userId, pictureId); // Assert Assert.Null(picture); }
public async Task GetContent_NotFound_ShouldNull() { // Arrange var database = await ContextGenerator.GetDummyContext(); var pictureService = await GetPictureService(database); var pictureId = Guid.NewGuid(); var userId = database.Users.First(x => x.UserName == "admin").Id; // Act var picture = pictureService.Get(userId, pictureId); // Assert Assert.Null(picture); }
public async Task GetContent_ShouldReturn_ExistingData() { // Arrange var existing = Files.GetSimpleImage(); var existingId = Guid.NewGuid(); var storageProviderMock = new Mock <IStorageProvider>(); storageProviderMock.Setup(x => x.Get($"{existingId}-50-40")).Returns(existing); var pictureService = new PictureService(await ContextGenerator.GetDummyContext(), storageProviderMock.Object); // Act var data = pictureService.GetContent(existingId, 50, 40); // Assert Assert.Equal(existing, data); }
public async Task GetContent_Happy_Flow() { // Arrange var database = await ContextGenerator.GetDummyContext(); var pictureService = await GetPictureService(database); var pictureId = database.Pictures.First().Id; var userId = database.Users.First(x => x.UserName == "admin").Id; // Act var picture = pictureService.Get(userId, pictureId); // Assert Assert.NotNull(picture); Assert.Equal(pictureId, picture.Id); }
static async Task Main(string[] args) { //TestProtobufSerialization(); var options = new DbContextOptionsBuilder <TestDBContext>() .UseInMemoryDatabase("Test") .Options; var writer = new DefaultFileGGDBFDataWriter(new DefaultGGDBFProtobufNetSerializer()); await using TestDBContext context = new(options); await context.Database.EnsureCreatedAsync(); await InitializeDatabase(context); ContextGenerator <TestContext> generator = new ContextGenerator <TestContext>(new EntityFrameworkGGDBFDataSource(context), writer); await generator.Generate(); //Reload the data await TestContext.Initialize(new FileGGDBFDataSource(new DefaultGGDBFProtobufNetSerializer())); if (TestContext.Instance.TestDatas.Values.Count() != 3) { throw new InvalidOperationException($"{nameof(TestModelType)} does not have expected entry count."); } if (TestContext.Instance.Test3DatasWithFK.Values.First().ModelId == null) { throw new InvalidOperationException($"{nameof(TestModelType3)} nav property key null."); } if (TestContext.Instance.Test3DatasWithFK.Values.First().Model == null) { throw new InvalidOperationException($"{nameof(TestModelType3)} nav property is null."); } if (TestContext.Instance.Test4Datas.Values.First().ModelCollection.Count() != 3) { throw new InvalidOperationException($"{nameof(TestModelType4)} collection nav property is invalid."); } }
/// <summary> /// Convert Abstract Syntax Tree to Virtual Machine object with associated virtual code for such machine /// </summary> /// <param name="ast">Abstract Syntax Tree.</param> /// <param name="request">Request used by user to perform convertion.</param> /// <returns>Object that allows evaluate next occurences</returns> private ConvertionResponse <IFireTimeEvaluator> Convert(RootScriptNode ast, ConvertionRequest <TMethodsAggregator> request) { var coretnessChecker = new RdlQueryValidator(Metdatas); var queryValidatorTraverser = new Traverser(coretnessChecker); ast.Accept(queryValidatorTraverser); if (!coretnessChecker.IsValid) { return(new ConvertionResponse <IFireTimeEvaluator>(null, coretnessChecker.Errors.ToArray())); } var contextChangeTracker = new Stack <bool>(); var scopeGenerator = new ContextGenerator(contextChangeTracker); var scopeTraverser = new ContextGeneratorTraverser(scopeGenerator, contextChangeTracker); ast.Accept(scopeTraverser); var codeGenerator = request.Debuggable ? new DebuggerSymbolGenerator(Metdatas, request.MethodsAggregator, MethodOccurences) : new CodeGenerator(Metdatas, request.MethodsAggregator, MethodOccurences); var codeGenerationTraverseVisitor = new ExtendedTraverser(codeGenerator, scopeGenerator.Scope.GetRootOfAllScopes()); ast.Accept(codeGenerationTraverseVisitor); IFireTimeEvaluator evaluator = codeGenerator.CreateVirtualMachine(request.CancellationToken); if (evaluator == null) { return(new ConvertionResponse <IFireTimeEvaluator>(null, coretnessChecker.Errors.ToArray())); } evaluator = new TimeZoneAdjuster(request.Source, evaluator); evaluator = new DaylightSavingTimeTracker(request.Source, evaluator); return(request.Source == request.Target ? new ConvertionResponse <IFireTimeEvaluator>(evaluator) : new ConvertionResponse <IFireTimeEvaluator>(new TimeZoneChangerDecorator(request.Source, request.Target, evaluator))); }
public static async Task Main(string[] args) { args = CheckArgs(args); IContextGenerator contextGenerator = new ContextGenerator(); var context = await contextGenerator.Create(args[0]); var repository = Repository.Discover(args[0]); var saveContextFilePath = args[0]; if (repository != null) { saveContextFilePath = new DirectoryInfo(repository).Parent.FullName; } // serialize the new context var filePath = Path.Combine(saveContextFilePath, "prquantifier.yaml"); context.SerializeToYaml(filePath); Console.WriteLine( $"Generate context for Repo located on '{saveContextFilePath}'" + $", context file located at {Path.Combine(Environment.CurrentDirectory, filePath)}"); }