Пример #1
0
        public override Boolean SetContentChunk(ContentChunk chunk, ChunkContentCandidate candidate, ChunkDetectionResult result)
        {
            chunk.multiNodePolicy = TaskMultiNodePolicy.AsSeparatedTables;
            chunk.type            = ContentChunkType.DynamicDataExtraction;

            return(true);
        }
Пример #2
0
        public ChunkDetectionResult Run(NodeGraph InitialGraph)
        {
            Check();



            ChunkDetectionResult result = new ChunkDetectionResult(InitialGraph, this);


            foreach (IContentChunkDetector detector in Detectors)
            {
                detector.GetCandidates(result);
            }

            result.Candidates.ScoreAndSort();

            NodeDictionaryGraphStyleSettings style = new NodeDictionaryGraphStyleSettings();


            result.CurrentGraphStates.Add(result.CurrentGraph.BuildDirectedGraph(style));

            foreach (ChunkContentCandidate candidate in result.Candidates)
            {
                //if (candidate.Score == 0)
                //{
                //    result.DeclinedCandidates.Add(candidate);
                //    continue;
                //}
                var rootNode = result.CurrentGraph.GetChildAtPath <NodeGraph>(candidate.Node.path, "/", false);
                if (rootNode == null)
                {
                    result.DeclinedCandidates.Add(candidate);
                }
                else
                {
                    ContentChunk contentChunk = new ContentChunk();
                    contentChunk.ExtractorName = candidate.Detector.GetExtractorName();
                    contentChunk.DeployRootNode(rootNode);

                    var subGraph = rootNode.GetSubgraph(true);
                    contentChunk.SubGraph = subGraph;

                    if (candidate.Detector.SetContentChunk(contentChunk, candidate, result))
                    {
                        result.DetectedChunks.Add(contentChunk);
                        result.AcceptedCandidates.Add(candidate);
                    }
                    else
                    {
                        result.DeclinedByDetectorCandidates.Add(candidate);
                    }

                    result.CurrentGraphStates.Add(result.CurrentGraph.BuildDirectedGraph(style));
                }
            }


            return(result);
        }
Пример #3
0
 protected override void Visit(ContentChunk chunk)
 {
     this.CodeIndent(chunk).Write("Using OutputScope(\"").Write(chunk.Name).WriteLine("\")").AddIndent();
     this.PushScope();
     base.Accept(chunk.Body);
     this.PopScope();
     this._source.RemoveIndent().WriteLine("End Using");
 }
Пример #4
0
 protected override void Visit(ContentChunk chunk)
 {
     this.CodeIndent(chunk).WriteLine("using(OutputScope(\"{0}\"))", new object[] { chunk.Name });
     this.CodeDefault();
     this.AppendOpenBrace();
     base.Accept(chunk.Body);
     this.AppendCloseBrace();
 }
Пример #5
0
 protected override void Visit(ContentChunk chunk)
 {
     CodeIndent(chunk).WriteLine("using(OutputScope(\"{0}\"))", chunk.Name);
     CodeDefault();
     AppendOpenBrace();
     Accept(chunk.Body);
     AppendCloseBrace();
 }
Пример #6
0
 public void Learn(ContentChunk chunk)
 {
     if (chunk.multiNodePolicy != TaskMultiNodePolicy.undefined)
     {
         multiNodePolicy = chunk.multiNodePolicy;
     }
     //if (!chunk.name.isNullOrEmpty()) ExtraInfoEntries.Add("ChunkName", chunk.name);
     if (!chunk.title.isNullOrEmpty())
     {
         ExtraInfoEntries.Add(nameof(ContentChunk.title), chunk.title);
     }
     if (!chunk.description.isNullOrEmpty())
     {
         ExtraInfoEntries.Add(nameof(ContentChunk.description), chunk.description);
     }
     //ExtraInfoEntries.AddObjectEntry("chunk", chunk, "Serialized chunk");
 }
        public override bool SetContentChunk(ContentChunk chunk, ChunkContentCandidate candidate, ChunkDetectionResult result)
        {
            JunctionPoint <NodeGraph>  junctionPoint     = candidate.MetaData as JunctionPoint <NodeGraph>;
            NodeGraphTemplateDetection templateDetection = new NodeGraphTemplateDetection(junctionPoint.rootItem);

            if (templateDetection.IsValid())
            {
                RecordTemplateSet templateSet = templateDetection.GetTemplateSet();
                chunk.ExtractorCustomizationSettings.AddObjectEntry(nameof(RecordTemplateExtractor.TemplateSet), templateSet);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #8
0
        public override bool SetContentChunk(ContentChunk chunk, ChunkContentCandidate candidate, ChunkDetectionResult result)
        {
            NodeGraphTemplateDetection templateDetection = new NodeGraphTemplateDetection(candidate.Node);

            chunk.multiNodePolicy = TaskMultiNodePolicy.AsSeparatedTables;
            chunk.type            = ContentChunkType.DynamicDataExtraction;


            if (templateDetection.IsValid())
            {
                RecordTemplateSet templateSet = templateDetection.GetTemplateSet();
                chunk.ExtractorCustomizationSettings.AddObjectEntry(nameof(RecordTemplateExtractor.TemplateSet), templateSet);

                return(true);
            }
            else
            {
                chunk.description = "Refused for failed template detection";

                return(false);
            }
        }
Пример #9
0
 protected override void Visit(ContentChunk chunk)
 {
     CodeIndent(chunk).AppendLine(string.Format("using(OutputScope(\"{0}\"))", chunk.Name));
     PushScope();
     AppendIndent().AppendLine("{");
     Indent += 4;
     Accept(chunk.Body);
     Indent -= 4;
     AppendIndent().AppendLine("}");
     PopScope();
 }
Пример #10
0
 protected abstract void Visit(ContentChunk chunk);
Пример #11
0
 protected override void Visit(ContentChunk chunk)
 {
     Accept(chunk.Body);
 }
 protected override void Visit(ContentChunk chunk)
 {
     _source.Append("OutputScope('").Append(chunk.Name).AppendLine("'); {");
     Accept(chunk.Body);
     _source.AppendLine("} DisposeOutputScope();");
 }
 protected override void Visit(ContentChunk chunk)
 {
     Accept(chunk.Body);
 }
Пример #14
0
 public abstract Boolean SetContentChunk(ContentChunk chunk, ChunkContentCandidate candidate, ChunkDetectionResult result);
Пример #15
0
 protected override void Visit(ContentChunk chunk)
 {
     CodeIndent(chunk)
         .Write("Using OutputScope(\"")
         .Write(chunk.Name)
         .WriteLine("\")")
         .AddIndent();
     PushScope();
     Accept(chunk.Body);
     PopScope();
     _source
         .RemoveIndent()
         .WriteLine("End Using");
 }
 protected override void Visit(ContentChunk chunk)
 {
     this._source.Append("OutputScope('").Append(chunk.Name).AppendLine("'); {");
     base.Accept(chunk.Body);
     this._source.AppendLine("} DisposeOutputScope();");
 }
Пример #17
0
        private void VisitContent(SpecialNodeInspector inspector)
        {
            var nameAttr = inspector.TakeAttribute("name");
            var varAttr = inspector.TakeAttribute("var");
            var defAttr = inspector.TakeAttribute("def");
            var setAttr = inspector.TakeAttribute("set");

            if (nameAttr != null)
            {
                var contentChunk = new ContentChunk { Name = nameAttr.Value, Position = Locate(inspector.OriginalNode) };
                Chunks.Add(contentChunk);
                using (new Frame(this, contentChunk.Body))
                    Accept(inspector.Body);
            }
            else if (varAttr != null || defAttr != null)
            {
                var variableChunk = new LocalVariableChunk { Name = AsCode(varAttr ?? defAttr), Type = "string" };
                Chunks.Add(variableChunk);

                var contentSetChunk = new ContentSetChunk { Variable = variableChunk.Name, Position = Locate(inspector.OriginalNode) };
                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else if (setAttr != null)
            {
                var addAttr = inspector.TakeAttribute("add");

                var contentSetChunk = new ContentSetChunk { Variable = AsCode(setAttr), Position = Locate(inspector.OriginalNode) };

                if (addAttr != null)
                {
                    if (addAttr.Value == "before")
                        contentSetChunk.AddType = ContentAddType.InsertBefore;
                    else if (addAttr.Value == "after")
                        contentSetChunk.AddType = ContentAddType.AppendAfter;
                    else if (addAttr.Value == "replace")
                        contentSetChunk.AddType = ContentAddType.Replace;
                    else
                        throw new CompilerException("add attribute must be 'before', 'after', or 'replace");
                }

                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else
            {
                throw new CompilerException("content element must have name, var, def, or set attribute");
            }
        }
Пример #18
0
 protected override void Visit(ContentChunk chunk)
 {
     _source.Write("__using").Write(++_usingDepth).Write("=OutputScopeAdapter(\"").Write(chunk.Name).WriteLine("\")");
     Accept(chunk.Body);
     _source.Write("__using").Write(_usingDepth--).WriteLine(".Dispose()");
 }
Пример #19
0
 protected override void Visit(ContentChunk chunk)
 {
     CodeIndent(chunk).WriteLine("using(OutputScope(\"{0}\"))", chunk.Name);
     CodeDefault();
     AppendOpenBrace();
     Accept(chunk.Body);
     AppendCloseBrace();
 }
Пример #20
0
        private void VisitContent(SpecialNodeInspector inspector)
        {
            var nameAttr = inspector.TakeAttribute("name");
            var varAttr  = inspector.TakeAttribute("var");
            var defAttr  = inspector.TakeAttribute("def");
            var setAttr  = inspector.TakeAttribute("set");

            if (nameAttr != null)
            {
                var contentChunk = new ContentChunk {
                    Name = nameAttr.Value, Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(contentChunk);
                using (new Frame(this, contentChunk.Body))
                    Accept(inspector.Body);
            }
            else if (varAttr != null || defAttr != null)
            {
                var variableChunk = new LocalVariableChunk {
                    Name = AsCode(varAttr ?? defAttr), Type = "string"
                };
                Chunks.Add(variableChunk);

                var contentSetChunk = new ContentSetChunk {
                    Variable = variableChunk.Name, Position = Locate(inspector.OriginalNode)
                };
                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else if (setAttr != null)
            {
                var addAttr = inspector.TakeAttribute("add");

                var contentSetChunk = new ContentSetChunk {
                    Variable = AsCode(setAttr), Position = Locate(inspector.OriginalNode)
                };

                if (addAttr != null)
                {
                    if (addAttr.Value == "before")
                    {
                        contentSetChunk.AddType = ContentAddType.InsertBefore;
                    }
                    else if (addAttr.Value == "after")
                    {
                        contentSetChunk.AddType = ContentAddType.AppendAfter;
                    }
                    else if (addAttr.Value == "replace")
                    {
                        contentSetChunk.AddType = ContentAddType.Replace;
                    }
                    else
                    {
                        throw new CompilerException("add attribute must be 'before', 'after', or 'replace");
                    }
                }

                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else
            {
                throw new CompilerException("content element must have name, var, def, or set attribute");
            }
        }
 protected abstract void Visit(ContentChunk chunk);
Пример #22
0
        private void VisitContent(SpecialNodeInspector inspector)
        {
            AttributeNode node  = inspector.TakeAttribute("name");
            AttributeNode node2 = inspector.TakeAttribute("var");
            AttributeNode node3 = inspector.TakeAttribute("def");
            AttributeNode attr  = inspector.TakeAttribute("set");

            if (node != null)
            {
                ContentChunk item = new ContentChunk {
                    Name     = node.Value,
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(item);
                using (new Frame(this, item.Body))
                {
                    base.Accept(inspector.Body);
                    return;
                }
            }
            if ((node2 != null) || (node3 != null))
            {
                LocalVariableChunk chunk3 = new LocalVariableChunk {
                    Name = this.AsCode(node2 ?? node3),
                    Type = "string"
                };
                this.Chunks.Add(chunk3);
                ContentSetChunk chunk4 = new ContentSetChunk {
                    Variable = chunk3.Name,
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(chunk4);
                using (new Frame(this, chunk4.Body))
                {
                    base.Accept(inspector.Body);
                    return;
                }
            }
            if (attr != null)
            {
                AttributeNode   node5  = inspector.TakeAttribute("add");
                ContentSetChunk chunk7 = new ContentSetChunk {
                    Variable = this.AsCode(attr),
                    Position = this.Locate(inspector.OriginalNode)
                };
                if (node5 != null)
                {
                    if (node5.Value != "before")
                    {
                        if (node5.Value != "after")
                        {
                            if (node5.Value != "replace")
                            {
                                throw new CompilerException("add attribute must be 'before', 'after', or 'replace");
                            }
                            chunk7.AddType = ContentAddType.Replace;
                        }
                        else
                        {
                            chunk7.AddType = ContentAddType.AppendAfter;
                        }
                    }
                    else
                    {
                        chunk7.AddType = ContentAddType.InsertBefore;
                    }
                }
                this.Chunks.Add(chunk7);
                using (new Frame(this, chunk7.Body))
                {
                    base.Accept(inspector.Body);
                    return;
                }
            }
            throw new CompilerException("content element must have name, var, def, or set attribute");
        }