/// <summary> /// Finds symbol /// </summary> /// <param name="s">Prototype</param> /// <returns>Found symbol</returns> public MathSymbol Find(MathSymbol s) { foreach (MathSymbol sym in symbols) { if (sym.IsSame(s)) { return(sym); } } return(null); }
/// <summary> /// Detects operation /// </summary> /// <param name="s">First symbol of the formula</param> /// <returns>Acceptor of operation</returns> public IOperationAcceptor Detect(MathSymbol s) { if (s is SimpleSymbol) { SimpleSymbol ss = s as SimpleSymbol; if (s.Symbol == '\u2211') { return(new ArraySingleOperationAcceptor(ArraySingleOperationType.Sum)); } } return(null); }
IOperationAcceptor IVariableDetector.Detect(MathSymbol sym) { if (table != null) { if (!table.ContainsKey(sym.Symbol)) { return(null); } return(new ElementaryObjectVariable(sym.Symbol, table)); } return(null); }
//public bool isDivision => symbol == MathSymbol.Divide; /// <summary> /// When a new equation is created, two random numbers are generated and a random symbol is generated. /// </summary> public Equation(Random gen, int maxValue = 101) { this.gen = gen; num1 = gen.Next(maxValue); symbol = (MathSymbol)gen.Next(4); num2 = gen.Next(maxValue); //make sure that the result of the division is not a decimal and that there is no division by 0 while ((symbol == MathSymbol.Divide && num2 == 0) || num1 % num2 != 0) { num2 = gen.Next(maxValue); } }
/// <summary> /// Detects operation acceptor /// </summary> /// <param name="s">Operation symbol</param> /// <returns>The acceptor</returns> public IBinaryAcceptor Detect(MathSymbol s) { if (s is BinarySymbol) { char c = s.Symbol; if ((c == symbol)) { return(new LogicalOperation(c)); } } return(null); }
/// <summary> /// Detects operation acceptor /// </summary> /// <param name="s">Operation symbol</param> /// <returns>The acceptor</returns> public IBinaryAcceptor Detect(MathSymbol s) { if (s is BinarySymbol) { char c = s.Symbol; if ((c == '>') | (c == '<') | (c == '\u2260') | (c == '\u2264') | (c == '\u2265')) { return(new ComparationOperation(c)); } } return(null); }
/// <summary> /// Creates element from formula /// </summary> /// <param name="formula">Formula</param> /// <param name="document">Document</param> /// <param name="creator">Creator</param> /// <returns>Element</returns> public static XElement CreateElement(MathFormula formula, IXmlSymbolCreator creator) { XElement e = formula.CreateXElement("F"); for (int i = 0; i < formula.Count; i++) { XElement el = MathSymbol.CreateElement(formula[i], creator); e.Add(el); } return(e); }
IMultiVariableOperation IMultiVariableOperationAcceptor.AcceptOperation(MathSymbol symbol) { if (!(symbol is BinaryFunctionSymbol)) { return(null); } if (symbol.Symbol == '2') { return(Singleton); } return(null); }
/// <summary> /// Detects operation /// </summary> /// <param name="s">First symbol of the formula</param> /// <returns>Acceptor of operation</returns> public IOperationAcceptor Detect(MathSymbol s) { if (s is SimpleSymbol) { SimpleSymbol sym = s as SimpleSymbol; if ((sym.Bold == bold) & (sym.Italic == italic) & (sym.SymbolType == type)) { return(new StringOperationAcceptor(s.String)); } } return(null); }
/// <summary> /// Gets the symbol for removing by mouse click /// </summary> /// <param name="p">the mouse position</param> /// <returns>the symbol for removing by mouse click</returns> public IDrawableSymbol GetRemovedSymbol(Point p) { for (int i = 0; i < Count; i++) { MathSymbol symbol = this[i]; IDrawableSymbol ret = MathSymbolDrawable.GetRemovedSymbol(symbol, p); if (ret != null) { return(ret); } } return(null); }
IBinaryAcceptor IBinaryDetector.Detect(MathSymbol s) { char c = s.Symbol; if (c == '+') { return(RealMatrixAdd.Singleton); } if (c == '-') { return(RealMatixDifference.Singleton); } return(null); }
/// <summary> /// Detects operation acceptor /// </summary> /// <param name="s">Operation symbol</param> /// <returns>The acceptor</returns> public IBinaryAcceptor Detect(MathSymbol s) { if (!(s is BinarySymbol)) { return(null); } BinarySymbol sym = s as BinarySymbol; if (s.Symbol != symbol) { return(null); } return(this); }
/// <summary> /// Detects operation /// </summary> /// <param name="s">First symbol of the formula</param> /// <returns>Acceptor of operation</returns> public IOperationAcceptor Detect(MathSymbol s) { IOperationAcceptor acc = detector.Detect(s); if (acc == null) { return(null); } if (acc is IMultiVariableOperationAcceptor) { return(new MultiVariableArrayOperationAcceptor(acc as IMultiVariableOperationAcceptor)); } return(new ArrayOperationAcceptor(acc)); }
/// <summary> /// Key up /// </summary> /// <param name="sender">Sender</param> /// <param name="args">Arguments</param> private void keyUp(object sender, KeyEventArgs args) { if (args.KeyData != Keys.Back) { return; } MathSymbol sym = formula.Last; if (sym != null) { sym.Remove(); DrawFormulaOnComponent(); } }
IOperationAcceptor IVariableDetector.Detect(MathSymbol sym) { if (sym.SymbolType != (int)FormulaConstants.Variable) { return(null); } string s = sym.Symbol + ""; if (dict.ContainsKey(s)) { return(new DoubleDictionaryVariable(s, this)); } return(null); }
/// <summary> /// This method is used to add new symbols to the database. /// </summary> /// <param name="bitmap"> /// The image containing the symbol. /// </param> /// <param name="symbol"> /// The symbol contained in the image. /// </param> public override bool Learn(MathTextBitmap bitmap, MathSymbol symbol) { FloatBitmap processedBitmap = bitmap.LastProcessedImage; TristateCheckVector newVector = CreateVector(processedBitmap); TristateCheckVector found = null; foreach (TristateCheckVector vector in symbolsDict) { if (vector.Symbols.Contains(symbol)) { found = vector; break; } } if (found == null) { // The symbol wasnt present in the database. newVector.Symbols.Add(symbol); symbolsDict.Add(newVector); } else { // The symbol is present, we may have to retrain the database. if (newVector.Equals(found)) { // It's the same one, so there is a conflict. return(false); } else { // We have to find the differnces, and change them to // don't care values. for (int i = 0; i < found.Length; i++) { if (found[i] != TristateValue.DontCare && found[i] != newVector[i]) { // If the value is different from what we had learned, // then we make the vector more general in that point. found[i] = TristateValue.DontCare; } } } } return(true); }
IOperationAcceptor IOperationDetector.Detect(MathSymbol s) { //PropertyInfo[] inform = objectType.GetProperties(); //foreach (PropertyInfo info in inform) //{ foreach (string propertyName in propertyNames) { if (propertyName.Equals(s.String)) { return(new SinglePropertyOperation(this, propertyName)); } } //} return(null); }
public static bool MatchMathSymbol(string src, int size, int pos, out int nextPos, out MathSymbol symbol) { foreach (var pair in MAP_SET_MATH_SYMBOL) { var setPair = pair.Value; var signSet = setPair.Value; foreach (var sign in signSet) { if (MatchSign(sign, src, size, pos, out nextPos)) { symbol = pair.Key; return true; } } } nextPos = pos; symbol = MathSymbol.None; return false; }
/// <summary> /// Accepts operation /// </summary> /// <param name="symbol">The symbol</param> /// <returns>Accepted operation</returns> public IMultiVariableOperation AcceptOperation(MathSymbol symbol) { if (symbol is RootSymbol) { return(new ElementaryRoot()); } if (symbol.Symbol == '2') { return(BinaryBrackets.Singleton); } if (symbol.Symbol == '3') { return(TernaryBrackets.Singleton); } return(ElementaryAtan2.Object); }
/// <summary> /// Detects operation acceptor /// </summary> /// <param name="s">Operation symbol</param> /// <returns>The acceptor</returns> public IBinaryAcceptor Detect(MathSymbol s) { if (s is BinarySymbol) { char c = s.Symbol; if (c == '=') { return(EqualityAcceptor.Object); } if (c == '\u2260') { return(InequalityAcceptor.Object); } } return(null); }
IBinaryAcceptor IBinaryDetector.Detect(MathSymbol s) { if (s is BinarySymbol) { char c = s.Symbol; if (c == '=') { return(Object); } if (c == '\u2260') { return(StringObjectUnequalityOperation.Object); } } return(null); }
/// <summary> /// Creates formula from Xml element /// </summary> /// <param name="e">Element</param> /// <param name="creator">Creator of symbols</param> /// <returns>Formula</returns> public static MathFormula CreateFormula(XElement e, IXmlSymbolCreator creator) { MathFormula f = new MathFormula((byte)0); IEnumerable <XElement> l = e.GetElementsByTagName("S"); foreach (XElement el in l) { if (el.Parent != e) { continue; } MathSymbol s = MathSymbol.CreateSymbol(el, creator); s.AppendWithChildren(f); } return(f); }
IOperationAcceptor IVariableDetector.Detect(MathSymbol sym) { char c = sym.Symbol; if (!table.ContainsKey(c)) { return(null); } object o = table[c]; if (!(o is IOneVariableFunction)) { return(null); } return(new OneVariableFunctionDetector(o as IOneVariableFunction)); }
/// <summary> /// Permite añadir un simbolo al nodo. /// </summary> /// <param name="symbol"> /// El simbolo a añadir /// </param> public bool AddSymbol(MathSymbol symbol) { if (symbols == null) { symbols = new List <MathSymbol>(); } if (this.symbols.Contains(symbol)) { return(false); } else { this.symbols.Add(symbol); return(true); } }
/// <summary> /// Detects i - th symbol of operation /// </summary> /// <param name="i">The symbol number</param> /// <param name="symbol">Symbol of detection</param> /// <returns></returns> public bool Detect(int i, MathSymbol symbol) { if (!(symbol is BinarySymbol)) { return(false); } char c = symbol.Symbol; if (i == 0) { return(c == '?'); } else { return(c == ':'); } }
/// <summary> /// Creates formula /// </summary> /// <param name="tree">Operation tree</param> /// <param name="level">Formula level</param> /// <param name="sizes">Sizes of symbols</param> /// <returns>The formula</returns> public MathFormula CreateFormula(ObjectFormulaTree tree, byte level, int[] sizes) { MathFormula form = new MathFormula(level, sizes); MathSymbol sym = null; if (symbol is Char) { sym = new SimpleSymbol((char)symbol); } else if (symbol is StringPair) { StringPair sp = symbol as StringPair; sym = new SubscriptedSymbol(sp.First, sp.Second); } sym.Append(form); return(form); }
/// <summary> /// Gets object to insert /// </summary> /// <param name="p">position of the object</param> /// <returns>The object</returns> public IInsertedObject GetInsertedObject(Point p) { for (int i = 0; i < Count; i++) { MathSymbol find = this[i]; IInsertedObject obj = MathSymbolDrawable.GetInsertedObject(find, p); if (obj != null) { return(obj); } } if (endRectangle.Contains(p)) { return(this); } return(null); }
/// <summary> /// Detects acceptor /// </summary> /// <param name="sym">The symbol</param> /// <param name="dic">Opretation dictionary</param> /// <returns>Acceptor</returns> static public IOperationAcceptor Detect(MathSymbol sym, IDictionary <string, IOperationAcceptor> dic) { string s = sym.Symbol + ""; if (dic != null) { if (dic.ContainsKey(s)) { return(dic[s]); } } if (sym.SymbolType != (int)FormulaConstants.Variable) { return(null); } return(null); }
/// <summary> /// Metodo que gestiona el evento que se provoca al hacer /// click en el boton "Aprender" de la interfaz. /// </summary> private void OnBtnLearnClicked(object sender, EventArgs arg) { string errorMsg = ""; symbol = new MathSymbol(); if (symbolLabelEditor.Label.Trim() == "") { errorMsg = ".- El texto del símbolo no es válido.\n"; } else { symbol.Text = symbolLabelEditor.Label.Trim(); } if (errorMsg == "") { //NO hay errores de validación nextButtonsHB.Sensitive = true; hboxSymbolWidgets.Sensitive = false; menuDatabase.Sensitive = false; menuSaveAs.Sensitive = false; menuOpen.Sensitive = false; learningThread = null; toolbar.Sensitive = false; learningThread = new Thread(new ThreadStart(LearnProccess)); learningThread.Start(); learningThread.Suspend(); return; } else { //Informamos de que no podemos aprender el caracter. OkDialog.Show( mainWindow, MessageType.Error, "El símbolo no puede ser aprendido porque:\n\n{0}", errorMsg); LogLine(errorMsg); } }
/// <summary> /// Constructor from prototype /// </summary> /// <param name="formula">Prototype</param> /// <param name="converter">Symbol converter</param> public MathFormula(MathFormula formula, IMathSymbolConverter converter) : this(formula.Level, formula.Sizes) { for (int i = 0; i < formula.Count; i++) { MathSymbol s = formula[i]; MathSymbol sym = converter.Convert(s); sym.Append(this); sym = Last; for (int j = 0; j < s.Count; j++) { if (s[j] != null) { sym[j] = new MathFormula(s[j], converter); } } } }
public MathTreeNode(MathSymbol newValue) { Value = newValue; }