/// <summary> /// Describes the specified logger. /// </summary> /// <param name="logger">The logger.</param> public void Describe(ILogBuilder logger) { logger.AppendLine("Feature Weighting model"); if (DoUseLocalFunction) { logger.AppendLine("Local weight model"); logger.nextTabLevel(); LocalFunction.Describe(logger); logger.prevTabLevel(); } if (DoUseLocalFunction) { logger.AppendLine("Global weight model(s)"); } logger.nextTabLevel(); foreach (var lf in GlobalFactors) { lf.Describe(logger); } logger.prevTabLevel(); }
public void Invoke(IExecutionContext context) { var parentScope = context.Scope; var function = new LocalFunction(parentScope, _parameters, _operations); context.Push(function.Pointer); }
/// <summary> /// Prepares the model. /// </summary> /// <param name="space">The space.</param> public void PrepareTheModel(SpaceModel space, ILogBuilder log) { foreach (FeatureWeightFactor gf in GlobalFactors) { if (DoShareAnalyticData) { SharedDataPool.TryToGet(gf.GlobalFunction, log); } gf.GlobalFunction.PrepareTheModel(space, log); gf.GlobalFunction.DoIndexNormalization(log); if (gf.GlobalFunction.resultType == FunctionResultTypeEnum.numericVectorForMultiClass) { nDimensions = space.labels.Count; resultType = gf.GlobalFunction.resultType; } if (DoShareAnalyticData) { SharedDataPool.TryToSet(gf.GlobalFunction, log); } } if (DoUseLocalFunction) { LocalFunction.PrepareTheModel(space, log); } if (!GlobalFactors.Any()) { log.log("WARNING: NO GLOBAL FACTORS DEFINED AT FEATURE WEIGHT MODEL"); } }
/// <summary> /// Добавить функцию, определённую в этом блоке скрипта /// </summary> public void addLocalFunction(LocalFunction localFunction) { if (!isRoot) { throw new InvalidOperationException("Local functions can only be added to root script blocks!"); } this.localFunctions.Add(localFunction); }
public static void Main() { Iterator.Test(); Async.Test(); AsyncIterator.Test(); LocalFunction.Test(); Lambda.Test(); Complex.Test(); }
/// <summary> /// Gets the weights. /// </summary> /// <param name="termWhiteList">The term white list.</param> /// <param name="document">The document.</param> /// <param name="space">The space.</param> /// <param name="label">The label.</param> /// <returns></returns> public WeightDictionary GetWeights(List <String> termWhiteList, SpaceDocumentModel document, SpaceModel space, SpaceLabel label = null) { WeightDictionary output = new WeightDictionary(); output.name = GetSignature() + "_" + document.name; output.description = "Feature weight table constructed by [" + GetSignature() + "] for features [" + termWhiteList.Count + "] in document [" + document.name + "]"; output.nDimensions = nDimensions; if (KERNELOPTION_USE_WHITELISTTERMS) { foreach (String term in termWhiteList) { if (document.terms.Contains(term)) { throw new NotImplementedException(); //output.entries.Add(entry); } } } else { List <String> terms = document.terms.GetTokens(); for (int i = 0; i < document.terms.Count; i++) { String term = terms[i]; WeightDictionaryEntry entry = new WeightDictionaryEntry(term, 0); if (DoUseLocalFunction) { entry = LocalFunction.GetElementFactorEntry(term, document); } foreach (FeatureWeightFactor gf in GlobalFactors) { entry = entry * (gf.GlobalFunction.GetElementFactorEntry(term, space, label) * gf.weight); } if (document.weight != 1) { entry = entry * document.weight; } output.Merge(entry); //output.AddEntry(term, entry.dimensions, false); } } return(output); }
/// <summary> /// Gets the local element factor /// </summary> /// <param name="term">The term.</param> /// <param name="document">The document.</param> /// <returns></returns> public double GetElementFactor(String term, SpaceDocumentModel document) { if (DoUseLocalFunction && LocalFunction != null) { if (LocalFunction.IsEnabled) { Double TF = LocalFunction.GetElementFactor(term, document); return(TF); } } return(1); }
/// <summary> /// Saves the model data set. /// </summary> /// <returns></returns> public WeightingModelDataSet SaveModelDataSet(ILogBuilder log) { WeightingModelDataSet output = new WeightingModelDataSet(); output.modelData.Add(LocalFunction.SaveModelData()); foreach (FeatureWeightFactor gf in GlobalFactors) { output.modelData.Add(gf.GlobalFunction.SaveModelData()); } return(output); }
/// <summary> /// Gets the signature. /// </summary> /// <returns></returns> public String GetSignature() { String output = ""; if (DoUseLocalFunction) { output += LocalFunction.GetSignature(); } foreach (FeatureWeightFactor gf in GlobalFactors) { output = output.add(gf.Settings.GetSignature(), "-"); } return(output); }
private static void PrintFunction(Script script, StringBuilder sb, int index) { LocalFunction func = script.FunctionPool[index]; sb.Append($"function {func.Name}"); sb.Append("("); Symbol[] symbols = script.ArgsSymbols?[index]; bool isFirst = true; for (int i = 0; i < func.ArgsCount; i++) { if (!isFirst) { sb.Append(", "); } sb.Append(symbols?[i].Name); isFirst = false; } sb.AppendLine(")"); if (func.LocalPoolIndex != ushort.MaxValue) { sb.AppendLine("Local Variable Pool:"); var table = new Table("Idx", "Name", "Type", "Len", "Value"); VmObject[] locals = script.LocalPool[func.LocalPoolIndex]; for (int i = 0; i < locals.Length; i++) { table.AddRow(i.ToString(), locals[i].Name, locals[i].Type.ToString(), locals[i].Length.ToString(), locals[i].Value.ToString()); } sb.AppendLine(table.Print()); } sb.AppendLine("Code:"); var codeTab = new Table("Addr", "opcode", "operand", "comment"); foreach (Instruction inst in script.Code[index]) { codeTab.AddRow(inst.Address.ToString("x"), inst.Opcode.ToString(), inst.Operand, inst.Comment); } sb.AppendLine(codeTab.Print()); sb.AppendLine(); }
public WeightDictionaryEntry GetCompositeEntry(String term, SpaceDocumentModel document, SpaceModel space) { WeightDictionaryEntry output = new WeightDictionaryEntry(term, 0); List <Double> dimensions = new List <double>(); dimensions.Add(LocalFunction.GetElementFactor(term, document)); foreach (var gf in GlobalFactors) { dimensions.Add(gf.GlobalFunction.GetElementFactor(term, space) * gf.weight); } output.dimensions = dimensions.ToArray(); return(output); }
private static void PrintFunctionPool(Script script, StringBuilder sb) { sb.AppendLine("Function Pool:"); var table = new Table("Index", "Name", "Start", "End", "Local Vars", "Arg Count", "F4", "FA"); for (int i = 0; i < script.FunctionPool.Length; i++) { LocalFunction func = script.FunctionPool[i]; table.AddRow(i.ToString(), func.Name, func.Start.ToString("x6"), func.End.ToString("x6"), func.LocalVarCount.ToString(), func.ArgsCount.ToString(), func.Field4.ToString(), func.FieldA.ToString()); } sb.AppendLine(table.Print()); for (int i = 0; i < script.FunctionPool.Length; i++) { PrintFunction(script, sb, i); } }
private void ReadFunctionPool(DataBuffer data) { data.Position = FunctionPoolOffset; int offset = data.ReadInt32(); int count = data.ReadInt32(); int length = PluginsOffset - FunctionPoolOffset; data.Position = FunctionPoolOffset + offset; var section = new Section("Function Pool", FunctionPoolOffset, count, length); Sections.Add(section); FunctionPool = new LocalFunction[count]; { for (int i = 0; i < FunctionPool.Length; i++) { FunctionPool[i] = new LocalFunction(data); FunctionPool[i].Name = GetId(FunctionPool[i].NameIndex, $"Function #{i}"); } } }
/// <summary> /// Loads the model data set. /// </summary> /// <param name="dataset">The dataset.</param> public void LoadModelDataSet(WeightingModelDataSet dataset, ILogBuilder log) { Dictionary <string, WeightingModelData> dict = dataset.GetDataDictionary(); if (dict.ContainsKey(LocalFunction.shortName)) { var localData = dict[LocalFunction.shortName]; if (DoUseLocalFunction) { LocalFunction.LoadModelData(localData); } } else { log.log("Loaded data set contains no data for [" + LocalFunction.shortName + "]"); } foreach (FeatureWeightFactor gf in GlobalFactors) { gf.GlobalFunction.LoadModelData(dict[gf.GlobalFunction.shortName]); } }
/// <summary> /// Запустить функцию с заданными аргументами [в основном для вызова из скрипта] /// </summary> public object executeFunction(string functionName, params object[] args) { GlobalFunction function = getGlobalFunction(functionName); if (function != null) { addToCallStack(FunctionType.GLOBAL, null); object obj = function.function.Invoke(this, args); removeFromCallStack(); return(obj); } else { if (localFunctions.ContainsKey(functionName)) { LocalFunction localFunction = localFunctions[functionName]; Dictionary <string, Variable> localArgs = new Dictionary <string, Variable>(); for (int i = 0; i < args.Length; i++) { localArgs.Add(localFunction.args[i], new Variable() { value = args[i] }); } addToCallStack(FunctionType.LOCAL, localArgs); object obj = localFunctions[functionName].code.execute(this); removeFromCallStack(); return(obj); } else { throw new ScriptException(ScriptException.FUNCTION_NOT_FOUND, "Функция \"" + functionName + "\" не найдена!"); } } }
private static void PrintLocalPool(Script script, StringBuilder sb) { sb.AppendLine("Local Pool:"); for (int i = 0; i < script.FunctionPool.Length; i++) { LocalFunction func = script.FunctionPool[i]; if (func.LocalPoolIndex == ushort.MaxValue) { continue; } var table = new Table("Name", "Type", "Len", "Value", "F8"); VmObject[] items = script.LocalPool[func.LocalPoolIndex]; for (int j = 0; j < items.Length; j++) { table.AddRow(items[j].Name, items[j].Type.ToString(), items[j].Length.ToString(), items[j].Value.ToString(), items[j].Field8.ToString()); } sb.AppendLine(func.Name); sb.AppendLine(table.Print()); } }
internal static void local_functions(this TextWriter trapFile, LocalFunction fn, string name, Type returnType, LocalFunction unboundFn) { trapFile.WriteTuple("local_functions", fn, name, returnType, unboundFn); }
internal static void local_function_stmts(this TextWriter trapFile, Entities.Statements.LocalFunction fnStmt, LocalFunction fn) { trapFile.WriteTuple("local_function_stmts", fnStmt, fn); }
internal static Tuple local_functions(LocalFunction fn, string name, Type returnType, LocalFunction unboundFn) => new Tuple("local_functions", fn, name, returnType, unboundFn);
internal static Tuple local_function_stmts(Entities.Statements.LocalFunction fnStmt, LocalFunction fn) => new Tuple("local_function_stmts", fnStmt, fn);
static void Main(string[] args) { string option; printOptions(); while ((option = ReadLine().ToLower()) != null && !quit(option)) { Console.Clear(); switch (option) { case "1": NumericLiteral.description(); break; case "2": OutVariable.description(); sourceCodeOutput(); OutVariable.discardParameters(); break; case "3": te.description(); (string name, int pen) = te.getInfoSoccerTeam(); (string n, string stadium, int pennant, int founded) = te.getInfoSoccerTeamInDepth(); var calc = te.calculateAB(15, 4); var calc2 = te.calculateABNoSemantic(15, 4); sourceCodeOutput(); WriteLine($"{name} --> {pen}"); WriteLine($"{n} {pennant} {stadium} {founded}"); WriteLine($"Div: {calc.div}, Sum: {calc.sum}"); WriteLine($"Diff: {calc2.Item2}, Mult: {calc2.Item3}"); te.buildTournament(); break; case "4": sp.description(); sourceCodeOutput(); sp.printTypeAndValue(new myType("luigi")); sp.printTypeAndValue(2); sp.printTypeAndValue("dsadsadas"); break; case "5": RefLocalReturn.description(); sourceCodeOutput(); RefLocalReturn.testRef(); break; case "6": LocalFunction.description(); sourceCodeOutput(); LocalFunction.testIntersection(); break; case "7": ExpressionBodied.description(); break; case "8": Throw.description(); break; case "9": ValueTaskType.description(); sourceCodeOutput(); var a = ValueTaskType.CachedFunc(); WriteLine(a); break; default: break; } printOptions(); } Console.Clear(); }