예제 #1
0
        private void ClearAddressIndex(ref List <AnalyzeIndex> analyzeIndexList, LineCollection lines)
        {
            if (analyzeIndexList == null)
            {
                return;
            }

            foreach (var index in analyzeIndexList.ToArray())
            {
                foreach (var analyze in index.AnalyzeIndexCollection.ToArray())
                {
                    var address = (analyze as AddressItem);

                    var addressControl = AnalyzeControlFactory.GetControl(address.AddressType);

                    if (addressControl != null)
                    {
                        bool c = addressControl.Control(analyze, lines, index);

                        if (!c)
                        {
                            index.AnalyzeIndexCollection.Remove(analyze);
                        }
                    }
                }


                if (index.AnalyzeIndexCollection.Count == 0)
                {
                    analyzeIndexList.Remove(index);
                }
            }
        }
예제 #2
0
        public async Task <JObject> Create(Line line)
        {
            try
            {
                await LineCollection.InsertOneAsync(line);

                return
                    (JObject.FromObject(
                         new
                {
                    status = "success",
                    result = true,
                    message = "Distributor Created"
                }
                         ));
            }
            catch (Exception ex)
            {
                return
                    (JObject.FromObject(
                         new
                {
                    status = "Exception Thrown",
                    result = false,
                    message = ex.Message
                }
                         ));
            }
        }
예제 #3
0
        internal override bool Control(INlpAnalyzeIndex analyze, LineCollection lines, AnalyzeIndex index)
        {
            if (index.WordNumber >= lines[index.LineNumber].SentenceList[index.SentenceNumber].WordList.Count - 1)
            {
                return(false);
            }

            var nextWord = lines[index.LineNumber].SentenceList[index.SentenceNumber].WordList[index.WordNumber + 1]?.SpellWord?.Root?.Text?.ToLower();

            if (nextWord == "mahalle")
            {
                return(true);
            }
            else if (nextWord == "mah")
            {
                return(true);
            }
            else if (nextWord == "mah.")
            {
                return(true);
            }


            return(false);
        }
예제 #4
0
        internal TFunctionData Execute(LineCollection lines)
        {
            TFunctionData stackFrame = new TFunctionData(this);

            for (int index = 0; index < lines.Count; index++)
            {
                if (BreakRequest)
                {
                    break;
                }
                Line current = lines[index];
                CurrentLine = current.LineNumber;
                try {
                    ObjectContext blockContext = Context.FindBlockContext(current.Name);
                    if (blockContext == null)
                    {
                        Execute(stackFrame, current);
                    }
                    else
                    {
                        CodeBlock block = blockContext.GetBlock(current.Name).Invoke(index, lines);
                        Context = Context.CreateSubContext();
                        block.Execute(this);
                        Context = Context.Collect();
                        index  += block.Length - 1; // skip the length of the executed block
                    }
                }
                catch (Exception ex) {
                    HandleError(current, stackFrame, ex);
                }
            }
            return(stackFrame);
        }
예제 #5
0
        public IfBlock(int index, LineCollection fullCode)
        {
            Else   = null;
            Header = fullCode[index];

            LineCollection ifLines   = new LineCollection();
            LineCollection elseLines = new LineCollection();

            int expected_endif = 1; // How many 'END IF' statements are expected

            index++;

            bool isElse = false; // Whether this should be added to the else block

            for (; index < fullCode.Count; index++)
            {
                Line cur = fullCode[index];
                if (cur.Name.EqualsIgnoreCase("IF"))
                {
                    expected_endif++;
                }

                if (expected_endif > 0)
                {
                    if (expected_endif == 1 && cur.Name.EqualsIgnoreCase("ELSE"))   // we are now in an else block
                    {
                        isElse = true;
                        continue; // We don't need to add the word 'ELSE'
                    }
                }

                if (cur.Text.EqualsIgnoreCase("END IF"))
                {
                    expected_endif--;
                }

                if (expected_endif == 0)
                {
                    if (elseLines.Count > 0)
                    {
                        Else = new ElseBlock(elseLines);
                    }
                    Footer = cur;
                    Body   = ifLines;
                    return;
                }

                if (isElse)
                {
                    elseLines.Add(cur);
                }
                else
                {
                    ifLines.Add(cur);
                }
            }

            throw ThrowHelper.UnterminatedBlock(Header.VisibleName);
        }
예제 #6
0
        public void invalidSetLineCollection()
        {
            ILineCollection lineCollection = new LineCollection(3);

            ILine line = new FakeLine();

            lineCollection[3] = line;
        }
예제 #7
0
 public Cart(IEnumerable <CartLine> lines)
 {
     cartLines = new LineCollection();
     foreach (var line in lines)
     {
         cartLines.AddLine(line);
     }
 }
예제 #8
0
 /// <summary>
 /// Clear Grid and Listbox
 /// </summary>
 /// <returns></returns>
 /// 2019/07/13, Vinoth N,  Initial Version
 private void Clear()
 {
     LineCollection.Clear();
     DetailCollection.Clear();
     ErrorCollection.Clear();
     counterStatus.Content = "";
     b_Download.IsEnabled  = false;
     tbk_counter.Text      = "0";
 }
예제 #9
0
 public ForBlock(int index, LineCollection code)
 {
     LoadFromCollection(
         code.ParseBlock(
             index,
             c => c.Name.EqualsIgnoreCase("FOR"),
             c => c.Name.EqualsIgnoreCase("NEXT")
             ));
 }
예제 #10
0
 public WhileBlock(int index, LineCollection code)
 {
     LoadFromCollection(
         code.ParseBlock(
             index,
             c => c.Name.EqualsIgnoreCase("WHILE"),
             c => c.Text.EqualsIgnoreCase("WEND")
             ));
 }
예제 #11
0
 public SelectBlock(int index, LineCollection code)
 {
     LoadFromCollection(
         code.ParseBlock(
             index,
             c => c.Name.EqualsIgnoreCase("SELECT"),
             c => c.Text.EqualsIgnoreCase("END SELECT")
             ));
 }
예제 #12
0
        public override void Analyse(LineCollection lines)
        {
            if (lines == null)
            {
                return;
            }


            manager = new LuceneManager();
            if (!manager.ExistSchema("address"))
            {
                manager.AddSchema("address");
            }



            var analyzeIndexList = new List <AnalyzeIndex>();


            foreach (var line in lines)
            {
                foreach (var sentence in line.SentenceList)
                {
                    foreach (var word in sentence.WordList)
                    {
                        if (word.SpellWord != null)
                        {
                            if (word.SpellWord.Root != null)
                            {
                                var adresList = AddressControl(word);


                                if (adresList != null)
                                {
                                    if (adresList.Count > 0)
                                    {
                                        var analyze = new AnalyzeIndex();

                                        analyze.AnalyzeIndexCollection.AddRange(adresList);
                                        analyze.LineNumber     = lines.IndexOf(line);
                                        analyze.WordNumber     = sentence.WordList.IndexOf(word);
                                        analyze.SentenceNumber = line.SentenceList.IndexOf(sentence);


                                        analyzeIndexList.Add(analyze);
                                    }
                                }
                            }
                        }
                    }
                }
            }



            ClearAddressIndex(ref analyzeIndexList, lines);
        }
예제 #13
0
 public DoBlock(int index, LineCollection code)
 {
     LoadFromCollection(
         code.ParseBlock(
             index,
             c => c.Name.EqualsIgnoreCase("DO"),
             c => c.Text.EqualsIgnoreCase("LOOP")
             ));
 }
예제 #14
0
        /// <summary>
        /// Sets the header as the first line in the collection, the last line as the footer, and the code in between as the body
        /// </summary>
        /// <param name="blockLines"></param>
        protected void LoadFromCollection(LineCollection blockLines)
        {
            LineCollection body = blockLines.Clone();

            Header = blockLines[0];
            Footer = blockLines[blockLines.Count - 1];
            body.Remove(Header);
            body.Remove(Footer);
            Body = body;
        }
예제 #15
0
 public FuncBlock(int index, LineCollection code)
 {
     LoadFromCollection(
         code.ParseBlock(
             index,
             c => c.Name.EqualsIgnoreCase("FUNCTION"),
             c => c.Text.EqualsIgnoreCase("END FUNCTION")
             ));
     Template = new TFunctionData(null);
     Template.SetAll(ParseFunction(Header.Text.Substring(Header.Name.Length)));
 }
예제 #16
0
        public char?FindListerOnMarker(LineCollection lines)
        {
            foreach (var line in lines)
            {
                if (GetListHighlight(line.Text, out char?c) == true)
                {
                    return(c);
                }
            }

            return(null);
        }
예제 #17
0
        internal static LineCollection ScanLines(string[] lines, out CodeBlock[] userFunctions)
        {
            LineCollection allLines = new LineCollection();
            List <uint>    funLines = new List <uint>();

            for (uint lineNumber = 0; lineNumber < lines.Length; ++lineNumber)
            {
                Line current = new Line(lineNumber + 1, lines[lineNumber]); // Tag all lines with its line number (index + 1)

                if (string.IsNullOrEmpty(current.Text) || current.Text[0] == ';')
                {
                    continue;
                }
                if (current.Name[current.Name.Length - 1] == '$' || current.Name[current.Name.Length - 1] == ']')
                {
                    current.Text = "LET " + current.Text; // add the word LET if it's an equality, but use the original name as visible name
                }
                else if (current.Name.EqualsIgnoreCase("FUNCTION"))
                {
                    funLines.Add(current.LineNumber);
                }
                else
                {
                    current.VisibleName = current.VisibleName.ToUpper();
                }

                while (current.Text[current.Text.Length - 1] == '_')   // line continuation
                {
                    lineNumber++;
                    if (lineNumber >= lines.Length)
                    {
                        throw new EndOfCodeException("line continuation character '_' cannot end script");
                    }
                    current = new Line(current.LineNumber, current.Text.Remove(current.Text.LastIndexOf('_')) + lines[lineNumber].Trim());
                }

                allLines.Add(current);
            }

            List <CodeBlock> userFuncs = new List <CodeBlock>();

            foreach (uint funcLine in funLines)
            {
                FuncBlock func = new FuncBlock(allLines.IndexOf(funcLine), allLines);
                userFuncs.Add(func);
                allLines.Remove(func.Header);
                allLines.Remove(func.Body);
                allLines.Remove(func.Footer);
            }
            userFunctions = userFuncs.ToArray();
            return(allLines);
        }
예제 #18
0
        public char?FindListMarkerChar(LineCollection lines, ListHighlightValue needle)
        {
            foreach (var line in lines)
            {
                var r = GetListHighlight(line.Text, out var c);
                if (r == needle)
                {
                    return(c);
                }
            }

            return(null);
        }
예제 #19
0
        public void Analyse(LineCollection lines)
        {
            if (lines == null)
            {
                return;
            }


            foreach (var a in AnalyseFactory.AnalyseList)
            {
                a.Analyse(lines);
            }
        }
        public LineCollection GenerateLineCollection(int lines)
        {
            var result = new LineCollection(Pool.Legs.Length);

            if (lines <= 0)
            {
                return(result);
            }

            while (result.Count < lines)
            {
                var line = GenerateNewLine();
                result.Add(line);
            }

            return(result);
        }
예제 #21
0
 public LineHitDictionary(LineCollection lines)
 {
     foreach (Line line in lines)
     {
         if (!ContainsKey(line.Nr))
         {
             if (line.Ci > 0)
             {
                 Add(line.Nr, true);
             }
             else
             {
                 Add(line.Nr, false);
             }
         }
     }
 }
예제 #22
0
        public async Task <JObject> Delete(string lineId)
        {
            try
            {
                var filter = Builders <Line> .Filter.Eq("_id", ObjectId.Parse(lineId));

                DeleteResult result = await LineCollection.DeleteOneAsync(filter);

                if (result.IsAcknowledged)
                {
                    return
                        (JObject.FromObject(
                             new
                    {
                        status = "success",
                        result = true,
                        message = "Line was deleted"
                    }
                             ));
                }
                else
                {
                    return
                        (JObject.FromObject(
                             new
                    {
                        status = "false",
                        result = false,
                        message = "Line could not be deleted"
                    }
                             ));
                }
            }
            catch (Exception ex)
            {
                return
                    (JObject.FromObject(
                         new
                {
                    status = "Exception Thrown",
                    result = false,
                    message = ex.Message
                }
                         ));
            }
        }
예제 #23
0
        private void Include(TFunctionData stackFrame)
        {
            stackFrame.AssertParamCount(2);
            string path = Path.GetFullPath(stackFrame.GetParameter <string>(1));

            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }

            CodeBlock[]    funcs;
            LineCollection lines = Executer.ScanLines(File.ReadAllLines(path), out funcs);



            NULL(stackFrame);
        }
예제 #24
0
        public void createLineCollection()
        {
            ILineCollection lineCollection = new LineCollection(3);

            Assert.AreEqual(lineCollection.Size, 3);
            foreach (ILine line in lineCollection)
            {
                Assert.IsNull(line);
            }

            ILineCollection lineCollection2 = new LineCollection(5);

            Assert.AreEqual(lineCollection2.Size, 5);
            for (int i = 0; i < 5; ++i)
            {
                Assert.IsNull(lineCollection2[i]);
            }
        }
예제 #25
0
        /// <summary>
        /// Runs a Tbasic script
        /// </summary>
        /// <param name="lines">the lines of the script to process</param>
        public void Execute(string[] lines)
        {
            CodeBlock[]    userFuncs;
            LineCollection code = ScanLines(lines, out userFuncs);

            if (userFuncs != null && userFuncs.Length > 0)
            {
                foreach (CodeBlock cb in userFuncs)
                {
                    FuncBlock fBlock = (FuncBlock)cb;
                    Global.SetFunction(fBlock.Template.Name, fBlock.CreateDelegate());
                }
            }
            Execute(code);

            /*if (ManagedWindows.Count != 0 && !this.ExitRequest) {
             *  System.Windows.Forms.Application.Run(new FormLoader(this));
             * }*/
        }
        public static Process Run(int procNum, int numLogs, LineCollection coll)
        {
            Process proc = new Process();
            proc.StartInfo.Arguments = string.Format("{0} {1}", procNum, numLogs);
            proc.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Runner.exe");
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            proc.StartInfo.RedirectStandardInput = false;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.CreateNoWindow = true;

            proc.Start();

            proc.BeginOutputReadLine();
            proc.OutputDataReceived += (s, e) => coll.AppendLine("Process {0}: `{1}'", procNum, e.Data);

            return proc;
        }
예제 #27
0
파일: Form1.cs 프로젝트: dinceruygun/NLP
        private void SetMorphologic(LineCollection result)
        {
            trwMorphologic.Nodes.Clear();

            foreach (var line in result)
            {
                var lineNode = new TreeNode(line.Text);


                foreach (var sentence in line.SentenceList)
                {
                    var sentenceNode = new TreeNode(sentence.Text);


                    foreach (var word in sentence.WordList)
                    {
                        var wordNode = new TreeNode(word.SpellWord == null ? word.Text : ($"{word.SpellWord.Text} [{word.SpellWord.Root.Text}]"));


                        if (word.SpellWord != null)
                        {
                            foreach (var morph in word.SpellWord.Morphologic)
                            {
                                var morphNode = new TreeNode($"[{morph.Morphologic?.Name}] {morph.Morphologic?.Description}");


                                wordNode.Nodes.Add(morphNode);
                            }
                        }


                        sentenceNode.Nodes.Add(wordNode);
                    }


                    lineNode.Nodes.Add(sentenceNode);
                }


                trwMorphologic.Nodes.Add(lineNode);
            }
        }
예제 #28
0
            private CaseBlock(LineCollection body)
            {
                Header = body[0];
                TFunctionData parms = new TFunctionData(null, Header.Text);

                if (parms.Name.EqualsIgnoreCase("DEFAULT"))
                {
                    Condition = new StringSegment("default");
                }
                else if (parms.ParameterCount < 2)
                {
                    throw ThrowHelper.NoCondition();
                }
                else
                {
                    Condition = new StringSegment(Header.Text, Header.Name.Length);
                }
                body.RemoveAt(0);
                Body = body;
            }
예제 #29
0
        public void setLineCollection()
        {
            ILineCollection lineCollection = new LineCollection(3);

            ILine line1 = new FakeLine();
            ILine line2 = new FakeLine();
            ILine line3 = new FakeLine();

            lineCollection[0] = line1;

            Assert.AreEqual(lineCollection.Size, 3);
            Assert.AreEqual(lineCollection[0], line1);
            Assert.IsNull(lineCollection[1]);
            Assert.IsNull(lineCollection[2]);

            lineCollection[1] = line2;
            lineCollection[2] = line3;

            Assert.AreEqual(lineCollection.Size, 3);
            Assert.AreEqual(lineCollection[0], line1);
            Assert.AreEqual(lineCollection[1], line2);
            Assert.AreEqual(lineCollection[2], line3);
        }
예제 #30
0
            public static int ParseBlock(int index, LineCollection all, out CaseBlock caseBlock)
            {
                LineCollection blockLines = new LineCollection();

                bool isBlock = false;

                for (; index < all.Count; index++)
                {
                    if (isBlock)
                    {
                        if (all[index].Name.EqualsIgnoreCase("CASE") ||
                            all[index].Name.EqualsIgnoreCase("DEFAULT"))
                        {
                            break;
                        }
                        else
                        {
                            blockLines.Add(all[index]);
                        }
                    }
                    else if (all[index].Name.EqualsIgnoreCase("CASE") ||
                             all[index].Name.EqualsIgnoreCase("DEFAULT"))
                    {
                        isBlock = true;
                        blockLines.Add(all[index]);
                    }
                }
                if (blockLines.Count > 0)
                {
                    caseBlock = new CaseBlock(blockLines);
                }
                else
                {
                    caseBlock = null;
                }
                return(index);
            }
예제 #31
0
 private string[] ConvertSourceCodeLinesToArray(LineCollection sourceCodeLines)
 {
     return(sourceCodeLines
            .Select(y => y.Text)
            .ToArray());
 }
예제 #32
0
			public Layer() {
				lineCollection = new LineCollection();
				Children.Add(lineCollection);
			}
예제 #33
0
        internal ParagraphMetrics(
			Paragraph paragraph, FormatterSink formattedData, TextGeometryCache geometryCache)
        {
            Contract.Requires(paragraph != null);
            Contract.Requires(formattedData != null);
            Contract.Requires(geometryCache != null);

            _Paragraph = paragraph;

            _Leading = formattedData.Leading;
            _LayoutRegion = formattedData.LayoutRegion;
            _BaselineOffset = formattedData.BaselineOffset;

            _Clusters = formattedData.Clusters.ToArray();

            _ClusterBidiLevels = new byte[formattedData.Clusters.Count];

            _Outlines = CreateOutlineList(formattedData, geometryCache, out _ClusterBidiLevels);

            // create the text index to cluster index transformation table
            _TextToCluster = new int[formattedData.FullText.Length];

            for(int i = 0; i < _Clusters.Length; ++i)
            {
                foreach(int characterIndex in _Clusters[i].Characters)
                {
                    _TextToCluster[characterIndex] = i;
                }
            }

            // determine the region that encompasses all formatted clusters
            float left = float.MaxValue;
            float top = float.MaxValue;
            float right = float.MinValue;
            float bottom = float.MinValue;

            for(int i = 0; i < _Clusters.Length; ++i)
            {
                left = Math.Min(left, _Clusters[i].Region.Left);
                top = Math.Min(top, _Clusters[i].Region.Top);
                right = Math.Max(right, _Clusters[i].Region.Right);
                bottom = Math.Max(bottom, _Clusters[i].Region.Bottom);
            }

            _TextRegion = Rectangle.FromEdges(left, top, right, bottom);

            // determine the ranges of each line
            _LineListBuilder.Clear();

            int lastLine = 0;

            IndexedRange range = IndexedRange.Empty;

            for(int i = 0; i < formattedData.Runs.Count; ++i)
            {
                if(formattedData.Runs[i].LineNumber > lastLine)
                {
                    _LineListBuilder.Add(ToTextRange(range));

                    range = new IndexedRange(formattedData.Runs[i].Clusters.StartIndex, 0);

                    lastLine = formattedData.Runs[i].LineNumber;
                }

                range = range.Extend(formattedData.Runs[i].Clusters.Length);
            }

            if(range.Length > 0)
            {
                _LineListBuilder.Add(ToTextRange(range));
            }

            _Lines = new LineCollection(_LineListBuilder);

            // build a collection of regions mapping to text indexes
            _RegionListBuilder.Clear();

            for(int i = 0; i < paragraph.Text.Length; ++i)
            {
                _RegionListBuilder.Add(_Clusters[_TextToCluster[i]].Region);
            }

            _Regions = new RegionCollection(_RegionListBuilder);
        }
        private void DoConcurrentTest(int numProcesses, int numLogs)
        {
            string logFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file.txt");

            if(File.Exists(logFile))
                File.Delete(logFile);

            LineCollection coll = new LineCollection();
            Process[] processes = new Process[numProcesses];

            for(int i = 0; i < numProcesses; ++i)
                processes[i] = Run(i, numLogs, coll);

            bool errorFound = false;

            for(int i = 0; i < numProcesses; ++i)
            {
                processes[i].WaitForExit();
                if(processes[i].ExitCode != 0)
                    errorFound = true;
                processes[i].Dispose();
                processes[i] = null;
            }

            if(errorFound)
            {
                Console.WriteLine(coll.BuildLines());
                Assert.Fail("Runner returned with an error.");
            }

            int[] maxNumber = new int[numProcesses];

            using(StreamReader sr = File.OpenText(logFile))
            {
                string line;

                while((line = sr.ReadLine()) != null)
                {
                    string[] tokens = line.Split(' ');
                    Assert.AreEqual(2, tokens.Length, "invalid output line: '" + line + "' expected two numbers.");
                    try
                    {
                        int thread = Convert.ToInt32(tokens[0]);
                        int number = Convert.ToInt32(tokens[1]);

                        Assert.AreEqual(maxNumber[thread], number);
                        maxNumber[thread]++;
                    }
                    catch(Exception ex)
                    {
                        throw new InvalidOperationException("Error when parsing line '" + line + "'", ex);
                    }
                }
            }
        }