private List<SToken> ExplodeStoken(SToken sToken, SToken token, string form) { List<SToken> tokens = new List<SToken>(); //foreach (string form in forms) { string text = sToken.TokenString; string textBefore = string.Empty; string textAfter = string.Empty; if (text.Contains(form)) { textBefore = " "+text.Substring(0, text.IndexOf(form)).Trim()+" "; textAfter = " "+text.Substring(text.IndexOf(form) + form.Length).Trim()+" "; } // while (text.Contains(form)) { SToken tokenInside = new SToken(); tokenInside.Configure(token.TokenId, token.TokenString, token.TokenType, token.TokenCode); tokenInside.Link(SToken.NULL, SToken.NULL, null, null); SToken tokenBefore = new SToken(); tokenBefore.Configure(sToken.TokenId, textBefore, sToken.TokenType, sToken.TokenCode); tokenBefore.Link(sToken.TokenBefore, tokenInside, null, null); SToken tokenAfter = new SToken(); tokenAfter.Configure(sToken.TokenId, textAfter, sToken.TokenType, sToken.TokenCode); //*** tokenAfter.Link(tokenInside, sToken.TokenAfter, null, null); tokenInside.TokenBefore = tokenBefore; if (sToken.TokenBefore != null) { //*** sToken.TokenBefore.TokenAfter = tokenBefore; } //*** if (sToken.TokenAfter != null) { //*** sToken.TokenAfter.TokenBefore = tokenAfter; } //*** tokenInside.TokenAfter = tokenAfter; tokens.Add(tokenBefore); tokens.Add(tokenInside); tokens.Add(tokenAfter); } } return tokens; }
private List<SToken> ExplodeStoken(SToken sToken, SToken token, string form) { List<SToken> tokens = new List<SToken>(); //foreach (string form in forms) { string text = sToken.TokenString; string textBefore = string.Empty; string textAfter = string.Empty; if (text.Contains(form)) { textBefore = " "+text.Substring(0, text.IndexOf(form)).Trim()+" "; textAfter = " "+text.Substring(text.IndexOf(form) + form.Length).Trim()+" "; } // while (text.Contains(form)) { SToken tokenInside = new SToken(); SToken tokenBefore = new SToken(); SToken tokenAfter = new SToken(); tokenInside.Configure(token.TokenId, token.TokenString, token.TokenType, token.TokenCode); tokenInside.Link(sToken.TokenParent, tokenBefore, tokenAfter, sToken.TokenChilds); tokenInside.TokenMultiplicity = sToken.TokenMultiplicity; tokenInside.TokenMultiplicityLevel = sToken.TokenMultiplicityLevel; tokenBefore.Configure(sToken.TokenId, textBefore, sToken.TokenType, sToken.TokenCode); tokenBefore.Link(sToken.TokenParent, sToken.TokenBefore, tokenInside, token.TokenChilds); tokenAfter.Configure(sToken.TokenId, textAfter, sToken.TokenType, sToken.TokenCode); //*** tokenAfter.Link(sToken.TokenParent, tokenInside, sToken.TokenAfter, token.TokenChilds); //*** tokenInside.TokenAfter = tokenAfter; if (string.IsNullOrEmpty(tokenBefore.TokenString.Trim())) { tokenInside.TokenBefore = tokenBefore.TokenBefore; } if (string.IsNullOrEmpty(tokenAfter.TokenString.Trim())) { //*** tokenInside.TokenAfter = tokenAfter.TokenAfter; } if (sToken.TokenMultiplicity != SElementMultiplicity.Undefined) { tokenInside.TokenMultiplicity = sToken.TokenMultiplicity; tokenBefore.TokenMultiplicity = sToken.TokenMultiplicity; tokenInside.TokenMultiplicity = sToken.TokenMultiplicity; } else { tokenInside.TokenMultiplicity = token.TokenMultiplicity; tokenBefore.TokenMultiplicity = token.TokenMultiplicity; tokenInside.TokenMultiplicity = token.TokenMultiplicity; } tokenAfter.TokenBefore = tokenBefore; if (sToken.TokenBefore != null) { //*** sToken.TokenBefore.TokenAfter = tokenBefore; } //*** if (sToken.TokenAfter != null) { //*** sToken.TokenAfter.TokenBefore = tokenAfter; } if (!string.IsNullOrEmpty(tokenBefore.TokenString.Trim())) { tokens.Add(tokenBefore); } tokens.Add(tokenInside); if (!string.IsNullOrEmpty(tokenAfter.TokenString.Trim())) { tokens.Add(tokenAfter); } } } return tokens; }
/// <summary> /// Create a collection of tokens from the input string /// </summary> /// <returns></returns> public List<SToken> TokenizeInput(string tokenizableString) { List<SToken> tokenizedInput = new List<SToken>(); SToken newToken = new SToken(); newToken.Configure(0, string.Empty, SElementType.Undefined, tokenizableString); newToken.Link(SToken.NULL, SToken.NULL, null, null); tokenizedInput.Add(newToken); return tokenizedInput; }
public bool AdoptSymbol(int symbolId, string symbolText, List<string> forms, string code, SElementMultiplicity multiplicity) { bool simbolFound = false; SToken token = new SToken(); if (currentToken.TokenBefore != null) { token = currentToken; } token.Configure(symbolId, symbolText, SElementType.Symbol, "[" + symbolId + ":0]"); token.Link(currentToken.TokenParent, currentToken, null, null); if (currentToken.TokenBefore != null) { token.TokenBefore = currentToken.TokenBefore; } if (token.TokenMultiplicity == SElementMultiplicity.Undefined) token.TokenMultiplicity = multiplicity; StringBuilder tokenCollectionAsString = new StringBuilder(); SToken localCurrentToken = currentToken; while (localCurrentToken != null) { for (int i = 0; i < forms.Count; i++) { if (localCurrentToken.TokenType == SElementType.Undefined) { if (localCurrentToken.TokenString.Contains(forms[i])) { List<SToken> explodedToken = ExplodeStoken(localCurrentToken, token, forms[i]); // Try child int ii = localCurrentToken.TokenParent.TokenChilds.IndexOf(localCurrentToken); if (ii > -1) { localCurrentToken.TokenParent.TokenChilds.Insert(localCurrentToken.TokenParent.TokenChilds.IndexOf(localCurrentToken), explodedToken[0]); localCurrentToken.TokenParent.TokenChilds.Remove(localCurrentToken); i = 0; //if (explodedToken[explodedToken.Count - 1]!=null) localCurrentToken = explodedToken[explodedToken.Count - 1]; simbolFound = true; } // Try properties if (currentToken.TokenDescribed != null) { ii = localCurrentToken.TokenDescribed.TokenProperties.IndexOf(localCurrentToken); if (ii > -1) { localCurrentToken.TokenDescribed.TokenProperties.Insert(localCurrentToken.TokenDescribed.TokenProperties.IndexOf(localCurrentToken), explodedToken[0]); localCurrentToken.TokenDescribed.TokenProperties.Remove(localCurrentToken); i = 0; //if (explodedToken[explodedToken.Count - 1]!=null) localCurrentToken = explodedToken[explodedToken.Count - 1]; simbolFound = true; } } } } } localCurrentToken = GetNext(localCurrentToken); } return simbolFound; }
public void AdoptLogic(int logicId, string logicText, List<string> forms, string code) { SToken token = new SToken(); token.Configure(logicId, code, SElementType.Logic, logicText); token.Link(SToken.NULL, SToken.NULL, null, null); StringBuilder tokenCollectionAsString = new StringBuilder(); SToken localCurrentToken = currentToken; while (localCurrentToken != null) { for (int i = 0; i < forms.Count; i++) { if (localCurrentToken.TokenType == SElementType.Undefined) { if (localCurrentToken.TokenString.Contains(forms[i])) { List<SToken> explodedToken = ExplodeStoken(localCurrentToken, token, forms[i]); tokenCollection.AddRange(explodedToken); tokenCollection.Remove(localCurrentToken); i = 0; localCurrentToken = explodedToken[explodedToken.Count - 1]; } } } //*** localCurrentToken = localCurrentToken.TokenAfter; } }
private void AppendT(string c) { SToken newToken = new SToken(); newToken.TokenString = ".."; if (!sticked && ( CurrentToken.TokenParent.TokenType == SElementType.CollectionAnd || CurrentToken.TokenParent.TokenType == SElementType.CollectionOr) ) { if (CurrentToken.TokenParent.TokenAfter != null) { newToken.Link(CurrentToken.TokenParent.TokenParent, CurrentToken.TokenParent.TokenAfter[0], null, null); CurrentToken.TokenParent.TokenAfter[0].TokenAfter = new List<SToken>() { newToken }; } else { newToken.Link(CurrentToken.TokenParent.TokenParent, null, null, null); } CurrentToken = newToken; return; } newToken.Link(CurrentToken.TokenParent, CurrentToken, null, null); CurrentToken.TokenAfter = new List<SToken>() { newToken }; CurrentToken = newToken; }
public void AdoptOperator(int operatorId, string operatorText, List<string> forms, string code) { SToken token = new SToken(); token.Configure(operatorId, string.Empty, SElementType.Operator, operatorText); token.Link(SToken.NULL, SToken.NULL, null, null); StringBuilder tokenCollectionAsString = new StringBuilder(); SToken localCurrentToken = currentToken; while (localCurrentToken != null) { for (int i = 0; i < forms.Count; i++) { if (localCurrentToken.TokenType == SElementType.Undefined) { if (localCurrentToken.TokenString.Contains(forms[i])) { List<SToken> explodedToken = ExplodeStoken(localCurrentToken, token, forms[i]); currentToken.TokenParent.TokenChilds.InsertRange(currentToken.TokenParent.TokenChilds.IndexOf(localCurrentToken), explodedToken); currentToken.TokenParent.TokenChilds.Remove(localCurrentToken); i = 0; localCurrentToken = explodedToken[explodedToken.Count - 1]; } } } //*** localCurrentToken = localCurrentToken.TokenAfter; } }
void FoldToken(string c) { bool foldNeeded = true; SElementType[] conditionType = new SElementType[] { SElementType.CollectionAnd, SElementType.CollectionOr }; if (currentToken.TokenBefore != null) // if there is nothing before fold { if (conditionType.Contains(currentToken.TokenBefore.TokenType)) // if there is another terminated fold before then fold { //foldNeeded = false; } if (currentToken.TokenBefore.TokenType == SElementType.Collection && currentToken.TokenString == "and") // Fold needed ? { foldNeeded = false; } if (currentToken.TokenParent.TokenNodeType == SElementType.FoldOpen) { foldNeeded = false; } } if (foldNeeded) { SToken firstToFold = currentToken; if (currentToken.TokenBefore != null) { if (currentToken.TokenBefore.TokenBefore != null && currentToken.TokenBefore.TokenNodeType == SElementType.FoldClose && currentToken.TokenBefore.TokenBefore.TokenNodeType != SElementType.CollectionAnd) { while (firstToFold.TokenBefore != null && firstToFold.TokenNodeType != SElementType.FoldOpen) { firstToFold = firstToFold.TokenBefore; } } else { firstToFold = currentToken.TokenBefore; } } // Insert Folding Markers SToken bracketOpenToken = new SToken(); SToken bracketCloseToken = new SToken(); bracketOpenToken.Configure(0, "(", SElementType.Collection, ""); bracketCloseToken.Configure(0, ")", SElementType.Collection, ""); bracketOpenToken.TokenNodeType = SElementType.FoldOpen; bracketCloseToken.TokenNodeType = SElementType.FoldClose; if (currentToken.TokenBefore != null) { bracketOpenToken.TokenMultiplicity = currentToken.TokenBefore.TokenMultiplicity; } bracketOpenToken.Link(firstToFold.TokenParent, firstToFold.TokenBefore, bracketCloseToken, new List<SToken>() { firstToFold }); bracketCloseToken.Link(firstToFold.TokenParent, bracketOpenToken, null, null); firstToFold.Link(bracketOpenToken, null, null, firstToFold.TokenChilds); if (bracketOpenToken.TokenBefore != null) { bracketOpenToken.TokenBefore.TokenAfter[0] = bracketOpenToken; } SToken localToken = firstToFold; while (localToken != null && localToken.TokenAfter != null) { localToken.TokenParent = bracketOpenToken; localToken = localToken.TokenAfter[0]; } // If bracketOpenToken is the first in clilds replace the lider if (bracketOpenToken.TokenBefore == null) { bracketOpenToken.TokenParent.TokenChilds.Remove(firstToFold); bracketOpenToken.TokenParent.TokenChilds.Add(bracketOpenToken); } //currentToken = bracketCloseToken; } switch (c) { case "and": currentToken.TokenParent.TokenType = SElementType.CollectionAnd; currentToken.TokenParent.TokenString = "( && "; break; case "or": currentToken.TokenParent.TokenType = SElementType.CollectionOr; currentToken.TokenParent.TokenString = "( || "; break; } if (currentToken.TokenParent.TokenNodeType != SElementType.FoldOpen) { //currentToken = currentToken.TokenParent; } else { //AppendToken(); } }
private bool SubstituteSymbols(SToken localCurrentToken) { try { bool simbolFound = false; //SToken localCurrentToken = currentToken; //while (localCurrentToken.TokenBefore != null && localCurrentToken.TokenBefore.TokenType == SElementType.Undefined) { } while (localCurrentToken != null) { int offset = 0; if (localCurrentToken.TokenType == SElementType.Undefined) while (!NothingMoreToreplace(localCurrentToken, offset)) { string candidate = GetFirstCandidateToReplace(localCurrentToken, offset); candidate = candidate.Trim(); offset += candidate.Length; while (!string.IsNullOrEmpty(candidate)) { bool found = false; string partialCandidate = candidate; while (!found) { SObjectCollection objectCollection = new SObjectCollection(); objectCollection.AddByName(singularize(partialCandidate), 0); // logics.getSymbsBySubstring(partialCandidate, 0, 100); if (objectCollection.SObject.Count < 1) { if (partialCandidate.LastIndexOf(' ') > -1) { partialCandidate = partialCandidate.Substring(0, partialCandidate.LastIndexOf(' ')); } else { candidate = candidate.Substring(partialCandidate.Length).Trim();// /*for (int i = 0; i < candidate.Length; i++) { if (char.IsWhiteSpace(candidate[i])) { ReplaceAt++; } else { candidate = candidate.Substring(i); return; } }*/ //string substitute = "[0:0]"; /***>> if (Symbol.CreateUnknown && (char.IsWhiteSpace(SubsritutedQuery[SubsritutedQuery.Length - 1]) || (SubsritutedQuery[SubsritutedQuery.Length - 1] == '!'))) { Symbol symbol = new Symbol(partialCandidate, true); substitute = "[" + symbol.SymbolID[0] + ":" + symbol.SymbolID[1] + "]"; } <<***/ //SubsritutedQuery = SubsritutedQuery.Substring(0, ReplaceAt) + substitute + SubsritutedQuery.Substring(ReplaceAt + partialCandidate.Length); //ReplaceAt = ReplaceAt + substitute.Length + 1; // because i have a spave after substitude found = true; } } else { bool needReplaceAtPluse = false; string substitute = ""; foreach (SymbolID symbol in objectCollection.SObject) { substitute = symbol.ToString(); simbolFound = AdoptSymbol(symbol.Location.A, symbol.Names[0], new List<string>() { partialCandidate }, "[" + symbol.Location.A + ":0]", pluralize(symbol.Names[0]).Equals(partialCandidate) ? SElementMultiplicity.All : SElementMultiplicity.One); currentToken = currentToken.TokenParent.TokenChilds[0]; //*** while (currentToken.TokenAfter != null) { //*** currentToken = currentToken.TokenAfter; } //currentToken.TokenParent.TokenChilds //currentToken.TokenType = localCurrentToken.TokenType; //currentToken.TokenNodeType = localCurrentToken.TokenNodeType; //currentToken.TokenMultiplicity = localCurrentToken.TokenMultiplicity; //currentToken = currentToken.TokenParent.TokenChilds[0]; //*** if (currentToken.TokenAfter != null) { //*** currentToken.TokenAfter.TokenBefore = currentToken; } //offset = 0; } if (partialCandidate.Length < candidate.Length) { candidate = candidate.Substring(partialCandidate.Length + 1); // this is not possible if we are at the end of candidate needReplaceAtPluse = true; } else { candidate = string.Empty; } if (needReplaceAtPluse) { //ReplaceAt++; } found = true; } } } } localCurrentToken = GetNext(localCurrentToken); } if (simbolFound && false) { SToken newToken = new SToken(); newToken.Configure(0, "", SElementType.Undefined, ""); newToken.Link(currentToken.TokenParent, currentToken, null, null); //*** currentToken.TokenAfter = newToken; currentToken = newToken; } return simbolFound; } catch (Exception ss) { } return false; }
private SToken AppendToken(string tokenText, string c) { //ParseDocument(); if (!sticked) { if (currentToken.TokenParent.TokenNodeType == SElementType.FoldOpen || currentToken.TokenParent.TokenType == SElementType.CollectionAnd || currentToken.TokenParent.TokenType == SElementType.CollectionOr) { //*** currentToken.TokenBefore.TokenAfter = currentToken.TokenAfter; // link //*** currentToken.TokenBefore = currentToken.TokenParent.TokenAfter; //*** currentToken.TokenParent.TokenAfter.TokenAfter = currentToken; currentToken.TokenParent = currentToken.TokenParent.TokenParent; } else { SToken newToken = new SToken(); newToken.Configure(0, "", SElementType.Undefined, ""); newToken.Link(currentToken.TokenParent, currentToken, null, null); // if the multilplicity is not defined get the colection multiplicity if (currentToken.TokenMultiplicity == SElementMultiplicity.Undefined) { newToken.TokenMultiplicity = currentToken.TokenParent.TokenMultiplicity; } //currentToken = newToken; currentToken.TokenString = c; //*** currentToken.TokenAfter = newToken; //*** currentToken = currentToken.TokenAfter; } } else { currentToken.TokenString = c; //currentToken = newToken; } sticked = false; return currentToken; }
void AppendTokenDown() { SToken newToken = new SToken(); newToken.Configure(0, "append", SElementType.Undefined, ""); newToken.Link(currentToken.TokenParent, currentToken, null, null); //*** currentToken.TokenAfter = newToken; //*** currentToken = currentToken.TokenAfter; }
private void AddBlock(string tokenText, string c) { currentToken.TokenString = tokenText + c; SToken aToken = new SToken(); aToken.Configure(0, string.Empty, SElementType.Undefined, ""); aToken.Link(SToken.NULL, SToken.NULL, parentToken, new List<SToken>()); parentToken.TokenChilds.Add(aToken); currentToken = aToken; }
private void AddToCollection(string tokenText, string c) { currentToken.TokenString = tokenText; if (!sticked && currentToken.TokenParent.TokenNodeType == SElementType.FoldOpen) { //*** currentToken = currentToken.TokenParent.TokenAfter; } currentToken = FoldBelowWithPrewious(c, new SElementType[] { SElementType.CollectionAnd, SElementType.CollectionOr }); if (currentToken.TokenParent.TokenType == SElementType.Collection) { //string c = ""; switch (c) { case "and": currentToken.TokenParent.TokenType = SElementType.CollectionAnd; currentToken.TokenParent.TokenString = "( && "; break; case "or": currentToken.TokenParent.TokenType = SElementType.CollectionOr; currentToken.TokenParent.TokenString = "( || "; break; } } SToken newTocken = new SToken(); newTocken.Configure(0, string.Empty, SElementType.Undefined, string.Empty); newTocken.Link(currentToken.TokenParent, currentToken, SToken.NULL, new List<SToken>()); //currentToken.TokenMultiplicity = currentToken.TokenParent.TokenMultiplicity; //*** currentToken.TokenAfter = newTocken; currentToken = newTocken; //if (currentToken.TokenParent.TokenType == SElementType.Collection) sticked = true; }
private void CreateNewCollection() { sticked = true; //Prepare Brackets SToken nextToken = CurrentToken; CurrentToken = CurrentToken.TokenBefore; CurrentToken.TokenAfter = null; SToken bracketOpenToken = new SToken(); SToken bracketCloseToken = new SToken(); bracketOpenToken.Configure(0, "(", SElementType.Collection, ""); bracketCloseToken.Configure(0, ")", SElementType.Collection, ""); bracketOpenToken.TokenNodeType = SElementType.FoldOpen; bracketCloseToken.TokenNodeType = SElementType.FoldClose; // Wire Up bracketOpenToken.Link(CurrentToken.TokenParent, CurrentToken.TokenBefore, bracketCloseToken, new List<SToken>() { CurrentToken }); bracketCloseToken.Link(CurrentToken.TokenParent, bracketOpenToken, null, null); nextToken.Link(bracketOpenToken, CurrentToken, null, null); if (CurrentToken.TokenBefore != null) { CurrentToken.TokenBefore.TokenAfter[0] = bracketOpenToken; } if (CurrentToken.TokenDescribed != null) { CurrentToken.TokenDescribed.TokenProperties[0] = bracketOpenToken; } CurrentToken.Link(bracketOpenToken, null, nextToken, null); CurrentToken = nextToken; }
public EDocument(string documentText) { DocumentText = documentText; RootTocken = new SToken(); SToken newTocken = new SToken(); RootTocken.Configure(0, string.Empty + "Program", SElementType.Undefined, string.Empty + " * "); newTocken.Configure(0, string.Empty + "..", SElementType.Undefined, string.Empty); RootTocken.TokenNodeType = SElementType.Undefined; newTocken.TokenNodeType = SElementType.Undefined; RootTocken.Link(SToken.NULL, SToken.NULL, null, null); newTocken.Link(rootTocken, SToken.NULL, null, null); RootTocken.TokenChilds.Add(newTocken); parentToken = RootTocken; currentToken = RootTocken.TokenChilds[0]; InitializePersons(); }
private SToken FoldBelowWithPrewious(string c, SElementType[] conditionType) { // Fold Needed ? bool foldNeeded = true; if (currentToken.TokenBefore != null) // if there is nothing before fold { if (conditionType.Contains(currentToken.TokenBefore.TokenType)) // if there is another terminated fold before then fold { //foldNeeded = false; } if (currentToken.TokenBefore.TokenType == SElementType.Collection && c == "and") // Fold needed ? { foldNeeded = false; } if (true) { } } // Fold Location ? SToken firstToFold = currentToken; if (foldNeeded) { if (currentToken.TokenNodeType == SElementType.FoldClose && currentToken.TokenBefore.TokenNodeType != SElementType.CollectionAnd) { while (firstToFold.TokenBefore != null && firstToFold.TokenNodeType != SElementType.FoldOpen) { firstToFold = firstToFold.TokenBefore; } } // Insert Folding Markers SToken bracketOpenToken = new SToken(); bracketOpenToken.Configure(0, "(", SElementType.Collection, ""); bracketOpenToken.TokenNodeType = SElementType.FoldOpen; bracketOpenToken.TokenMultiplicity = currentToken.TokenMultiplicity; SToken bracketCloseToken = new SToken(); bracketCloseToken.Configure(0, ")", SElementType.Collection, ""); bracketCloseToken.TokenNodeType = SElementType.FoldClose; bracketOpenToken.Link(firstToFold.TokenParent, firstToFold.TokenBefore, bracketCloseToken, new List<SToken>() { firstToFold }); if (bracketOpenToken.TokenBefore != null) { //*** bracketOpenToken.TokenBefore.TokenAfter = bracketOpenToken; } SToken localToken = firstToFold; while (localToken != null) { localToken.TokenParent = bracketOpenToken; //*** localToken = localToken.TokenAfter; } bracketCloseToken.Link(firstToFold.TokenParent, bracketOpenToken, null, null); // If bracketOpenToken is the first in clilds replace the lider if (bracketOpenToken.TokenBefore == null) { bracketOpenToken.TokenParent.TokenChilds.Remove(firstToFold); bracketOpenToken.TokenParent.TokenChilds.Add(bracketOpenToken); } // Fold element //*** firstToFold.Link(bracketOpenToken, null, firstToFold.TokenAfter, firstToFold.TokenChilds); } else { SToken localToken = null; if (currentToken.TokenParent.TokenChilds.Count > 0) { localToken = currentToken.TokenParent.TokenChilds[0]; //*** while (localToken.TokenAfter != null) { //*** localToken = localToken.TokenAfter; } } currentToken = localToken; // localToken.TokenAfter = new SToken(0, "", SElementType.Undefined, ""); // currentToken.TokenBefore.TokenAfter = currentToken.TokenAfter; // currentToken.TokenBefore = localToken; // currentToken.TokenParent = localToken.TokenParent; // currentToken.TokenBefore.TokenAfter = currentToken; } // Right //sticked = true; // keep next token into array return currentToken; }
public void ParseAsNatural() { StringBuilder currentPhrase = new StringBuilder(); bool handled = false; foreach (string c in documentText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { switch (c) { case ".": //currentToken.TokenString = currentPhrase.ToString(); handled = true; AddBlock(currentPhrase.ToString(), c); currentPhrase = new StringBuilder(); break; case "he": case "she": case "it": handled = true; currentToken = LastToken; break; case "increase": // Set influenc case "decrease": case "increasedBy": // Set influence case "decreasedBy": handled = true; SetInfluence(currentToken, c); currentPhrase = new StringBuilder(); break; case "they": handled = true; newEvaluation = true; CurrentToken = lastTokenCollection; AppendToken(c); //SetNext(); break; case ",": if (FoldNeeded) { CreateNewCollection(); } else { AppendToCollection(); } break; case "and": case "or": EscapeFromCollection(c); //currentToken.TokenString = currentPhrase.ToString(); handled = true; //Append(); //AddToCollection(currentPhrase.ToString(), c); currentPhrase = new StringBuilder(); //AppendT(c); break; case "can": // Set a function handled = true; if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenActivities == null) { currentToken.TokenDescribed.TokenActivities = new List<SToken>(); } currentToken.TokenDescribed.TokenActivities.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); currentPhrase = new StringBuilder(); isPreoperand = false; break; case "have": // Set a property handled = true; currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenProperties == null) { currentToken.TokenDescribed.TokenProperties = new List<SToken>(); } currentToken.TokenDescribed.TokenProperties.Add(currentToken); currentToken.TokenDescribed.TokenAfter = null; currentToken.Link(currentToken.TokenParent, null, null, null); currentPhrase = new StringBuilder(); nextIsAPropertyFoTheCurrent = true; isPreoperand = false; break; case "a": case "an": case "some": case "many": case "all": case "one": case "no": case "1": case "0": handled = true; SetMultiplicityFlag(c); currentPhrase = new StringBuilder(); break; default: // is it a multiplication factor? int multiplicityLevel = 0; int.TryParse(c, out multiplicityLevel); if (multiplicityLevel != 0) { handled = true; SetMultiplicityLevel(multiplicityLevel); currentPhrase = new StringBuilder(); break; } handled = true; string actualWord = c; if (c.EndsWith("`s")) { nextIsAPropertyFoTheCurrent = true; actualWord = c.Substring(0, c.Length - 2); } CurrentToken.TokenString = actualWord; SToken existentToken = KnownTockens.FirstOrDefault(p => p.TokenString == actualWord); if (existentToken != null) { CurrentToken = existentToken; } else { KnownTockens.Add(CurrentToken); } if (!SubstituteSymbols(currentToken)) { if (CurrentToken.TokenMultiplicity == SElementMultiplicity.Undefined) CurrentToken.TokenMultiplicity = currentToken.TokenParent.TokenMultiplicity; } //AppendToken(c); if (CurrentToken.TokenDescribed != null) { if (CurrentToken.TokenDescribed.TokenInfluenceC != null) { foreach (SToken token in CurrentToken.TokenDescribed.TokenInfluenceC) { if (CurrentToken.TokenDescribed.TokenInfluenceC.Count > 0) { if (token.TokenInfluenceA == null) { token.TokenInfluenceA = new List<SToken>(); } } token.TokenInfluenceA.Add(CurrentToken.TokenDescribed); } CurrentToken.TokenDescribed.TokenInfluenceC = null; } if (CurrentToken.TokenDescribed.TokenInfluenceD != null) { } } AppendT(c); break; } if (!handled) { currentPhrase.Append(" " + c); } else { handled = false; } //RefreshPersons(); } }
private void SetInfluence(SToken currentToken, string c) { switch (c) { case "increase": if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenInfluenceA == null) { currentToken.TokenDescribed.TokenInfluenceA = new List<SToken>(); } currentToken.TokenDescribed.TokenInfluenceA.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); /* if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenInfluenceA == null) { currentToken.TokenDescribed.TokenInfluenceA = new List<SToken>(); } currentToken.TokenDescribed.TokenInfluenceA.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); * */ break; case "decrease": if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenInfluenceB == null) { currentToken.TokenDescribed.TokenInfluenceB = new List<SToken>(); } currentToken.TokenDescribed.TokenInfluenceB.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); /* if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenInfluenceB == null) { currentToken.TokenDescribed.TokenInfluenceB = new List<SToken>(); } currentToken.TokenDescribed.TokenInfluenceB.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); * */ break; case "increasedBy": if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenInfluenceC == null) { currentToken.TokenDescribed.TokenInfluenceC = new List<SToken>(); } currentToken.TokenDescribed.TokenInfluenceC.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); /* if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenInfluenceB == null) { currentToken.TokenDescribed.TokenInfluenceB = new List<SToken>(); } currentToken.TokenDescribed.TokenInfluenceB.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); * */ break; case "decreasedBy": if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenInfluenceD == null) { currentToken.TokenDescribed.TokenInfluenceD = new List<SToken>(); } currentToken.TokenDescribed.TokenInfluenceD.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); /* if (currentToken.TokenDescribed == null) currentToken.TokenDescribed = currentToken.TokenBefore; if (currentToken.TokenDescribed.TokenInfluenceB == null) { currentToken.TokenDescribed.TokenInfluenceB = new List<SToken>(); } currentToken.TokenDescribed.TokenInfluenceB.Add(currentToken); currentToken.Link(currentToken.TokenParent, null, null, null); * */ break; } }