public async Task <DbFeature> InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { _logger.LogInformation("Persisting feature {FeatureTitle} version {Version} for product {ProductName} and group {GroupName}", feature.Title, version, productName, groupName); var hash = feature.CalculateHash(); DbFeature dbFeature; using (var session = _storeProvider.Store.OpenAsyncSession()) { dbFeature = await session.LoadAsync <DbFeature>(DbFeatureExtensions.GetIdentifier(productName, groupName, feature.Title, hash)); if (dbFeature != null) { // Add the new version to the list var versions = new List <string>(dbFeature.Versions); versions.Add(version); // Prevent duplicates dbFeature.Versions = versions.Distinct().ToArray(); } else { // Create a new feature var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); } await session.SaveChangesAsync(); } return(dbFeature); }
/// <summary> /// Gets the feature that matches the provided criteria. /// </summary> /// <param name="productName">The name of the product under which the feature is positioned.</param> /// <param name="groupName">The name of the group under which the feature is positioned.</param> /// <param name="title">The title of the feature.</param> /// <param name="version">Version of the feature to retrieve.</param> /// <returns> /// A <see cref="DisplayableFeature"/> instance describing the requested feature; /// or <c>null</c> if the feature cannot be found. /// </returns> public async Task <DisplayableFeature> GetFeatureAsync(string productName, string groupName, string title, string version) { using (var session = _storeProvider.Store.OpenAsyncSession()) { var dbFeature = await session.Query <Features_ByTitleProductAndGroup.QueryModel, Features_ByTitleProductAndGroup>() .Where(feature => feature.Product == productName && feature.Group == groupName && feature.Title == title && feature.Version == version) .OfType <DbFeature>() .SingleOrDefaultAsync(); if (dbFeature == null) { return(null); } var result = new DisplayableFeature(dbFeature); result.TestResult = dbFeature.TestResult; result.Version = version; // Process the server tags var processor = new FeatureProcessor(); processor.Process(result); return(result); } }
public async Task InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); DbFeature dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); var configuration = await ConfigurationManager.GetOrCreateConfigurationAsync(); using (var session = Database.DocumentStore.OpenAsyncSession()) { // Using the store method when the feature already exists in the database will override it completely, this is acceptable await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); if (configuration.ExpirationEnabled && Regex.IsMatch(version, configuration.ExpirationRegex)) { // Set the expiration in the metadata session.Advanced.GetMetadataFor(dbFeature)["Raven-Expiration-Date"] = new RavenJValue(DateTime.UtcNow.Date.AddDays(configuration.ExpirationDays)); } await session.SaveChangesAsync(); } }
public void Save(BinarySerializer writer) { writer.WriteString(Description); FeatureProcessor.Save(writer); writer.WriteObject(BowSpace); writer.WriteObject(Model); writer.WriteBool(IsTrained); }
public Prediction <LblT> Predict(string example) { Preconditions.CheckState(IsTrained); example = FeatureProcessor.Run(example); SparseVector <double> vector = BowSpace.ProcessDocument(example); return(Model.Predict(vector)); }
public async Task InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); DbFeature dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); using (var session = Database.DocumentStore.OpenAsyncSession()) { // Using the store method when the feature already exists in the database will override it completely, this is acceptable await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); await session.SaveChangesAsync(); } }
/// <summary> /// Gets the feature that matches the provided criteria. /// </summary> /// <param name="productName">The name of the product under which the feature is positioned.</param> /// <param name="groupName">The name of the group under which the feature is positioned.</param> /// <param name="title">The title of the feature.</param> /// <param name="version">Version of the feature to retrieve.</param> /// <returns> /// A <see cref="DisplayableFeature"/> instance describing the requested feature; /// or <c>null</c> if the feature cannot be found. /// </returns> public async Task <DisplayableFeature> GetFeatureAsync(string productName, string groupName, string title, string version) { using (var session = Database.DocumentStore.OpenAsyncSession()) { var dbFeature = await session.LoadAsync <DbFeature>(DbFeatureExtensions.GetIdentifier(productName, groupName, title, version)); if (dbFeature == null) { return(null); } var result = new DisplayableFeature(dbFeature); result.TestResult = dbFeature.TestResult; result.Version = dbFeature.Version; // Process the server tags var processor = new FeatureProcessor(); processor.Process(result); return(result); } }
public void Train(ILabeledExampleCollection <LblT, string> dataset) { Preconditions.CheckState(!IsTrained); Preconditions.CheckNotNull(dataset); Preconditions.CheckNotNull(BowSpace); Preconditions.CheckNotNull(FeatureProcessor); Preconditions.CheckNotNull(Model); // preprocess the text foreach (LabeledExample <LblT, string> le in dataset) { le.Example = FeatureProcessor.Run(le.Example); } // bow vectors List <SparseVector <double> > bowData = BowSpace is DeltaBowSpace <LblT> ?(BowSpace as DeltaBowSpace <LblT>).Initialize(dataset as ILabeledDataset <LblT, string> ?? new LabeledDataset <LblT, string>(dataset)) : BowSpace.Initialize(dataset.Select(d => d.Example)); var bowDataset = new LabeledDataset <LblT, SparseVector <double> >(); for (int i = 0; i < bowData.Count; i++) { bowDataset.Add(dataset[i].Label, bowData[i]); } // train if (OnTrainModel == null) { Model.Train(bowDataset); } else { OnTrainModel(this, bowDataset); } IsTrained = true; }
public async Task <DbFeature> InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { _logger.LogInformation("Persisting feature {FeatureTitle} version {Version} for product {ProductName} and group {GroupName}", feature.Title, version, productName, groupName); var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); DbFeature dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); var configuration = await _configurationManager.GetOrCreateConfigurationAsync(); using (var session = _storeProvider.Store.OpenAsyncSession()) { // Using the store method when the feature already exists in the database will override it completely, this is acceptable await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); session.SetExpirationAccordingToConfiguration(dbFeature, version, configuration); await session.SaveChangesAsync(); } return(dbFeature); }
/// <summary> /// Provides a vector of features for a given item. /// </summary> /// <param name="featureSource">The parameter is not used.</param> /// <param name="item">The item to provide features for.</param> /// <returns>The feature vector for <paramref name="item"/>.</returns> public Vector GetItemFeatures(NoFeatureSource featureSource, Movie item) { return(FeatureProcessor.ProcessFeatures(item.Year, item.Genres)); }
public async Task <IEnumerable <string> > GetAsync(string branchName) { return(FeatureProcessor.RemoveServerTags(await _productManager.GetTagsAsync(branchName))); }
/// <summary> /// Gets the feature that matches the provided criteria. /// </summary> /// <param name="productName">The name of the product under which the feature is positioned.</param> /// <param name="groupName">The name of the group under which the feature is positioned.</param> /// <param name="title">The title of the feature.</param> /// <param name="version">Version of the feature to retrieve.</param> /// <returns> /// A <see cref="DisplayableFeature"/> instance describing the requested feature; /// or <c>null</c> if the feature cannot be found. /// </returns> public async Task<DisplayableFeature> GetFeatureAsync(string productName, string groupName, string title, string version) { using (var session = Database.DocumentStore.OpenAsyncSession()) { var dbFeature = await session.LoadAsync<DbFeature>(DbFeatureExtensions.GetIdentifier(productName, groupName, title, version)); if (dbFeature == null) { return null; } var result = new DisplayableFeature(dbFeature); result.TestResult = dbFeature.TestResult; result.Version = dbFeature.Version; // Process the server tags var processor = new FeatureProcessor(); processor.Process(result); return result; } }