Added enums to JSONEntity and JSONDatapoint
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Shared.Models;
|
||||
|
||||
namespace Server.Exceptions;
|
||||
|
||||
public class ProbMethodNotFoundException(string probMethod) : Exception($"Unknown probMethod name {probMethod}") { }
|
||||
public class ProbMethodNotFoundException(ProbMethodEnum probMethod) : Exception($"Unknown probMethod name {probMethod}") { }
|
||||
|
||||
public class SimilarityMethodNotFoundException(string similarityMethod) : Exception($"Unknown similarityMethod name \"{similarityMethod}\"") { }
|
||||
public class SimilarityMethodNotFoundException(SimilarityMethodEnum similarityMethod) : Exception($"Unknown similarityMethod name \"{similarityMethod}\"") { }
|
||||
|
||||
public class JSONPathSelectionException(string path, string testedContent) : Exception($"Unable to select tokens using JSONPath {path} for string: {testedContent}.") { }
|
||||
@@ -38,12 +38,12 @@ public class DatabaseHelper(ILogger<DatabaseHelper> logger)
|
||||
return helper.ExecuteSQLCommandGetInsertedID("INSERT INTO searchdomain (name, settings) VALUES (@name, @settings)", parameters);
|
||||
}
|
||||
|
||||
public static int DatabaseInsertEntity(SQLHelper helper, string name, string probmethod, int id_searchdomain)
|
||||
public static int DatabaseInsertEntity(SQLHelper helper, string name, ProbMethodEnum probmethod, int id_searchdomain)
|
||||
{
|
||||
Dictionary<string, dynamic> parameters = new()
|
||||
{
|
||||
{ "name", name },
|
||||
{ "probmethod", probmethod },
|
||||
{ "probmethod", probmethod.ToString() },
|
||||
{ "id_searchdomain", id_searchdomain }
|
||||
};
|
||||
return helper.ExecuteSQLCommandGetInsertedID("INSERT INTO entity (name, probmethod, id_searchdomain) VALUES (@name, @probmethod, @id_searchdomain)", parameters);
|
||||
@@ -60,13 +60,13 @@ public class DatabaseHelper(ILogger<DatabaseHelper> logger)
|
||||
return helper.ExecuteSQLCommandGetInsertedID("INSERT INTO attribute (attribute, value, id_entity) VALUES (@attribute, @value, @id_entity)", parameters);
|
||||
}
|
||||
|
||||
public static int DatabaseInsertDatapoint(SQLHelper helper, string name, string probmethod_embedding, string similarityMethod, string hash, int id_entity)
|
||||
public static int DatabaseInsertDatapoint(SQLHelper helper, string name, ProbMethodEnum probmethod_embedding, SimilarityMethodEnum similarityMethod, string hash, int id_entity)
|
||||
{
|
||||
Dictionary<string, dynamic> parameters = new()
|
||||
{
|
||||
{ "name", name },
|
||||
{ "probmethod_embedding", probmethod_embedding },
|
||||
{ "similaritymethod", similarityMethod },
|
||||
{ "probmethod_embedding", probmethod_embedding.ToString() },
|
||||
{ "similaritymethod", similarityMethod.ToString() },
|
||||
{ "hash", hash },
|
||||
{ "id_entity", id_entity }
|
||||
};
|
||||
|
||||
@@ -179,13 +179,13 @@ public class SearchdomainHelper(ILogger<SearchdomainHelper> logger, DatabaseHelp
|
||||
preexistingEntity.datapoints.Add(newDatapoint);
|
||||
|
||||
}
|
||||
if (newEntityDatapoint is not null && (newEntityDatapoint.Probmethod_embedding != datapoint.probMethod.name || newEntityDatapoint.SimilarityMethod != datapoint.similarityMethod.name))
|
||||
if (newEntityDatapoint is not null && (newEntityDatapoint.Probmethod_embedding != datapoint.probMethod.probMethodEnum || newEntityDatapoint.SimilarityMethod != datapoint.similarityMethod.similarityMethodEnum))
|
||||
{
|
||||
// Datapoint - Updated (probmethod or similaritymethod)
|
||||
Dictionary<string, dynamic> parameters = new()
|
||||
{
|
||||
{ "probmethod", newEntityDatapoint.Probmethod_embedding },
|
||||
{ "similaritymethod", newEntityDatapoint.SimilarityMethod },
|
||||
{ "probmethod", newEntityDatapoint.Probmethod_embedding.ToString() },
|
||||
{ "similaritymethod", newEntityDatapoint.SimilarityMethod.ToString() },
|
||||
{ "datapointName", datapoint.name },
|
||||
{ "entityId", preexistingEntityID}
|
||||
};
|
||||
@@ -227,7 +227,7 @@ public class SearchdomainHelper(ILogger<SearchdomainHelper> logger, DatabaseHelp
|
||||
}
|
||||
|
||||
var probMethod = Probmethods.GetMethod(jsonEntity.Probmethod) ?? throw new ProbMethodNotFoundException(jsonEntity.Probmethod);
|
||||
Entity entity = new(jsonEntity.Attributes, probMethod, jsonEntity.Probmethod, datapoints, jsonEntity.Name)
|
||||
Entity entity = new(jsonEntity.Attributes, probMethod, jsonEntity.Probmethod.ToString(), datapoints, jsonEntity.Name)
|
||||
{
|
||||
id = id_entity
|
||||
};
|
||||
|
||||
@@ -1,37 +1,29 @@
|
||||
using System.Text.Json;
|
||||
using Server.Exceptions;
|
||||
using Shared.Models;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public class ProbMethod
|
||||
{
|
||||
public Probmethods.probMethodDelegate method;
|
||||
public ProbMethodEnum probMethodEnum;
|
||||
public string name;
|
||||
|
||||
public ProbMethod(string name, ILogger logger)
|
||||
public ProbMethod(ProbMethodEnum probMethodEnum, ILogger logger)
|
||||
{
|
||||
this.name = name;
|
||||
this.probMethodEnum = probMethodEnum;
|
||||
this.name = probMethodEnum.ToString();
|
||||
Probmethods.probMethodDelegate? probMethod = Probmethods.GetMethod(name);
|
||||
if (probMethod is null)
|
||||
{
|
||||
logger.LogError("Unable to retrieve probMethod {name}", [name]);
|
||||
throw new ProbMethodNotFoundException(name);
|
||||
throw new ProbMethodNotFoundException(probMethodEnum);
|
||||
}
|
||||
method = probMethod;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ProbMethodEnum
|
||||
{
|
||||
Mean,
|
||||
HarmonicMean,
|
||||
QuadraticMean,
|
||||
GeometricMean,
|
||||
EVEWAvg,
|
||||
HVEWAvg,
|
||||
LVEWAvg,
|
||||
DictionaryWeightedAverage
|
||||
}
|
||||
|
||||
public static class Probmethods
|
||||
{
|
||||
@@ -54,6 +46,11 @@ public static class Probmethods
|
||||
};
|
||||
}
|
||||
|
||||
public static probMethodDelegate? GetMethod(ProbMethodEnum probMethodEnum)
|
||||
{
|
||||
return GetMethod(probMethodEnum.ToString());
|
||||
}
|
||||
|
||||
public static probMethodDelegate? GetMethod(string name)
|
||||
{
|
||||
string methodName = name;
|
||||
|
||||
@@ -8,12 +8,19 @@ using Server.HealthChecks;
|
||||
using Server.Helper;
|
||||
using Server.Models;
|
||||
using Server.Services;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddControllersWithViews()
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.Converters.Add(
|
||||
new JsonStringEnumConverter()
|
||||
);
|
||||
});
|
||||
|
||||
// Add Localization
|
||||
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
|
||||
|
||||
@@ -96,8 +96,16 @@ public class Searchdomain
|
||||
string probmethodString = datapointReader.GetString(3);
|
||||
string similarityMethodString = datapointReader.GetString(4);
|
||||
string hash = datapointReader.GetString(5);
|
||||
ProbMethod probmethod = new(probmethodString, _logger);
|
||||
SimilarityMethod similarityMethod = new(similarityMethodString, _logger);
|
||||
ProbMethodEnum probmethodEnum = (ProbMethodEnum)Enum.Parse(
|
||||
typeof(ProbMethodEnum),
|
||||
probmethodString
|
||||
);
|
||||
SimilarityMethodEnum similairtyMethodEnum = (SimilarityMethodEnum)Enum.Parse(
|
||||
typeof(SimilarityMethodEnum),
|
||||
similarityMethodString
|
||||
);
|
||||
ProbMethod probmethod = new(probmethodEnum, _logger);
|
||||
SimilarityMethod similarityMethod = new(similairtyMethodEnum, _logger);
|
||||
if (embedding_unassigned.TryGetValue(id, out Dictionary<string, float[]>? embeddings) && probmethod is not null)
|
||||
{
|
||||
embedding_unassigned.Remove(id);
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
using System.Numerics.Tensors;
|
||||
using System.Text.Json;
|
||||
using Shared.Models;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public class SimilarityMethod
|
||||
{
|
||||
public SimilarityMethods.similarityMethodDelegate method;
|
||||
public SimilarityMethodEnum similarityMethodEnum;
|
||||
public string name;
|
||||
|
||||
public SimilarityMethod(string name, ILogger logger)
|
||||
public SimilarityMethod(SimilarityMethodEnum similarityMethodEnum, ILogger logger)
|
||||
{
|
||||
this.name = name;
|
||||
this.similarityMethodEnum = similarityMethodEnum;
|
||||
this.name = similarityMethodEnum.ToString();
|
||||
SimilarityMethods.similarityMethodDelegate? probMethod = SimilarityMethods.GetMethod(name);
|
||||
if (probMethod is null)
|
||||
{
|
||||
@@ -21,14 +23,6 @@ public class SimilarityMethod
|
||||
}
|
||||
}
|
||||
|
||||
public enum SimilarityMethodEnum
|
||||
{
|
||||
Cosine,
|
||||
Euclidian,
|
||||
Manhattan,
|
||||
Pearson
|
||||
}
|
||||
|
||||
public static class SimilarityMethods
|
||||
{
|
||||
public delegate float similarityMethodProtoDelegate(float[] vector1, float[] vector2);
|
||||
|
||||
Reference in New Issue
Block a user