/// <summary> /// Renders the textMap from specified token subject /// </summary> /// <param name="token">The token.</param> /// <param name="mode">The mode.</param> /// <returns></returns> public static textMap <pipelineTaskSubjectContentToken> render(this pipelineTaskSubjectContentToken token, contentTokenSubjectRenderMode mode) { textMap <pipelineTaskSubjectContentToken> output = new textMap <pipelineTaskSubjectContentToken>(); renderSub(output, token, mode); output.AddPlainRender(textMapBase.SEPARATOR); return(output); }
private static void renderSub(textMap <pipelineTaskSubjectContentToken> output, pipelineTaskSubjectContentToken token, contentTokenSubjectRenderMode mode) { switch (token.contentLevelType) { //output.Add(token, renderString(token, mode)); //break; case flags.token.cnt_level.mcToken: output.Add(token, renderString(token, mode)); break; case flags.token.cnt_level.mcChunk: case flags.token.cnt_level.mcBlock: case flags.token.cnt_level.mcTokenStream: output.AddOpen(token, token.contentLevelType.renderOpen(mode)); foreach (pipelineTaskSubjectContentToken tkn in token) { renderSub(output, tkn, mode); } output.AddClose(token.contentLevelType.renderClose(mode)); break; } }
protected override List <pipelineTaskSubjectContentToken> processIteration(pipelineTaskSubjectContentToken streamSubject) { List <pipelineTaskSubjectContentToken> chunks = new List <pipelineTaskSubjectContentToken>(); if (streamSubject.contentLevelType == cnt_level.mcChunk) { chunks.Add(streamSubject); } foreach (imbSCI.Data.interfaces.IObjectWithPathAndChildren chk in streamSubject) { pipelineTaskSubjectContentToken ch = chk as pipelineTaskSubjectContentToken; if (ch.contentLevelType == cnt_level.mcChunk) { } } var subchk = pipelineSubjectTools.GetSubjectChildrenTokenType <pipelineTaskSubjectContentToken, IGraphNode>(streamSubject, new cnt_level[] { cnt_level.mcChunk }, true); chunks.AddRange(subchk); imbMCDocumentElement stream = streamSubject.mcElement as imbMCDocumentElement; if (stream == null) { return(chunks); } subjectRenderLayers layers = new subjectRenderLayers(); foreach (chunkMatchRule rule in settings.rules) { textMap <pipelineTaskSubjectContentToken> typeTagFormMap = layers.render(streamSubject, rule.renderMode); MatchCollection mchs = rule.regex.Matches(typeTagFormMap.render); List <List <pipelineTaskSubjectContentToken> > mchs_s = typeTagFormMap.Select(mchs); List <List <pipelineTaskSubjectContentToken> > mchs_subjects = new List <List <pipelineTaskSubjectContentToken> >(); foreach (List <pipelineTaskSubjectContentToken> mg in mchs_s) { List <pipelineTaskSubjectContentToken> mgc = new List <pipelineTaskSubjectContentToken>(); foreach (pipelineTaskSubjectContentToken m in mg) { if (rule.contentLevel.Contains(m.contentLevelType)) { mgc.Add(m); } } if (mgc.Any()) { mchs_subjects.Add(mgc); } } foreach (List <pipelineTaskSubjectContentToken> mGroup in mchs_subjects) { String tkn = imbStringGenerators.getRandomString(4); Boolean createChunk = true; foreach (pipelineTaskSubjectContentToken s in mGroup) { tkn = tkn + s.name; } if (rule.flagTypesToMatch.Any()) { Dictionary <Type, Object> flags = new Dictionary <Type, object>(); foreach (pipelineTaskSubjectContentToken s in mGroup) { foreach (Type flagType in rule.flagTypesToMatch) { Object fl = s.flagBag.FirstOrDefault(x => x.GetType() == flagType); if (fl == null) { continue; } if (!flags.ContainsKey(flagType)) { if (fl != null) { flags.Add(flagType, fl); } continue; } if (settings.doCheckGramTagCriteria) { if (flags[flagType] != fl) { createChunk = false; break; } } } if (createChunk == false) { break; } } } if (createChunk) { pipelineTaskSubjectContentToken chunkSubject = new pipelineTaskSubjectContentToken(); chunkSubject.name = tkn; streamSubject.Add(chunkSubject); imbMCChunk chunk = new imbMCChunk(); chunk.name = tkn; chunkSubject.contentLevelType = flags.token.cnt_level.mcChunk; chunkSubject.flagBag.Add(rule.chunkType); chunkSubject.mcElement = chunk; if (stream != null) { chunk.htmlNode = stream.htmlNode; } chunk.position = mGroup.Min(x => x.mcElement.position); stream.Add(chunk); List <Object> commonFlags = new List <object>(); List <Object> forbidenFlags = new List <object>(); Boolean isFirstSubject = true; foreach (pipelineTaskSubjectContentToken s in mGroup) { s.mcElement.removeFromParent(); chunk.Add(s.mcElement); s.removeFromParent(); chunkSubject.Add(s); if (isFirstSubject) { commonFlags.AddRange(s.flagBag, true); isFirstSubject = false; } else { foreach (Object flag in s.flagBag) { if (!forbidenFlags.Contains(flag)) { if (!commonFlags.Contains(flag)) { forbidenFlags.AddUnique(flag); } } else { commonFlags.Remove(flag); } } } } chunkSubject.initialForm = chunkSubject.render(contentTokenSubjectRenderMode.currentForm).render; var lemmaForm = chunkSubject.render(contentTokenSubjectRenderMode.lemmaForm); chunkSubject.currentForm = lemmaForm.GetCleanRender(); chunk.content = chunkSubject.currentForm; chunkSubject.flagBag.Clear(); chunkSubject.flagBag.AddRange(commonFlags, true); chunks.Add(chunkSubject); } } } return(chunks); }