private static void ParseContextLine(CapabilitiesCollection collection, string line, int lineIndex, ref ConceptBuilder conceptBuilder) { if (!line.StartsWith("Concept")) { InvalidData(line, lineIndex, "Invalid line to parse. Expected Concept keyword"); } var words = line.Split('\"'); if (words.Length < 2) { InvalidData(line, lineIndex, "Expected concept name to be defined"); } var conceptList = new List <string>(); for (var i = 1; i < words.Length; i += 2) { conceptList.Add(words[i]); } if (conceptList.Count == 0) { InvalidData(line, lineIndex, "Expected concept name between quotes"); } conceptBuilder = collection.AddConcept(conceptList[0]); conceptList.RemoveAt(0); foreach (var concept in conceptList) { collection.AddRelation(conceptBuilder, concept); } }
public bool HasCapability(string capability) { if (Concept.BlackList.ContainsKey(capability)) { return(false); } if (Concept.HasCapability(capability)) { return(true); } foreach (var child in Node.Children.Values) { var ri = child.Get <ReferenceInterpreter>(); if (ri == null) { continue; } var cb = new ConceptBuilder(ri.Node); if (cb.HasCapability(capability)) { return(true); } } return(false); }
public string GetCapability(string capability) { string value; if (Concept.BlackList.ContainsKey(capability)) { return(string.Empty); } if (Concept.Data.TryGetValue(capability, out value)) { return(value); } foreach (var child in Node.Children.Values) { var ri = child.Get <ReferenceInterpreter>(); if (ri == null) { continue; } var cb = new ConceptBuilder(ri.Node); var childCapability = cb.GetCapability(capability); if (!string.IsNullOrEmpty(childCapability)) { return(childCapability); } } return(string.Empty); }
public void AddRelatedConcept(ConceptBuilder relatedConcept) { if (GetRelatedConcept(relatedConcept.Name).Node != null) { return; } Node.AddNewChild().Set <ReferenceInterpreter>().Node = relatedConcept.Node; }
private static void ParseSectionExcluded(ConceptBuilder concept, string line, int lineIndex, ref ParseContext parseContext) { if (line.Trim() == "End") { parseContext = ParseContext.Concept; return; } if (line.Trim().Contains(" ")) { InvalidData(line, lineIndex, "Key names should be indentifier based"); } concept.AddBlacklistedCapability(line.Trim()); }
private static void ParseSectionKeys(ConceptBuilder concept, string line, int lineIndex, ref ParseContext parseContext) { if (line.Trim() == "End") { parseContext = ParseContext.Concept; return; } if (line.Contains("=")) { var splitLineByEqual = line.Split('='); var capabilityName = splitLineByEqual[0].Trim(); var splitByQuote = splitLineByEqual[1].Trim().Split('"'); var conceptValue = splitByQuote[1]; concept.SetCapability(capabilityName, conceptValue); return; } InvalidData(line, lineIndex, "Unknown code in section Keys"); }
public static CapabilitiesCollection LoadFileCapabilities(string fileName) { var collection = new CapabilitiesCollection(); var lines = File.ReadAllLines(fileName); var parseContext = ParseContext.None; var lineIndex = 0; var concept = new ConceptBuilder(null); foreach (var codeLine in lines) { lineIndex++; var line = codeLine.TrimEnd(); if (line.Contains("'")) { var pos = line.IndexOf("'"); line = line.Remove(pos).TrimEnd(); } if (string.IsNullOrEmpty(line.Trim())) { continue; } switch (parseContext) { case ParseContext.None: ParseContextLine(collection, line, lineIndex, ref concept); parseContext = ParseContext.Concept; break; case ParseContext.Concept: ParseContextBody(line, lineIndex, ref parseContext); break; case ParseContext.Keys: ParseSectionKeys(concept, line, lineIndex, ref parseContext); break; case ParseContext.Excluded: ParseSectionExcluded(concept, line, lineIndex, ref parseContext); break; } } return(collection); }
public ConceptBuilder GetRelatedConcept(string relatedConcept) { if (Name == relatedConcept) { return(this); } foreach (var child in Node.Children.Values) { var ri = child.Get <ReferenceInterpreter>(); if (ri == null) { continue; } var cb = new ConceptBuilder(ri.Node); var result = cb.GetRelatedConcept(relatedConcept); if (result._node != null) { return(result); } } return(new ConceptBuilder(null)); }
public void AddRelation(ConceptBuilder concept, string relation) { var relationBuilder = AddConcept(relation); concept.AddRelatedConcept(relationBuilder); }